| modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met. |
+--------------------------------------------------------------------+
- | Copyright (c) 2004-2011, Michael Wallner <mike@php.net> |
+ | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
+--------------------------------------------------------------------+
*/
static void message_headers(php_http_message_t *msg, php_http_buffer_t *str);
-PHP_HTTP_API zend_bool php_http_message_info_callback(php_http_message_t **message, HashTable **headers, php_http_info_t *info TSRMLS_DC)
+zend_bool php_http_message_info_callback(php_http_message_t **message, HashTable **headers, php_http_info_t *info)
{
php_http_message_t *old = *message;
/* advance message */
if (!old || old->type || zend_hash_num_elements(&old->hdrs)) {
- (*message) = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
+ (*message) = php_http_message_init(NULL, 0, NULL);
(*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, php_http_message_body_t *body TSRMLS_DC)
+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)
{
if (!message) {
message = emalloc(sizeof(*message));
}
memset(message, 0, sizeof(*message));
- TSRMLS_SET_CTX(message->ts);
php_http_message_set_type(message, type);
message->http.version.major = 1;
message->http.version.minor = 1;
zend_hash_init(&message->hdrs, 0, NULL, ZVAL_PTR_DTOR, 0);
- message->body = body ? body : php_http_message_body_init(NULL, NULL TSRMLS_CC);
+ message->body = body ? body : php_http_message_body_init(NULL, NULL);
return message;
}
-PHP_HTTP_API php_http_message_t *php_http_message_init_env(php_http_message_t *message, php_http_message_type_t type TSRMLS_DC)
+php_http_message_t *php_http_message_init_env(php_http_message_t *message, php_http_message_type_t type)
{
int free_msg = !message;
zval *sval, tval;
switch (type) {
case PHP_HTTP_REQUEST:
- mbody = php_http_env_get_request_body(TSRMLS_C);
+ mbody = php_http_env_get_request_body();
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);
+ message = php_http_message_init(message, type, mbody);
+ if ((sval = php_http_env_get_server_var(ZEND_STRL("SERVER_PROTOCOL"), 1)) && !strncmp(Z_STRVAL_P(sval), "HTTP/", lenof("HTTP/"))) {
+ php_http_version_parse(&message->http.version, Z_STRVAL_P(sval));
}
- if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_METHOD"), 1 TSRMLS_CC))) {
+ if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_METHOD"), 1))) {
message->http.info.request.method = estrdup(Z_STRVAL_P(sval));
}
- if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_URI"), 1 TSRMLS_CC))) {
- message->http.info.request.url = estrdup(Z_STRVAL_P(sval));
+ if ((sval = php_http_env_get_server_var(ZEND_STRL("REQUEST_URI"), 1))) {
+ message->http.info.request.url = php_http_url_parse(Z_STRVAL_P(sval), Z_STRLEN_P(sval), ~0);
}
- php_http_env_get_request_headers(&message->hdrs TSRMLS_CC);
+ php_http_env_get_request_headers(&message->hdrs);
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)) {
+ message = php_http_message_init(NULL, type, NULL);
+ if (!SG(sapi_headers).http_status_line || !php_http_info_parse((php_http_info_t *) &message->http, SG(sapi_headers).http_status_line)) {
if (!(message->http.info.response.code = SG(sapi_headers).http_response_code)) {
message->http.info.response.code = 200;
}
message->http.info.response.status = estrdup(php_http_env_get_response_status_for_code(message->http.info.response.code));
}
- php_http_env_get_response_headers(&message->hdrs TSRMLS_CC);
-#if PHP_VERSION_ID >= 50400
- if (php_output_get_level(TSRMLS_C)) {
- if (php_output_get_status(TSRMLS_C) & PHP_OUTPUT_SENT) {
- php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "Could not fetch response body, output has already been sent at %s:%d", php_output_get_start_filename(TSRMLS_C), php_output_get_start_lineno(TSRMLS_C));
+ php_http_env_get_response_headers(&message->hdrs);
+ if (php_output_get_level()) {
+ if (php_output_get_status() & PHP_OUTPUT_SENT) {
+ php_error_docref(NULL, E_WARNING, "Could not fetch response body, output has already been sent at %s:%d", php_output_get_start_filename(), php_output_get_start_lineno());
goto error;
- } else if (SUCCESS != php_output_get_contents(&tval TSRMLS_CC)) {
- php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "Could not fetch response body");
+ } else if (SUCCESS != php_output_get_contents(&tval)) {
+ php_error_docref(NULL, E_WARNING, "Could not fetch response body");
goto error;
} else {
php_http_message_body_append(message->body, Z_STRVAL(tval), Z_STRLEN(tval));
zval_dtor(&tval);
}
}
-#endif
break;
default:
return message;
}
-PHP_HTTP_API php_http_message_t *php_http_message_parse(php_http_message_t *msg, const char *str, size_t len, zend_bool greedy TSRMLS_DC)
+php_http_message_t *php_http_message_parse(php_http_message_t *msg, const char *str, size_t len, zend_bool greedy)
{
php_http_message_parser_t p;
php_http_buffer_t buf;
int free_msg;
php_http_buffer_from_string_ex(&buf, str, len);
- php_http_message_parser_init(&p TSRMLS_CC);
+ php_http_message_parser_init(&p);
if ((free_msg = !msg)) {
- msg = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
+ msg = php_http_message_init(NULL, 0, NULL);
}
if (greedy) {
flags |= PHP_HTTP_MESSAGE_PARSER_GREEDY;
}
- if (FAILURE == php_http_message_parser_parse(&p, &buf, flags, &msg)) {
+ if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE == php_http_message_parser_parse(&p, &buf, flags, &msg)) {
if (free_msg) {
php_http_message_free(&msg);
}
return msg;
}
-PHP_HTTP_API zval *php_http_message_header(php_http_message_t *msg, const char *key_str, size_t key_len, int join)
+zval *php_http_message_header(php_http_message_t *msg, const char *key_str, size_t key_len)
{
- zval *ret = NULL, **header;
- char *key = php_http_pretty_key(estrndup(key_str, key_len), key_len, 1, 1);
+ zval *ret;
+ char *key;
+ ALLOCA_FLAG(free_key);
- if (SUCCESS == zend_symtable_find(&msg->hdrs, key, key_len + 1, (void *) &header)) {
- if (join && Z_TYPE_PP(header) == IS_ARRAY) {
- TSRMLS_FETCH_FROM_CTX(msg->ts);
+ key = do_alloca(key_len + 1, free_key);
- ret = php_http_header_value_to_string(*header TSRMLS_CC);
- } else {
- Z_ADDREF_PP(header);
- ret = *header;
- }
- }
+ memcpy(key, key_str, key_len);
+ key[key_len] = '\0';
+ php_http_pretty_key(key, key_len, 1, 1);
- efree(key);
+ ret = zend_symtable_str_find(&msg->hdrs, key, key_len);
+
+ free_alloca(key, free_key);
return ret;
}
-PHP_HTTP_API zend_bool php_http_message_is_multipart(php_http_message_t *msg, char **boundary)
+zend_bool php_http_message_is_multipart(php_http_message_t *msg, char **boundary)
{
- zval *ct = php_http_message_header(msg, ZEND_STRL("Content-Type"), 1);
+ zend_string *ct = php_http_message_header_string(msg, ZEND_STRL("Content-Type"));
zend_bool is_multipart = 0;
- TSRMLS_FETCH_FROM_CTX(msg->ts);
if (ct) {
php_http_params_opts_t popts;
ZEND_INIT_SYMTABLE(¶ms);
php_http_params_opts_default_get(&popts);
- popts.input.str = Z_STRVAL_P(ct);
- popts.input.len = Z_STRLEN_P(ct);
+ popts.input.str = ct->val;
+ popts.input.len = ct->len;
- if (php_http_params_parse(¶ms, &popts TSRMLS_CC)) {
- zval **cur, **arg;
- char *ct_str;
+ if (php_http_params_parse(¶ms, &popts)) {
+ zval *cur, *arg;
+ zend_string *ct_str;
+ zend_ulong index;
zend_hash_internal_pointer_reset(¶ms);
- if (SUCCESS == zend_hash_get_current_data(¶ms, (void *) &cur)
- && Z_TYPE_PP(cur) == IS_ARRAY
- && HASH_KEY_IS_STRING == zend_hash_get_current_key(¶ms, &ct_str, NULL, 0)
+ if ((cur = zend_hash_get_current_data(¶ms))
+ && (Z_TYPE_P(cur) == IS_ARRAY)
+ && (HASH_KEY_IS_STRING == zend_hash_get_current_key(¶ms, &ct_str, &index))
) {
- if (php_http_match(ct_str, "multipart", PHP_HTTP_MATCH_WORD)) {
+ if (php_http_match(ct_str->val, "multipart", PHP_HTTP_MATCH_WORD)) {
is_multipart = 1;
/* get boundary */
if (boundary
- && SUCCESS == zend_hash_find(Z_ARRVAL_PP(cur), ZEND_STRS("arguments"), (void *) &arg)
- && Z_TYPE_PP(arg) == IS_ARRAY
+ && (arg = zend_hash_str_find(Z_ARRVAL_P(cur), ZEND_STRL("arguments")))
+ && Z_TYPE_P(arg) == IS_ARRAY
) {
- zval **val;
- HashPosition pos;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
+ zval *val;
+ php_http_arrkey_t key;
- FOREACH_KEYVAL(pos, *arg, key, val) {
- if (key.type == HASH_KEY_IS_STRING && !strcasecmp(key.str, "boundary")) {
- zval *bnd = php_http_ztyp(IS_STRING, *val);
+ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arg), key.h, key.key, val)
+ {
+ if (key.key && key.key->len == lenof("boundary") && !strcasecmp(key.key->val, "boundary")) {
+ zend_string *bnd = zval_get_string(val);
- if (Z_STRLEN_P(bnd)) {
- *boundary = estrndup(Z_STRVAL_P(bnd), Z_STRLEN_P(bnd));
+ if (bnd->len) {
+ *boundary = estrndup(bnd->val, bnd->len);
}
- zval_ptr_dtor(&bnd);
+ zend_string_release(bnd);
}
}
+ ZEND_HASH_FOREACH_END();
}
}
}
}
zend_hash_destroy(¶ms);
- zval_ptr_dtor(&ct);
+ zend_string_release(ct);
}
return is_multipart;
}
/* */
-PHP_HTTP_API void php_http_message_set_type(php_http_message_t *message, php_http_message_type_t type)
+void php_http_message_set_type(php_http_message_t *message, php_http_message_type_t type)
{
/* just act if different */
if (type != message->type) {
/* free request info */
switch (message->type) {
case PHP_HTTP_REQUEST:
- STR_FREE(message->http.info.request.method);
- STR_FREE(message->http.info.request.url);
+ PTR_FREE(message->http.info.request.method);
+ PTR_FREE(message->http.info.request.url);
break;
case PHP_HTTP_RESPONSE:
- STR_FREE(message->http.info.response.status);
+ PTR_FREE(message->http.info.response.status);
break;
default:
}
}
-PHP_HTTP_API void php_http_message_set_info(php_http_message_t *message, php_http_info_t *info)
+void php_http_message_set_info(php_http_message_t *message, php_http_info_t *info)
{
php_http_message_set_type(message, info->type);
message->http.version = info->http.version;
switch (message->type) {
case PHP_HTTP_REQUEST:
- STR_SET(PHP_HTTP_INFO(message).request.url, PHP_HTTP_INFO(info).request.url ? estrdup(PHP_HTTP_INFO(info).request.url) : NULL);
- STR_SET(PHP_HTTP_INFO(message).request.method, PHP_HTTP_INFO(info).request.method ? estrdup(PHP_HTTP_INFO(info).request.method) : NULL);
+ PTR_SET(PHP_HTTP_INFO(message).request.url, PHP_HTTP_INFO(info).request.url ? php_http_url_copy(PHP_HTTP_INFO(info).request.url, 0) : NULL);
+ PTR_SET(PHP_HTTP_INFO(message).request.method, PHP_HTTP_INFO(info).request.method ? estrdup(PHP_HTTP_INFO(info).request.method) : NULL);
break;
case PHP_HTTP_RESPONSE:
PHP_HTTP_INFO(message).response.code = PHP_HTTP_INFO(info).response.code;
- STR_SET(PHP_HTTP_INFO(message).response.status, PHP_HTTP_INFO(info).response.status ? estrdup(PHP_HTTP_INFO(info).response.status) : NULL);
+ PTR_SET(PHP_HTTP_INFO(message).response.status, PHP_HTTP_INFO(info).response.status ? estrdup(PHP_HTTP_INFO(info).response.status) : NULL);
break;
default:
}
}
-PHP_HTTP_API void php_http_message_update_headers(php_http_message_t *msg)
+void php_http_message_update_headers(php_http_message_t *msg)
{
- zval *h;
+ zval h;
size_t size;
+ zend_string *cl;
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 (php_http_message_header(msg, ZEND_STRL("Content-Range"))) {
+ /* don't mess around with a Content-Range message */
} 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);
+ ZVAL_LONG(&h, size);
+ zend_hash_str_update(&msg->hdrs, "Content-Length", lenof("Content-Length"), &h);
if (msg->body->boundary) {
char *str;
size_t len;
+ zend_string *ct;
- if (!(h = php_http_message_header(msg, ZEND_STRL("Content-Type"), 1))) {
+ if (!(ct = php_http_message_header_string(msg, ZEND_STRL("Content-Type")))) {
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);
- zend_hash_update(&msg->hdrs, "Content-Type", sizeof("Content-Type"), &h, sizeof(zval *), NULL);
+ ZVAL_STR(&h, php_http_cs2zs(str, len));
+ zend_hash_str_update(&msg->hdrs, "Content-Type", lenof("Content-Type"), &h);
+ } else if (!php_http_match(ct->val, "boundary=", PHP_HTTP_MATCH_WORD)) {
+ len = spprintf(&str, 0, "%s; boundary=\"%s\"", ct->val, msg->body->boundary);
+ ZVAL_STR(&h, php_http_cs2zs(str, len));
+ zend_hash_str_update(&msg->hdrs, "Content-Type", lenof("Content-Type"), &h);
+ zend_string_release(ct);
} else {
- zval_ptr_dtor(&h);
+ zend_string_release(ct);
}
}
+ } else if ((cl = php_http_message_header_string(msg, ZEND_STRL("Content-Length")))) {
+ if (!zend_string_equals_literal(cl, "0")) {
+ /* body->size == 0, so get rid of old Content-Length */
+ zend_hash_str_del(&msg->hdrs, ZEND_STRL("Content-Length"));
+ }
+ zend_string_release(cl);
}
}
static void message_headers(php_http_message_t *msg, php_http_buffer_t *str)
{
- TSRMLS_FETCH_FROM_CTX(msg->ts);
+ char *tmp = NULL;
switch (msg->type) {
case PHP_HTTP_REQUEST:
- php_http_buffer_appendf(str, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&msg->http, PHP_HTTP_CRLF));
+ 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, PHP_HTTP_CRLF));
+ php_http_buffer_appendf(str, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&msg->http, tmp, PHP_HTTP_CRLF));
+ PTR_FREE(tmp);
break;
default:
}
php_http_message_update_headers(msg);
- php_http_headers_to_string(str, &msg->hdrs TSRMLS_CC);
+ php_http_header_to_string(str, &msg->hdrs);
}
-PHP_HTTP_API void php_http_message_to_callback(php_http_message_t *msg, php_http_pass_callback_t cb, void *cb_arg)
+void php_http_message_to_callback(php_http_message_t *msg, php_http_pass_callback_t cb, void *cb_arg)
{
php_http_buffer_t str;
}
}
-PHP_HTTP_API void php_http_message_to_string(php_http_message_t *msg, char **string, size_t *length)
+void php_http_message_to_string(php_http_message_t *msg, char **string, size_t *length)
{
php_http_buffer_t str;
char *data;
php_http_buffer_dtor(&str);
}
-PHP_HTTP_API void php_http_message_serialize(php_http_message_t *message, char **string, size_t *length)
+void php_http_message_serialize(php_http_message_t *message, char **string, size_t *length)
{
char *buf;
php_http_buffer_t str;
php_http_buffer_dtor(&str);
}
-PHP_HTTP_API php_http_message_t *php_http_message_reverse(php_http_message_t *msg)
+php_http_message_t *php_http_message_reverse(php_http_message_t *msg)
{
- int i, c = 0;
-
- php_http_message_count(c, msg);
+ size_t i, c = php_http_message_count(msg);
if (c > 1) {
php_http_message_t *tmp = msg, **arr;
return msg;
}
-PHP_HTTP_API php_http_message_t *php_http_message_zip(php_http_message_t *one, php_http_message_t *two)
+php_http_message_t *php_http_message_zip(php_http_message_t *dst, php_http_message_t *src)
{
- php_http_message_t *dst = php_http_message_copy(one, NULL), *src = php_http_message_copy(two, NULL), *tmp_dst, *tmp_src, *ret = dst;
+ php_http_message_t *tmp_dst, *tmp_src, *ret = dst;
- while(dst && src) {
+ while (dst && src) {
tmp_dst = dst->parent;
tmp_src = src->parent;
dst->parent = src;
return ret;
}
-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 *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;
- TSRMLS_FETCH_FROM_CTX(from->ts);
if (from) {
info.type = from->type;
info.http = from->http;
- copy = temp = php_http_message_init(to, 0, php_http_message_body_copy(from->body, NULL) TSRMLS_CC);
+ copy = temp = php_http_message_init(to, 0, php_http_message_body_copy(from->body, NULL));
php_http_message_set_info(temp, &info);
- zend_hash_copy(&temp->hdrs, &from->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+ zend_hash_copy(&temp->hdrs, &from->hdrs, (copy_ctor_func_t) zval_add_ref);
if (parents) while (from->parent) {
info.type = from->parent->type;
info.http = from->parent->http;
- temp->parent = php_http_message_init(NULL, 0, php_http_message_body_copy(from->parent->body, NULL) TSRMLS_CC);
+ temp->parent = php_http_message_init(NULL, 0, php_http_message_body_copy(from->parent->body, NULL));
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 *));
+ array_copy(&from->parent->hdrs, &temp->parent->hdrs);
temp = temp->parent;
from = from->parent;
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)
+void php_http_message_dtor(php_http_message_t *message)
{
if (message) {
zend_hash_destroy(&message->hdrs);
switch (message->type) {
case PHP_HTTP_REQUEST:
- STR_SET(message->http.info.request.method, NULL);
- STR_SET(message->http.info.request.url, NULL);
+ PTR_SET(message->http.info.request.method, NULL);
+ PTR_SET(message->http.info.request.url, NULL);
break;
case PHP_HTTP_RESPONSE:
- STR_SET(message->http.info.response.status, NULL);
+ PTR_SET(message->http.info.response.status, NULL);
break;
default:
}
}
-PHP_HTTP_API void php_http_message_free(php_http_message_t **message)
+void php_http_message_free(php_http_message_t **message)
{
if (*message) {
if ((*message)->parent) {
}
}
-#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpMessage, method, 0, req_args)
-#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpMessage, method, 0)
-#define PHP_HTTP_MESSAGE_ME(method, visibility) PHP_ME(HttpMessage, method, PHP_HTTP_ARGS(HttpMessage, method), visibility)
-
-PHP_HTTP_BEGIN_ARGS(__construct, 0)
- PHP_HTTP_ARG_VAL(message, 0)
- PHP_HTTP_ARG_VAL(greedy, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_EMPTY_ARGS(getBody);
-PHP_HTTP_BEGIN_ARGS(setBody, 1)
- PHP_HTTP_ARG_VAL(body, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(addBody, 1)
- PHP_HTTP_ARG_VAL(body, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(getHeader, 1)
- PHP_HTTP_ARG_VAL(header, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(setHeader, 1)
- PHP_HTTP_ARG_VAL(header, 0)
- PHP_HTTP_ARG_VAL(value, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(addHeader, 2)
- PHP_HTTP_ARG_VAL(header, 0)
- PHP_HTTP_ARG_VAL(value, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_EMPTY_ARGS(getHeaders);
-PHP_HTTP_BEGIN_ARGS(setHeaders, 1)
- PHP_HTTP_ARG_VAL(headers, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(addHeaders, 1)
- PHP_HTTP_ARG_VAL(headers, 0)
- PHP_HTTP_ARG_VAL(append, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_EMPTY_ARGS(getType);
-PHP_HTTP_BEGIN_ARGS(setType, 1)
- PHP_HTTP_ARG_VAL(type, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_EMPTY_ARGS(getInfo);
-PHP_HTTP_BEGIN_ARGS(setInfo, 1)
- PHP_HTTP_ARG_VAL(http_info, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_EMPTY_ARGS(getResponseCode);
-PHP_HTTP_BEGIN_ARGS(setResponseCode, 1)
- PHP_HTTP_ARG_VAL(response_code, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_EMPTY_ARGS(getResponseStatus);
-PHP_HTTP_BEGIN_ARGS(setResponseStatus, 1)
- PHP_HTTP_ARG_VAL(response_status, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_EMPTY_ARGS(getRequestMethod);
-PHP_HTTP_BEGIN_ARGS(setRequestMethod, 1)
- PHP_HTTP_ARG_VAL(request_method, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_EMPTY_ARGS(getRequestUrl);
-PHP_HTTP_BEGIN_ARGS(setRequestUrl, 1)
- PHP_HTTP_ARG_VAL(url, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_EMPTY_ARGS(getHttpVersion);
-PHP_HTTP_BEGIN_ARGS(setHttpVersion, 1)
- PHP_HTTP_ARG_VAL(http_version, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_EMPTY_ARGS(getParentMessage);
-PHP_HTTP_EMPTY_ARGS(__toString);
-PHP_HTTP_BEGIN_ARGS(toString, 0)
- PHP_HTTP_ARG_VAL(include_parent, 0)
-PHP_HTTP_END_ARGS;
-PHP_HTTP_BEGIN_ARGS(toCallback, 1)
- PHP_HTTP_ARG_VAL(callback, 0)
-PHP_HTTP_END_ARGS;
-PHP_HTTP_BEGIN_ARGS(toStream, 1)
- PHP_HTTP_ARG_VAL(stream, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_EMPTY_ARGS(count);
-
-PHP_HTTP_EMPTY_ARGS(serialize);
-PHP_HTTP_BEGIN_ARGS(unserialize, 1)
- PHP_HTTP_ARG_VAL(serialized, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_EMPTY_ARGS(rewind);
-PHP_HTTP_EMPTY_ARGS(valid);
-PHP_HTTP_EMPTY_ARGS(key);
-PHP_HTTP_EMPTY_ARGS(current);
-PHP_HTTP_EMPTY_ARGS(next);
-
-PHP_HTTP_EMPTY_ARGS(detach);
-PHP_HTTP_BEGIN_ARGS(prepend, 1)
- PHP_HTTP_ARG_OBJ(http\\Message, message, 0)
-PHP_HTTP_END_ARGS;
-PHP_HTTP_EMPTY_ARGS(reverse);
-
-PHP_HTTP_BEGIN_ARGS(isMultipart, 0)
- PHP_HTTP_ARG_VAL(boundary, 1)
-PHP_HTTP_END_ARGS;
-PHP_HTTP_EMPTY_ARGS(splitMultipartBody);
-
-static zval *php_http_message_object_read_prop(zval *object, zval *member, int type PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC);
-static void php_http_message_object_write_prop(zval *object, zval *member, zval *value PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC);
-static zval **php_http_message_object_get_prop_ptr(zval *object, zval *member PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC);
-static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC);
-
-static zend_class_entry *php_http_message_class_entry;
-
-zend_class_entry *php_http_message_get_class_entry(void)
-{
- return php_http_message_class_entry;
-}
-
-static zend_function_entry php_http_message_method_entry[] = {
- PHP_HTTP_MESSAGE_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
- PHP_HTTP_MESSAGE_ME(getBody, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(setBody, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(addBody, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(getHeader, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(setHeader, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(addHeader, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(getHeaders, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(setHeaders, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(addHeaders, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(getType, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(setType, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(getInfo, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(setInfo, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(getResponseCode, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(setResponseCode, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(getResponseStatus, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(setResponseStatus, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(getRequestMethod, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(setRequestMethod, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(getRequestUrl, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(setRequestUrl, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(getHttpVersion, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(setHttpVersion, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(getParentMessage, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(toString, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(toCallback, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(toStream, ZEND_ACC_PUBLIC)
-
- /* implements Countable */
- PHP_HTTP_MESSAGE_ME(count, ZEND_ACC_PUBLIC)
-
- /* implements Serializable */
- PHP_HTTP_MESSAGE_ME(serialize, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(unserialize, ZEND_ACC_PUBLIC)
-
- /* implements Iterator */
- PHP_HTTP_MESSAGE_ME(rewind, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(valid, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(current, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(key, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(next, ZEND_ACC_PUBLIC)
+static zval *php_http_message_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *rv);
+static void php_http_message_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot);
- ZEND_MALIAS(HttpMessage, __toString, toString, PHP_HTTP_ARGS(HttpMessage, __toString), ZEND_ACC_PUBLIC)
-
- PHP_HTTP_MESSAGE_ME(detach, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(prepend, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(reverse, ZEND_ACC_PUBLIC)
-
- PHP_HTTP_MESSAGE_ME(isMultipart, ZEND_ACC_PUBLIC)
- PHP_HTTP_MESSAGE_ME(splitMultipartBody, ZEND_ACC_PUBLIC)
-
- EMPTY_FUNCTION_ENTRY
-};
static zend_object_handlers php_http_message_object_handlers;
static HashTable php_http_message_object_prophandlers;
-typedef void (*php_http_message_object_prophandler_func_t)(php_http_message_object_t *o, zval *v TSRMLS_DC);
+static void php_http_message_object_prophandler_hash_dtor(zval *pData)
+{
+ pefree(Z_PTR_P(pData), 1);
+}
+
+typedef void (*php_http_message_object_prophandler_func_t)(php_http_message_object_t *o, zval *v);
typedef struct php_http_message_object_prophandler {
php_http_message_object_prophandler_func_t read;
php_http_message_object_prophandler_func_t write;
} php_http_message_object_prophandler_t;
-static STATUS php_http_message_object_add_prophandler(const char *prop_str, size_t prop_len, php_http_message_object_prophandler_func_t read, php_http_message_object_prophandler_func_t write) {
+static ZEND_RESULT_CODE php_http_message_object_add_prophandler(const char *prop_str, size_t prop_len, php_http_message_object_prophandler_func_t read, php_http_message_object_prophandler_func_t write) {
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);
+ if (!zend_hash_str_add_mem(&php_http_message_object_prophandlers, prop_str, prop_len, (void *) &h, sizeof(h))) {
+ return FAILURE;
+ }
+ return SUCCESS;
}
-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 php_http_message_object_prophandler_t *php_http_message_object_get_prophandler(zend_string *name_str) {
+ return zend_hash_str_find_ptr(&php_http_message_object_prophandlers, name_str->val, name_str->len);
}
-static void php_http_message_object_prophandler_get_type(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_type(php_http_message_object_t *obj, zval *return_value) {
RETVAL_LONG(obj->message->type);
}
-static void php_http_message_object_prophandler_set_type(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
- zval *cpy = php_http_ztyp(IS_LONG, value);
- php_http_message_set_type(obj->message, Z_LVAL_P(cpy));
- zval_ptr_dtor(&cpy);
+static void php_http_message_object_prophandler_set_type(php_http_message_object_t *obj, zval *value) {
+ php_http_message_set_type(obj->message, zval_get_long(value));
}
-static void php_http_message_object_prophandler_get_request_method(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_request_method(php_http_message_object_t *obj, zval *return_value) {
if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message) && obj->message->http.info.request.method) {
- RETVAL_STRING(obj->message->http.info.request.method, 1);
+ RETVAL_STRING(obj->message->http.info.request.method);
} else {
RETVAL_NULL();
}
}
-static void php_http_message_object_prophandler_set_request_method(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
+static void php_http_message_object_prophandler_set_request_method(php_http_message_object_t *obj, zval *value) {
if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message)) {
- zval *cpy = php_http_ztyp(IS_STRING, value);
- STR_SET(obj->message->http.info.request.method, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
- zval_ptr_dtor(&cpy);
+ zend_string *zs = zval_get_string(value);
+ PTR_SET(obj->message->http.info.request.method, estrndup(zs->val, zs->len));
+ zend_string_release(zs);
}
}
-static void php_http_message_object_prophandler_get_request_url(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
- if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message) && obj->message->http.info.request.url) {
- RETVAL_STRING(obj->message->http.info.request.url, 1);
+static void php_http_message_object_prophandler_get_request_url(php_http_message_object_t *obj, zval *return_value) {
+ char *url_str;
+ size_t url_len;
+
+ if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message) && obj->message->http.info.request.url && php_http_url_to_string(obj->message->http.info.request.url, &url_str, &url_len, 0)) {
+ RETVAL_STR(php_http_cs2zs(url_str, url_len));
} else {
RETVAL_NULL();
}
}
-static void php_http_message_object_prophandler_set_request_url(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
+static void php_http_message_object_prophandler_set_request_url(php_http_message_object_t *obj, zval *value) {
if (PHP_HTTP_MESSAGE_TYPE(REQUEST, obj->message)) {
- zval *cpy = php_http_ztyp(IS_STRING, value);
- STR_SET(obj->message->http.info.request.url, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
- zval_ptr_dtor(&cpy);
+ PTR_SET(obj->message->http.info.request.url, php_http_url_from_zval(value, ~0));
}
}
-static void php_http_message_object_prophandler_get_response_status(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_response_status(php_http_message_object_t *obj, zval *return_value) {
if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message) && obj->message->http.info.response.status) {
- RETVAL_STRING(obj->message->http.info.response.status, 1);
+ RETVAL_STRING(obj->message->http.info.response.status);
} else {
RETVAL_NULL();
}
}
-static void php_http_message_object_prophandler_set_response_status(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
+static void php_http_message_object_prophandler_set_response_status(php_http_message_object_t *obj, zval *value) {
if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) {
- zval *cpy = php_http_ztyp(IS_STRING, value);
- STR_SET(obj->message->http.info.response.status, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
- zval_ptr_dtor(&cpy);
+ zend_string *zs = zval_get_string(value);
+ PTR_SET(obj->message->http.info.response.status, estrndup(zs->val, zs->len));
+ zend_string_release(zs);
}
}
-static void php_http_message_object_prophandler_get_response_code(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_response_code(php_http_message_object_t *obj, zval *return_value) {
if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) {
RETVAL_LONG(obj->message->http.info.response.code);
} else {
RETVAL_NULL();
}
}
-static void php_http_message_object_prophandler_set_response_code(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
+static void php_http_message_object_prophandler_set_response_code(php_http_message_object_t *obj, zval *value) {
if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, obj->message)) {
- zval *cpy = php_http_ztyp(IS_LONG, value);
- obj->message->http.info.response.code = Z_LVAL_P(cpy);
- STR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(obj->message->http.info.response.code)));
- zval_ptr_dtor(&cpy);
+ obj->message->http.info.response.code = zval_get_long(value);
+ PTR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(obj->message->http.info.response.code)));
}
}
-static void php_http_message_object_prophandler_get_http_version(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_http_version(php_http_message_object_t *obj, zval *return_value) {
char *version_str;
size_t version_len;
- php_http_version_to_string(&obj->message->http.version, &version_str, &version_len, NULL, NULL TSRMLS_CC);
- RETVAL_STRINGL(version_str, version_len, 0);
+ php_http_version_to_string(&obj->message->http.version, &version_str, &version_len, NULL, NULL);
+ RETVAL_STR(php_http_cs2zs(version_str, version_len));
}
-static void php_http_message_object_prophandler_set_http_version(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
- zval *cpy = php_http_ztyp(IS_STRING, value);
- php_http_version_parse(&obj->message->http.version, Z_STRVAL_P(cpy) TSRMLS_CC);
- zval_ptr_dtor(&cpy);
+static void php_http_message_object_prophandler_set_http_version(php_http_message_object_t *obj, zval *value) {
+ zend_string *zs = zval_get_string(value);
+ php_http_version_parse(&obj->message->http.version, zs->val);
+ zend_string_release(zs);
}
-static void php_http_message_object_prophandler_get_headers(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_headers(php_http_message_object_t *obj, zval *return_value ) {
array_init(return_value);
- zend_hash_copy(Z_ARRVAL_P(return_value), &obj->message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+ array_copy(&obj->message->hdrs, Z_ARRVAL_P(return_value));
}
-static void php_http_message_object_prophandler_set_headers(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
- zval *cpy = php_http_ztyp(IS_ARRAY, value);
+static void php_http_message_object_prophandler_set_headers(php_http_message_object_t *obj, zval *value) {
+ HashTable *headers;
+ zval *orig_value = value;
+
+ if (Z_TYPE_P(value) != IS_ARRAY && Z_TYPE_P(value) != IS_OBJECT) {
+ convert_to_array_ex(value);
+ }
+ headers = HASH_OF(value);
zend_hash_clean(&obj->message->hdrs);
- zend_hash_copy(&obj->message->hdrs, Z_ARRVAL_P(cpy), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
- zval_ptr_dtor(&cpy);
+ array_copy(headers, &obj->message->hdrs);
+
+ if (orig_value != value) {
+ zval_ptr_dtor(value);
+ }
}
-static void php_http_message_object_prophandler_get_body(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
- if (obj->body.handle) {
- RETVAL_OBJVAL(obj->body, 1);
+static void php_http_message_object_prophandler_get_body(php_http_message_object_t *obj, zval *return_value) {
+ if (obj->body) {
+ RETVAL_OBJECT(&obj->body->zo, 1);
} else {
RETVAL_NULL();
}
}
-static void php_http_message_object_prophandler_set_body(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
- php_http_message_object_set_body(obj, value TSRMLS_CC);
+static void php_http_message_object_prophandler_set_body(php_http_message_object_t *obj, zval *value) {
+ php_http_message_object_set_body(obj, value);
}
-static void php_http_message_object_prophandler_get_parent_message(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) {
+static void php_http_message_object_prophandler_get_parent_message(php_http_message_object_t *obj, zval *return_value) {
if (obj->message->parent) {
- RETVAL_OBJVAL(obj->parent, 1);
+ RETVAL_OBJECT(&obj->parent->zo, 1);
} else {
RETVAL_NULL();
}
}
-static void php_http_message_object_prophandler_set_parent_message(php_http_message_object_t *obj, zval *value TSRMLS_DC) {
- if (Z_TYPE_P(value) == IS_OBJECT && instanceof_function(Z_OBJCE_P(value), php_http_message_class_entry TSRMLS_CC)) {
- php_http_message_object_t *parent_obj = zend_object_store_get_object(value TSRMLS_CC);
+static void php_http_message_object_prophandler_set_parent_message(php_http_message_object_t *obj, zval *value) {
+ if (Z_TYPE_P(value) == IS_OBJECT && instanceof_function(Z_OBJCE_P(value), php_http_message_class_entry)) {
+ php_http_message_object_t *parent_obj = PHP_HTTP_OBJ(NULL, value);
if (obj->message->parent) {
- zend_objects_store_del_ref_by_handle(obj->parent.handle TSRMLS_CC);
+ zend_objects_store_del(&obj->parent->zo);
}
- Z_OBJ_ADDREF_P(value);
- obj->parent = Z_OBJVAL_P(value);
+ Z_ADDREF_P(value);
+ obj->parent = parent_obj;
obj->message->parent = parent_obj->message;
}
}
-PHP_MINIT_FUNCTION(http_message)
-{
- PHP_HTTP_REGISTER_CLASS(http, Message, http_message, php_http_object_get_class_entry(), 0);
- php_http_message_class_entry->create_object = php_http_message_object_new;
- memcpy(&php_http_message_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
- php_http_message_object_handlers.clone_obj = php_http_message_object_clone;
- php_http_message_object_handlers.read_property = php_http_message_object_read_prop;
- php_http_message_object_handlers.write_property = php_http_message_object_write_prop;
- 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);
-
- 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);
- php_http_message_object_add_prophandler(ZEND_STRL("type"), php_http_message_object_prophandler_get_type, php_http_message_object_prophandler_set_type);
- zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("body"), ZEND_ACC_PROTECTED TSRMLS_CC);
- php_http_message_object_add_prophandler(ZEND_STRL("body"), php_http_message_object_prophandler_get_body, php_http_message_object_prophandler_set_body);
- zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestMethod"), "", ZEND_ACC_PROTECTED TSRMLS_CC);
- php_http_message_object_add_prophandler(ZEND_STRL("requestMethod"), php_http_message_object_prophandler_get_request_method, php_http_message_object_prophandler_set_request_method);
- zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestUrl"), "", ZEND_ACC_PROTECTED TSRMLS_CC);
- php_http_message_object_add_prophandler(ZEND_STRL("requestUrl"), php_http_message_object_prophandler_get_request_url, php_http_message_object_prophandler_set_request_url);
- zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("responseStatus"), "", ZEND_ACC_PROTECTED TSRMLS_CC);
- php_http_message_object_add_prophandler(ZEND_STRL("responseStatus"), php_http_message_object_prophandler_get_response_status, php_http_message_object_prophandler_set_response_status);
- zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("responseCode"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
- php_http_message_object_add_prophandler(ZEND_STRL("responseCode"), php_http_message_object_prophandler_get_response_code, php_http_message_object_prophandler_set_response_code);
- zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("httpVersion"), ZEND_ACC_PROTECTED TSRMLS_CC);
- php_http_message_object_add_prophandler(ZEND_STRL("httpVersion"), php_http_message_object_prophandler_get_http_version, php_http_message_object_prophandler_set_http_version);
- zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("headers"), ZEND_ACC_PROTECTED TSRMLS_CC);
- php_http_message_object_add_prophandler(ZEND_STRL("headers"), php_http_message_object_prophandler_get_headers, php_http_message_object_prophandler_set_headers);
- zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("parentMessage"), ZEND_ACC_PROTECTED TSRMLS_CC);
- php_http_message_object_add_prophandler(ZEND_STRL("parentMessage"), php_http_message_object_prophandler_get_parent_message, php_http_message_object_prophandler_set_parent_message);
-
- zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_NONE"), PHP_HTTP_NONE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_REQUEST"), PHP_HTTP_REQUEST TSRMLS_CC);
- zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_RESPONSE"), PHP_HTTP_RESPONSE TSRMLS_CC);
-
- return SUCCESS;
-}
-
-PHP_MSHUTDOWN_FUNCTION(http_message)
-{
- zend_hash_destroy(&php_http_message_object_prophandlers);
-
- return SUCCESS;
-}
-
#define PHP_HTTP_MESSAGE_OBJECT_INIT(obj) \
do { \
if (!obj->message) { \
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC); \
+ obj->message = php_http_message_init(NULL, 0, NULL); \
} \
} while(0)
-void php_http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_DC)
+void php_http_message_object_reverse(zval *zmsg, zval *return_value)
{
- int i = 0;
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ size_t i;
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, zmsg);
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
/* count */
- php_http_message_count(i, obj->message);
+ i = php_http_message_count(obj->message);
if (i > 1) {
- zend_object_value *ovalues = NULL;
- php_http_message_object_t **objects = NULL;
+ php_http_message_object_t **objects;
int last;
objects = ecalloc(i, sizeof(**objects));
- ovalues = ecalloc(i, sizeof(*ovalues));
/* we are the first message */
objects[0] = obj;
- ovalues[0] = getThis()->value.obj;
/* fetch parents */
- for (i = 1; obj->parent.handle; ++i) {
- ovalues[i] = obj->parent;
- objects[i] = obj = zend_object_store_get_object_by_handle(obj->parent.handle TSRMLS_CC);
+ for (i = 1; obj->parent; ++i) {
+ objects[i] = obj = obj->parent;
}
/* reorder parents */
for (last = --i; i; --i) {
objects[i]->message->parent = objects[i-1]->message;
- objects[i]->parent = ovalues[i-1];
+ objects[i]->parent = objects[i-1];
}
objects[0]->message->parent = NULL;
- objects[0]->parent.handle = 0;
- objects[0]->parent.handlers = NULL;
+ objects[0]->parent = NULL;
/* add ref, because we previously have not been a parent message */
- Z_OBJ_ADDREF_P(getThis());
- RETVAL_OBJVAL(ovalues[last], 1);
+ Z_ADDREF_P(zmsg);
+ /* no addref, because we've been a parent message previously */
+ RETVAL_OBJECT(&objects[last]->zo, 0);
efree(objects);
- efree(ovalues);
} else {
- RETURN_ZVAL(getThis(), 1, 0);
+ RETURN_ZVAL(zmsg, 1, 0);
}
}
-void php_http_message_object_prepend(zval *this_ptr, zval *prepend, zend_bool top TSRMLS_DC)
+void php_http_message_object_prepend(zval *this_ptr, zval *prepend, zend_bool top)
{
- zval m;
php_http_message_t *save_parent_msg = NULL;
- zend_object_value save_parent_obj = {0, NULL};
- php_http_message_object_t *obj = zend_object_store_get_object(this_ptr TSRMLS_CC);
- php_http_message_object_t *prepend_obj = zend_object_store_get_object(prepend TSRMLS_CC);
-
- INIT_PZVAL(&m);
- m.type = IS_OBJECT;
+ php_http_message_object_t *save_parent_obj = NULL, *obj = PHP_HTTP_OBJ(NULL, this_ptr);
+ php_http_message_object_t *prepend_obj = PHP_HTTP_OBJ(NULL, prepend);
if (!top) {
save_parent_obj = obj->parent;
save_parent_msg = obj->message->parent;
} else {
/* iterate to the most parent object */
- while (obj->parent.handle) {
- m.value.obj = obj->parent;
- obj = zend_object_store_get_object(&m TSRMLS_CC);
+ while (obj->parent) {
+ obj = obj->parent;
}
}
/* prepend */
- obj->parent = prepend->value.obj;
+ obj->parent = prepend_obj;
obj->message->parent = prepend_obj->message;
/* add ref */
- zend_objects_store_add_ref(prepend TSRMLS_CC);
- while (prepend_obj->parent.handle) {
- m.value.obj = prepend_obj->parent;
- zend_objects_store_add_ref(&m TSRMLS_CC);
- prepend_obj = zend_object_store_get_object(&m TSRMLS_CC);
- }
+ Z_ADDREF_P(prepend);
if (!top) {
prepend_obj->parent = save_parent_obj;
}
}
-STATUS php_http_message_object_set_body(php_http_message_object_t *msg_obj, zval *zbody TSRMLS_DC)
+ZEND_RESULT_CODE php_http_message_object_set_body(php_http_message_object_t *msg_obj, zval *zbody)
{
- zval *tmp = NULL;
php_stream *s;
- zend_object_value ov;
+ zend_string *body_str;
php_http_message_body_t *body;
php_http_message_body_object_t *body_obj;
switch (Z_TYPE_P(zbody)) {
case IS_RESOURCE:
- php_stream_from_zval_no_verify(s, &zbody);
+ php_stream_from_zval_no_verify(s, zbody);
if (!s) {
- php_http_error(HE_THROW, PHP_HTTP_E_CLIENT, "not a valid stream resource");
+ php_http_throw(unexpected_val, "The stream is not a valid resource", NULL);
return FAILURE;
}
is_resource:
- body = php_http_message_body_init(NULL, s TSRMLS_CC);
- if (SUCCESS != php_http_new(&ov, php_http_message_body_get_class_entry(), (php_http_new_t) php_http_message_body_object_new_ex, NULL, body, NULL TSRMLS_CC)) {
+ body = php_http_message_body_init(NULL, s);
+ if (!(body_obj = php_http_message_body_object_new_ex(php_http_message_body_class_entry, body))) {
php_http_message_body_free(&body);
return FAILURE;
}
- MAKE_STD_ZVAL(tmp);
- ZVAL_OBJVAL(tmp, ov, 0);
- zbody = tmp;
break;
case IS_OBJECT:
- if (instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_get_class_entry() TSRMLS_CC)) {
- Z_OBJ_ADDREF_P(zbody);
+ if (instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry)) {
+ Z_ADDREF_P(zbody);
+ body_obj = PHP_HTTP_OBJ(NULL, zbody);
break;
}
/* no break */
default:
- tmp = php_http_ztyp(IS_STRING, zbody);
+ body_str = zval_get_string(zbody);
s = php_stream_temp_new();
- php_stream_write(s, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
- zval_ptr_dtor(&tmp);
- tmp = NULL;
+ php_stream_write(s, body_str->val, body_str->len);
+ zend_string_release(body_str);
goto is_resource;
}
- body_obj = zend_object_store_get_object(zbody TSRMLS_CC);
-
- if (msg_obj->body.handle) {
- zend_objects_store_del_ref_by_handle(msg_obj->body.handle TSRMLS_CC);
+ if (!body_obj->body) {
+ body_obj->body = php_http_message_body_init(NULL, NULL);
}
- php_http_message_body_free(&msg_obj->message->body);
-
- msg_obj->message->body = php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC);
- msg_obj->body = Z_OBJVAL_P(zbody);
-
- if (tmp) {
- FREE_ZVAL(tmp);
+ if (msg_obj->body) {
+ zend_objects_store_del(&msg_obj->body->zo);
}
+ if (msg_obj->message) {
+ php_http_message_body_free(&msg_obj->message->body);
+ msg_obj->message->body = body_obj->body;
+ } else {
+ msg_obj->message = php_http_message_init(NULL, 0, body_obj->body);
+ }
+ php_http_message_body_addref(body_obj->body);
+ msg_obj->body = body_obj;
+
return SUCCESS;
}
-zend_object_value php_http_message_object_new(zend_class_entry *ce TSRMLS_DC)
+ZEND_RESULT_CODE php_http_message_object_init_body_object(php_http_message_object_t *obj)
{
- return php_http_message_object_new_ex(ce, NULL, NULL TSRMLS_CC);
+ php_http_message_body_addref(obj->message->body);
+ return php_http_new((void *) &obj->body, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body);
}
-zend_object_value php_http_message_object_new_ex(zend_class_entry *ce, php_http_message_t *msg, php_http_message_object_t **ptr TSRMLS_DC)
+zend_object *php_http_message_object_new(zend_class_entry *ce)
{
- zend_object_value ov;
- php_http_message_object_t *o;
+ return &php_http_message_object_new_ex(ce, NULL)->zo;
+}
- o = ecalloc(1, sizeof(php_http_message_object_t));
- zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
- object_properties_init((zend_object *) o, ce);
+php_http_message_object_t *php_http_message_object_new_ex(zend_class_entry *ce, php_http_message_t *msg)
+{
+ php_http_message_object_t *o;
- if (ptr) {
- *ptr = o;
- }
+ o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce));
+ zend_object_std_init(&o->zo, ce);
+ object_properties_init(&o->zo, ce);
if (msg) {
o->message = msg;
if (msg->parent) {
- o->parent = php_http_message_object_new_ex(ce, msg->parent, NULL TSRMLS_CC);
+ o->parent = php_http_message_object_new_ex(ce, msg->parent);
}
- 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);
+ o->body = php_http_message_body_object_new_ex(php_http_message_body_class_entry, php_http_message_body_init(&msg->body, NULL));
}
- ov.handle = zend_objects_store_put((zend_object *) o, NULL, php_http_message_object_free, NULL TSRMLS_CC);
- ov.handlers = &php_http_message_object_handlers;
+ o->zo.handlers = &php_http_message_object_handlers;
- return ov;
+ return o;
}
-zend_object_value php_http_message_object_clone(zval *this_ptr TSRMLS_DC)
+zend_object *php_http_message_object_clone(zval *this_ptr)
{
- zend_object_value new_ov;
php_http_message_object_t *new_obj = NULL;
- php_http_message_object_t *old_obj = zend_object_store_get_object(this_ptr TSRMLS_CC);
+ php_http_message_object_t *old_obj = PHP_HTTP_OBJ(NULL, this_ptr);
- new_ov = php_http_message_object_new_ex(old_obj->zo.ce, php_http_message_copy(old_obj->message, NULL), &new_obj TSRMLS_CC);
- zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
+ new_obj = php_http_message_object_new_ex(old_obj->zo.ce, php_http_message_copy(old_obj->message, NULL));
+ zend_objects_clone_members(&new_obj->zo, &old_obj->zo);
- return new_ov;
+ return &new_obj->zo;
}
-void php_http_message_object_free(void *object TSRMLS_DC)
+void php_http_message_object_free(zend_object *object)
{
- php_http_message_object_t *o = (php_http_message_object_t *) object;
+ php_http_message_object_t *o = PHP_HTTP_OBJ(object, NULL);
- if (o->iterator) {
+ if (!Z_ISUNDEF(o->iterator)) {
zval_ptr_dtor(&o->iterator);
- o->iterator = NULL;
+ ZVAL_UNDEF(&o->iterator);
}
if (o->message) {
/* do NOT free recursivly */
efree(o->message);
o->message = NULL;
}
- if (o->parent.handle) {
- zend_objects_store_del_ref_by_handle(o->parent.handle TSRMLS_CC);
+ if (o->parent) {
+ if (GC_REFCOUNT(&o->parent->zo) == 1) {
+ zend_objects_store_del(&o->parent->zo);
+ }
+ zend_objects_store_del(&o->parent->zo);
+ o->parent = NULL;
}
- if (o->body.handle) {
- zend_objects_store_del_ref_by_handle(o->body.handle TSRMLS_CC);
+ if (o->body) {
+ if (GC_REFCOUNT(&o->body->zo) == 1) {
+ zend_objects_store_del(&o->body->zo);
+ }
+ zend_objects_store_del(&o->body->zo);
+ o->body = NULL;
}
- zend_object_std_dtor((zend_object *) o TSRMLS_CC);
- efree(o);
+ zend_object_std_dtor(object);
}
-
-static zval **php_http_message_object_get_prop_ptr(zval *object, zval *member PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC)
+static zval *php_http_message_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *tmp)
{
- zval *copy = php_http_ztyp(IS_STRING, member);
-
- if (php_http_message_object_has_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy))) {
- zval_ptr_dtor(©);
- return &php_http_property_proxy_init(NULL, object, member, NULL TSRMLS_CC)->myself;
- }
- zval_ptr_dtor(©);
-
- return zend_get_std_object_handlers()->get_property_ptr_ptr(object, member PHP_HTTP_ZEND_LITERAL_CC TSRMLS_CC);
-}
+ zval *return_value;
+ zend_string *member_name = zval_get_string(member);
+ php_http_message_object_prophandler_t *handler = php_http_message_object_get_prophandler(member_name);
-static zval *php_http_message_object_read_prop(zval *object, zval *member, int type PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC)
-{
- php_http_message_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
- php_http_message_object_prophandler_t *handler;
- zval *return_value, *copy = php_http_ztyp(IS_STRING, member);
+ if (!handler || type == BP_VAR_R || type == BP_VAR_IS) {
+ return_value = zend_get_std_object_handlers()->read_property(object, member, type, cache_slot, tmp);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ if (handler) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object);
- if (SUCCESS == php_http_message_object_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) {
- if (type == BP_VAR_R) {
- ALLOC_ZVAL(return_value);
- Z_SET_REFCOUNT_P(return_value, 0);
- Z_UNSET_ISREF_P(return_value);
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ handler->read(obj, tmp);
- handler->read(obj, return_value TSRMLS_CC);
- } else {
- zend_error(E_ERROR, "Cannot access HttpMessage properties by reference or array key/index");
- return_value = NULL;
+ zval_ptr_dtor(return_value);
+ ZVAL_COPY_VALUE(return_value, tmp);
}
+ zend_string_release(member_name);
+ return return_value;
} else {
- return_value = zend_get_std_object_handlers()->read_property(object, member, type PHP_HTTP_ZEND_LITERAL_CC TSRMLS_CC);
- }
+ php_property_proxy_t *proxy;
+ php_property_proxy_object_t *proxy_obj;
- zval_ptr_dtor(©);
+ proxy = php_property_proxy_init(object, member_name);
+ proxy_obj = php_property_proxy_object_new_ex(NULL, proxy);
- return return_value;
+ ZVAL_OBJ(tmp, &proxy_obj->zo);
+ zend_string_release(member_name);
+ return tmp;
+ }
}
-static void php_http_message_object_write_prop(zval *object, zval *member, zval *value PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC)
+static void php_http_message_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot)
{
- php_http_message_object_t *obj = zend_object_store_get_object(object TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object);
php_http_message_object_prophandler_t *handler;
- zval *copy = php_http_ztyp(IS_STRING, member);
+ zend_string *member_name = zval_get_string(member);
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- if (SUCCESS == php_http_message_object_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) {
- handler->write(obj, value TSRMLS_CC);
+ if ((handler = php_http_message_object_get_prophandler(member_name))) {
+ handler->write(obj, value);
} else {
- zend_get_std_object_handlers()->write_property(object, member, value PHP_HTTP_ZEND_LITERAL_CC TSRMLS_CC);
+ zend_get_std_object_handlers()->write_property(object, member, value, cache_slot);
}
- zval_ptr_dtor(©);
+ zend_string_release(member_name);
}
-static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC)
+static HashTable *php_http_message_object_get_debug_info(zval *object, int *is_temp)
{
- 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;
+ zval tmp;
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object);
+ HashTable *props = zend_get_std_object_handlers()->get_properties(object);
+ char *ver_str, *url_str = NULL;
+ size_t ver_len, url_len = 0;
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ *is_temp = 0;
- INIT_PZVAL_ARRAY(&array, props);
-
-#define ASSOC_PROP(ptype, n, val) \
- do { \
- zend_property_info *pi; \
- if (SUCCESS == zend_hash_find(&obj->zo.ce->properties_info, n, sizeof(n), (void *) &pi)) { \
- add_assoc_ ##ptype## _ex(&array, pi->name, pi->name_length + 1, val); \
- } \
- } while(0) \
-
-#define ASSOC_STRING(name, val) ASSOC_STRINGL(name, val, strlen(val))
-#define ASSOC_STRINGL(name, val, len) ASSOC_STRINGL_EX(name, val, len, 1)
-#define ASSOC_STRINGL_EX(n, val, len, cpy) \
+#define UPDATE_PROP(name_str, action_with_tmp) \
do { \
zend_property_info *pi; \
- if (SUCCESS == zend_hash_find(&obj->zo.ce->properties_info, n, sizeof(n), (void *) &pi)) { \
- add_assoc_stringl_ex(&array, pi->name, pi->name_length + 1, val, len, cpy); \
+ if ((pi = zend_hash_str_find_ptr(&obj->zo.ce->properties_info, name_str, lenof(name_str)))) { \
+ action_with_tmp; \
+ zend_hash_update_ind(props, pi->name, &tmp); \
} \
} while(0)
- ASSOC_PROP(long, "type", msg->type);
- ASSOC_STRINGL_EX("httpVersion", version, spprintf(&version, 0, "%u.%u", msg->http.version.major, msg->http.version.minor), 0);
+ UPDATE_PROP("type", ZVAL_LONG(&tmp, obj->message->type));
- switch (msg->type) {
+ ver_len = spprintf(&ver_str, 0, "%u.%u", obj->message->http.version.major, obj->message->http.version.minor);
+ UPDATE_PROP("httpVersion", ZVAL_STR(&tmp, php_http_cs2zs(ver_str, ver_len)));
+
+ 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));
+ UPDATE_PROP("responseCode", ZVAL_LONG(&tmp, 0));
+ UPDATE_PROP("responseStatus", ZVAL_EMPTY_STRING(&tmp));
+ UPDATE_PROP("requestMethod", ZVAL_STRING(&tmp, STR_PTR(obj->message->http.info.request.method)));
+ if (obj->message->http.info.request.url) {
+ php_http_url_to_string(obj->message->http.info.request.url, &url_str, &url_len, 0);
+ UPDATE_PROP("requestUrl", ZVAL_STR(&tmp, php_http_cs2zs(url_str, url_len)));
+ } else {
+ UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp));
+ }
+
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_STRINGL("requestMethod", "", 0);
- ASSOC_STRINGL("requestUrl", "", 0);
+ UPDATE_PROP("responseCode", ZVAL_LONG(&tmp, obj->message->http.info.response.code));
+ UPDATE_PROP("responseStatus", ZVAL_STRING(&tmp, STR_PTR(obj->message->http.info.response.status)));
+ UPDATE_PROP("requestMethod", ZVAL_EMPTY_STRING(&tmp));
+ UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp));
break;
case PHP_HTTP_NONE:
default:
- ASSOC_PROP(long, "responseCode", 0);
- ASSOC_STRINGL("responseStatus", "", 0);
- ASSOC_STRINGL("requestMethod", "", 0);
- ASSOC_STRINGL("requestUrl", "", 0);
+ UPDATE_PROP("responseCode", ZVAL_LONG(&tmp, 0));
+ UPDATE_PROP("responseStatus", ZVAL_EMPTY_STRING(&tmp));
+ UPDATE_PROP("requestMethod", ZVAL_EMPTY_STRING(&tmp));
+ UPDATE_PROP("requestUrl", ZVAL_EMPTY_STRING(&tmp));
break;
}
- 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 *));
- ASSOC_PROP(zval, "headers", headers);
+ UPDATE_PROP("headers",
+ array_init(&tmp);
+ array_copy(&obj->message->hdrs, Z_ARRVAL(tmp));
+ );
- 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_init(&obj->message->body, NULL TSRMLS_CC), NULL TSRMLS_CC);
- }
- ZVAL_OBJVAL(body, obj->body, 1);
- ASSOC_PROP(zval, "body", body);
+ UPDATE_PROP("body",
+ if (obj->body) {
+ ZVAL_OBJECT(&tmp, &obj->body->zo, 1);
+ } else {
+ ZVAL_NULL(&tmp);
+ }
+ );
- MAKE_STD_ZVAL(parent);
- if (msg->parent) {
- ZVAL_OBJVAL(parent, obj->parent, 1);
- } else {
- ZVAL_NULL(parent);
- }
- ASSOC_PROP(zval, "parentMessage", parent);
+ UPDATE_PROP("parentMessage",
+ if (obj->message->parent) {
+ ZVAL_OBJECT(&tmp, &obj->parent->zo, 1);
+ } else {
+ ZVAL_NULL(&tmp);
+ }
+ );
return props;
}
-/* PHP */
-
-PHP_METHOD(HttpMessage, __construct)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___construct, 0, 0, 0)
+ ZEND_ARG_INFO(0, message)
+ ZEND_ARG_INFO(0, greedy)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, __construct)
{
zend_bool greedy = 1;
zval *zmessage = NULL;
php_http_message_t *msg = NULL;
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-
- with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!b", &zmessage, &greedy) && zmessage) {
- if (Z_TYPE_P(zmessage) == IS_RESOURCE) {
- php_stream *s;
- php_http_message_parser_t p;
-
- php_stream_from_zval(s, &zmessage);
- if (s && php_http_message_parser_init(&p TSRMLS_CC)) {
- unsigned flags = (greedy ? PHP_HTTP_MESSAGE_PARSER_GREEDY : 0);
-
- php_http_message_parser_parse_stream(&p, s, flags, &msg);
- php_http_message_parser_dtor(&p);
- }
-
- if (!msg) {
- php_http_error(HE_THROW, PHP_HTTP_E_MESSAGE, "could not parse message from stream");
- }
- } else {
- zmessage = php_http_ztyp(IS_STRING, zmessage);
- if (!(msg = php_http_message_parse(NULL, Z_STRVAL_P(zmessage), Z_STRLEN_P(zmessage), greedy TSRMLS_CC))) {
- php_http_error(HE_THROW, PHP_HTTP_E_MESSAGE, "could not parse message: %.*s", MIN(25, Z_STRLEN_P(zmessage)), Z_STRVAL_P(zmessage));
- }
- zval_ptr_dtor(&zmessage);
- }
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
+ zend_error_handling zeh;
+
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!b", &zmessage, &greedy), invalid_arg, return);
+
+ zend_replace_error_handling(EH_THROW, php_http_exception_bad_message_class_entry, &zeh);
+ if (zmessage && Z_TYPE_P(zmessage) == IS_RESOURCE) {
+ php_stream *s;
+ php_http_message_parser_t p;
+ zend_error_handling zeh;
- if (msg) {
- 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);
+ zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh);
+ php_stream_from_zval(s, zmessage);
+ zend_restore_error_handling(&zeh);
+
+ if (s && php_http_message_parser_init(&p)) {
+ unsigned flags = (greedy ? PHP_HTTP_MESSAGE_PARSER_GREEDY : 0);
+ php_http_buffer_t buf;
+
+ 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);
}
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- } end_error_handling();
+ if (!msg && !EG(exception)) {
+ php_http_throw(bad_message, "Empty message received from stream", NULL);
+ }
+ } else if (zmessage) {
+ zend_string *zs_msg = zval_get_string(zmessage);
+
+ msg = php_http_message_parse(NULL, zs_msg->val, zs_msg->len, greedy);
+
+ if (!msg && !EG(exception)) {
+ php_http_throw(bad_message, "Could not parse message: %.*s", MIN(25, zs_msg->len), zs_msg->val);
+ }
+ zend_string_release(zs_msg);
+ }
+
+ if (msg) {
+ php_http_message_dtor(obj->message);
+ obj->message = msg;
+ if (obj->message->parent) {
+ obj->parent = php_http_message_object_new_ex(obj->zo.ce, obj->message->parent);
+ }
+ }
+ zend_restore_error_handling(&zeh);
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
}
-PHP_METHOD(HttpMessage, getBody)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getBody, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, getBody)
{
- with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj;
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- if (!obj->body.handle) {
- 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);
- }
- }
- } end_error_handling();
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ if (!obj->body) {
+ php_http_message_object_init_body_object(obj);
+
+ }
+ if (obj->body) {
+ RETVAL_OBJECT(&obj->body->zo, 1);
+ }
}
-PHP_METHOD(HttpMessage, setBody)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setBody, 0, 0, 1)
+ ZEND_ARG_OBJ_INFO(0, body, http\\Message\\Body, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, setBody)
{
zval *zbody;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zbody, php_http_message_body_get_class_entry())) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zbody, php_http_message_body_class_entry)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- php_http_message_object_prophandler_set_body(obj, zbody TSRMLS_CC);
+ php_http_message_object_prophandler_set_body(obj, zbody);
}
RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpMessage, addBody)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_addBody, 0, 0, 1)
+ ZEND_ARG_OBJ_INFO(0, body, http\\Message\\Body, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, addBody)
{
zval *new_body;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &new_body, php_http_message_body_get_class_entry())) {
- 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);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &new_body, php_http_message_body_class_entry)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
+ php_http_message_body_object_t *new_obj = PHP_HTTP_OBJ(NULL, new_body);
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
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);
}
-
-PHP_METHOD(HttpMessage, getHeader)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getHeader, 0, 0, 1)
+ ZEND_ARG_INFO(0, header)
+ ZEND_ARG_INFO(0, into_class)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, getHeader)
{
char *header_str;
- int header_len;
+ size_t header_len;
+ zend_class_entry *header_ce = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &header_str, &header_len)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|C!", &header_str, &header_len, &header_ce)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
zval *header;
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- if ((header = php_http_message_header(obj->message, header_str, header_len, 0))) {
- RETURN_ZVAL(header, 1, 1);
+ if ((header = php_http_message_header(obj->message, header_str, header_len))) {
+ if (!header_ce) {
+ RETURN_ZVAL(header, 1, 0);
+ } else if (instanceof_function(header_ce, php_http_header_class_entry)) {
+ php_http_object_method_t cb;
+ zval argv[2];
+
+ ZVAL_STRINGL(&argv[0], header_str, header_len);
+ ZVAL_COPY(&argv[1], header);
+
+ object_init_ex(return_value, header_ce);
+ php_http_object_method_init(&cb, return_value, ZEND_STRL("__construct"));
+ php_http_object_method_call(&cb, return_value, NULL, 2, argv);
+ php_http_object_method_dtor(&cb);
+
+ zval_ptr_dtor(&argv[0]);
+ zval_ptr_dtor(&argv[1]);
+
+ return;
+ } else {
+ php_error_docref(NULL, E_WARNING, "Class '%s' is not as descendant of http\\Header", header_ce->name->val);
+ }
}
}
RETURN_FALSE;
}
-PHP_METHOD(HttpMessage, getHeaders)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getHeaders, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, getHeaders)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
}
}
-PHP_METHOD(HttpMessage, setHeader)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setHeader, 0, 0, 1)
+ ZEND_ARG_INFO(0, header)
+ ZEND_ARG_INFO(0, value)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, setHeader)
{
zval *zvalue = NULL;
char *name_str;
- int name_len;
+ size_t name_len;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z!", &name_str, &name_len, &zvalue)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s|z!", &name_str, &name_len, &zvalue)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
char *name = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
if (!zvalue) {
- zend_symtable_del(&obj->message->hdrs, name, name_len + 1);
+ zend_symtable_str_del(&obj->message->hdrs, name, name_len);
} else {
- Z_ADDREF_P(zvalue);
- zend_symtable_update(&obj->message->hdrs, name, name_len + 1, &zvalue, sizeof(void *), NULL);
+ Z_TRY_ADDREF_P(zvalue);
+ zend_symtable_str_update(&obj->message->hdrs, name, name_len, zvalue);
}
efree(name);
}
RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpMessage, setHeaders)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setHeaders, 0, 0, 1)
+ ZEND_ARG_ARRAY_INFO(0, headers, 1)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, setHeaders)
{
zval *new_headers = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/!", &new_headers)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "a/!", &new_headers)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpMessage, addHeader)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_addHeader, 0, 0, 2)
+ ZEND_ARG_INFO(0, header)
+ ZEND_ARG_INFO(0, value)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, addHeader)
{
zval *zvalue;
char *name_str;
- int name_len;
+ size_t name_len;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name_str, &name_len, &zvalue)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &name_str, &name_len, &zvalue)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
char *name = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
zval *header;
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- Z_ADDREF_P(zvalue);
- if ((header = php_http_message_header(obj->message, name, name_len, 0))) {
+ Z_TRY_ADDREF_P(zvalue);
+ if ((header = php_http_message_header(obj->message, name, name_len))) {
convert_to_array(header);
- zend_hash_next_index_insert(Z_ARRVAL_P(header), &zvalue, sizeof(void *), NULL);
- zval_ptr_dtor(&header);
+ zend_hash_next_index_insert(Z_ARRVAL_P(header), zvalue);
} else {
- zend_symtable_update(&obj->message->hdrs, name, name_len + 1, &zvalue, sizeof(void *), NULL);
+ zend_symtable_str_update(&obj->message->hdrs, name, name_len, zvalue);
}
efree(name);
}
RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpMessage, addHeaders)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_addHeaders, 0, 0, 1)
+ ZEND_ARG_ARRAY_INFO(0, headers, 0)
+ ZEND_ARG_INFO(0, append)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, addHeaders)
{
zval *new_headers;
zend_bool append = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &new_headers, &append)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "a|b", &new_headers, &append)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpMessage, getType)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getType, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, getType)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
}
}
-PHP_METHOD(HttpMessage, setType)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setType, 0, 0, 1)
+ ZEND_ARG_INFO(0, type)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, setType)
{
- long type;
+ zend_long type;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &type)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &type)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpMessage, getInfo)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getInfo, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, getInfo)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ char *str, *tmp = NULL;
+ size_t len;
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
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, ""));
+ len = spprintf(&str, 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, ""));
+ len = spprintf(&str, 0, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&obj->message->http, tmp, ""));
+ PTR_FREE(tmp);
break;
default:
RETURN_NULL();
break;
}
- Z_TYPE_P(return_value) = IS_STRING;
- return;
+
+ RETVAL_STR(php_http_cs2zs(str, len));
}
- RETURN_FALSE;
}
-PHP_METHOD(HttpMessage, setInfo)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setInfo, 0, 0, 1)
+ ZEND_ARG_INFO(0, http_info)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, setInfo)
{
char *str;
- int len;
+ size_t len;
+ php_http_message_object_t *obj;
php_http_info_t inf;
- if ( SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len)
- && php_http_info_parse(&inf, str TSRMLS_CC)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &len), invalid_arg, return);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- php_http_message_set_info(obj->message, &inf);
- php_http_info_dtor(&inf);
+ if (!php_http_info_parse(&inf, str)) {
+ php_http_throw(bad_header, "Could not parse message info '%s'", str);
+ return;
}
+
+ php_http_message_set_info(obj->message, &inf);
+ php_http_info_dtor(&inf);
+
RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpMessage, getHttpVersion)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getHttpVersion, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, getHttpVersion)
{
if (SUCCESS == zend_parse_parameters_none()) {
char *str;
size_t len;
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- php_http_version_to_string(&obj->message->http.version, &str, &len, NULL, NULL TSRMLS_CC);
- RETURN_STRINGL(str, len, 0);
+ php_http_version_to_string(&obj->message->http.version, &str, &len, NULL, NULL);
+ RETURN_STR(php_http_cs2zs(str, len));
}
-
- RETURN_FALSE;
}
-PHP_METHOD(HttpMessage, setHttpVersion)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setHttpVersion, 0, 0, 1)
+ ZEND_ARG_INFO(0, http_version)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, setHttpVersion)
{
char *v_str;
- int v_len;
+ size_t v_len;
+ php_http_version_t version;
+ php_http_message_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &v_str, &v_len)) {
- php_http_version_t version;
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &v_str, &v_len), invalid_arg, return);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ php_http_expect(php_http_version_parse(&version, v_str), unexpected_val, return);
+
+ obj->message->http.version = version;
- if (php_http_version_parse(&version, v_str TSRMLS_CC)) {
- obj->message->http.version = version;
- }
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpMessage, getResponseCode)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getResponseCode, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, getResponseCode)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
+ if (obj->message->type != PHP_HTTP_RESPONSE) {
+ php_error_docref(NULL, E_WARNING, "http\\Message is not if type response");
+ RETURN_FALSE;
+ }
+
RETURN_LONG(obj->message->http.info.response.code);
}
- RETURN_FALSE;
}
-PHP_METHOD(HttpMessage, setResponseCode)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setResponseCode, 0, 0, 1)
+ ZEND_ARG_INFO(0, response_code)
+ ZEND_ARG_INFO(0, strict)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, setResponseCode)
{
- long code;
+ zend_long code;
zend_bool strict = 1;
+ php_http_message_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &code, &strict)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l|b", &code, &strict), invalid_arg, return);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
- if (strict && (code < 100 || code > 599)) {
- php_http_error(HE_WARNING, PHP_HTTP_E_INVALID_PARAM, "Invalid response code (100-599): %ld", code);
- RETURN_FALSE;
- }
+ if (obj->message->type != PHP_HTTP_RESPONSE) {
+ php_http_throw(bad_method_call, "http\\Message is not of type response", NULL);
+ return;
+ }
- obj->message->http.info.response.code = code;
- STR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(code)));
+ if (strict && (code < 100 || code > 599)) {
+ php_http_throw(invalid_arg, "Invalid response code (100-599): %ld", code);
+ return;
}
+
+ obj->message->http.info.response.code = code;
+ PTR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(code)));
+
RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpMessage, getResponseStatus)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getResponseStatus, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, getResponseStatus)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
+ if (obj->message->type != PHP_HTTP_RESPONSE) {
+ php_error_docref(NULL, E_WARNING, "http\\Message is not of type response");
+ }
+
if (obj->message->http.info.response.status) {
- RETURN_STRING(obj->message->http.info.response.status, 1);
+ RETURN_STRING(obj->message->http.info.response.status);
} else {
RETURN_EMPTY_STRING();
}
}
-
- RETURN_FALSE;
}
-PHP_METHOD(HttpMessage, setResponseStatus)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setResponseStatus, 0, 0, 1)
+ ZEND_ARG_INFO(0, response_status)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, setResponseStatus)
{
char *status;
- int status_len;
+ size_t status_len;
+ php_http_message_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &status, &status_len)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &status, &status_len), invalid_arg, return);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
- STR_SET(obj->message->http.info.response.status, estrndup(status, status_len));
+ if (obj->message->type != PHP_HTTP_RESPONSE) {
+ php_http_throw(bad_method_call, "http\\Message is not of type response", NULL);
}
+
+ PTR_SET(obj->message->http.info.response.status, estrndup(status, status_len));
RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpMessage, getRequestMethod)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getRequestMethod, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, getRequestMethod)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
+ if (obj->message->type != PHP_HTTP_REQUEST) {
+ php_error_docref(NULL, E_WARNING, "http\\Message is not of type request");
+ RETURN_FALSE;
+ }
+
if (obj->message->http.info.request.method) {
- RETURN_STRING(obj->message->http.info.request.method, 1);
+ RETURN_STRING(obj->message->http.info.request.method);
} else {
RETURN_EMPTY_STRING();
}
}
-
- RETURN_FALSE;
}
-PHP_METHOD(HttpMessage, setRequestMethod)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setRequestMethod, 0, 0, 1)
+ ZEND_ARG_INFO(0, request_method)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, setRequestMethod)
{
char *method;
- int method_len;
+ size_t method_len;
+ php_http_message_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &method, &method_len), invalid_arg, return);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
- PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
- if (method_len < 1) {
- php_http_error(HE_WARNING, PHP_HTTP_E_INVALID_PARAM, "Cannot set HttpMessage::requestMethod to an empty string");
- RETURN_FALSE;
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ if (obj->message->type != PHP_HTTP_REQUEST) {
+ php_http_throw(bad_method_call, "http\\Message is not of type request", NULL);
+ return;
+ }
- STR_SET(obj->message->http.info.request.method, estrndup(method, method_len));
+ if (method_len < 1) {
+ php_http_throw(invalid_arg, "Cannot set http\\Message's request method to an empty string", NULL);
+ return;
}
+
+ PTR_SET(obj->message->http.info.request.method, estrndup(method, method_len));
RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpMessage, getRequestUrl)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getRequestUrl, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, getRequestUrl)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
+ if (obj->message->type != PHP_HTTP_REQUEST) {
+ php_error_docref(NULL, E_WARNING, "http\\Message is not of type request");
+ RETURN_FALSE;
+ }
+
if (obj->message->http.info.request.url) {
- RETURN_STRING(obj->message->http.info.request.url, 1);
+ char *url_str;
+ size_t url_len;
+
+ php_http_url_to_string(obj->message->http.info.request.url, &url_str, &url_len, 0);
+ RETURN_STR(php_http_cs2zs(url_str, url_len));
} else {
RETURN_EMPTY_STRING();
}
}
-
- RETURN_FALSE;
}
-PHP_METHOD(HttpMessage, setRequestUrl)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setRequestUrl, 0, 0, 1)
+ ZEND_ARG_INFO(0, url)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, setRequestUrl)
{
- char *url_str;
- int url_len;
+ zval *zurl;
+ php_http_url_t *url;
+ php_http_message_object_t *obj;
+ zend_error_handling zeh;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url_str, &url_len)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zurl), invalid_arg, return);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ obj = PHP_HTTP_OBJ(NULL, getThis());
- PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
- if (url_len < 1) {
- php_http_error(HE_WARNING, PHP_HTTP_E_INVALID_PARAM, "Cannot set HttpMessage::requestUrl to an empty string");
- RETURN_FALSE;
- }
- STR_SET(obj->message->http.info.request.url, estrndup(url_str, url_len));
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ if (obj->message->type != PHP_HTTP_REQUEST) {
+ php_http_throw(bad_method_call, "http\\Message is not of type request", NULL);
+ return;
+ }
+
+ zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh);
+ url = php_http_url_from_zval(zurl, ~0);
+ zend_restore_error_handling(&zeh);
+
+ if (url && php_http_url_is_empty(url)) {
+ php_http_url_free(&url);
+ php_http_throw(invalid_arg, "Cannot set http\\Message's request url to an empty string", NULL);
+ } else if (url) {
+ PTR_SET(obj->message->http.info.request.url, url);
}
+
RETVAL_ZVAL(getThis(), 1, 0);
}
-
-PHP_METHOD(HttpMessage, getParentMessage)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getParentMessage, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, getParentMessage)
{
- with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj;
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- if (obj->message->parent) {
- RETVAL_OBJVAL(obj->parent, 1);
- } else {
- php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "HttpMessage does not have a parent message");
- }
- }
- } end_error_handling();
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ if (!obj->message->parent) {
+ php_http_throw(unexpected_val, "http\\Message has not parent message", NULL);
+ return;
+ }
+
+ RETVAL_OBJECT(&obj->parent->zo, 1);
}
-PHP_METHOD(HttpMessage, toString)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___toString, 0, 0, 0)
+ZEND_END_ARG_INFO();
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toString, 0, 0, 0)
+ ZEND_ARG_INFO(0, include_parent)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, toString)
{
zend_bool include_parent = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &include_parent)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &include_parent)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
char *string;
size_t length;
php_http_message_to_string(obj->message, &string, &length);
}
if (string) {
- RETURN_STRINGL(string, length, 0);
+ RETURN_STR(php_http_cs2zs(string, length));
}
}
RETURN_EMPTY_STRING();
}
-PHP_METHOD(HttpMessage, toStream)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toStream, 0, 0, 1)
+ ZEND_ARG_INFO(0, stream)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, toStream)
{
zval *zstream;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zstream)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
php_stream *s;
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- php_stream_from_zval(s, &zstream);
+ php_stream_from_zval(s, zstream);
php_http_message_to_callback(obj->message, (php_http_pass_callback_t) _php_stream_write, s);
}
}
-PHP_METHOD(HttpMessage, toCallback)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toCallback, 0, 0, 1)
+ ZEND_ARG_INFO(0, callback)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, toCallback)
{
php_http_pass_fcall_arg_t fcd;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f", &fcd.fci, &fcd.fcc)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "f", &fcd.fci, &fcd.fcc)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- fcd.fcz = getThis();
- Z_ADDREF_P(fcd.fcz);
- TSRMLS_SET_CTX(fcd.ts);
-
+ ZVAL_COPY(&fcd.fcz, getThis());
php_http_message_to_callback(obj->message, php_http_pass_fcall_callback, &fcd);
zend_fcall_info_args_clear(&fcd.fci, 1);
-
zval_ptr_dtor(&fcd.fcz);
- RETURN_TRUE;
+
+ RETURN_ZVAL(getThis(), 1, 0);
}
- RETURN_FALSE;
}
-PHP_METHOD(HttpMessage, serialize)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_serialize, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, serialize)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
char *string;
size_t length;
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
php_http_message_serialize(obj->message, &string, &length);
- RETURN_STRINGL(string, length, 0);
+ RETURN_STR(php_http_cs2zs(string, length));
}
RETURN_EMPTY_STRING();
}
-PHP_METHOD(HttpMessage, unserialize)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_unserialize, 0, 0, 1)
+ ZEND_ARG_INFO(0, serialized)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, unserialize)
{
- int length;
+ size_t length;
char *serialized;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &length)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &length)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
php_http_message_t *msg;
if (obj->message) {
+ /* do not free recursively */
php_http_message_dtor(obj->message);
efree(obj->message);
}
- if ((msg = php_http_message_parse(NULL, serialized, (size_t) length, 1 TSRMLS_CC))) {
+ if ((msg = php_http_message_parse(NULL, serialized, length, 1))) {
obj->message = msg;
} else {
- obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- php_http_error(HE_ERROR, PHP_HTTP_E_RUNTIME, "Could not unserialize HttpMessage");
+ obj->message = php_http_message_init(NULL, 0, NULL);
+ php_error_docref(NULL, E_ERROR, "Could not unserialize http\\Message");
}
}
}
-PHP_METHOD(HttpMessage, detach)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_detach, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, detach)
{
- with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj, *new_obj;
+ php_http_message_t *msg_cpy;
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- RETVAL_OBJVAL(php_http_message_object_new_ex(obj->zo.ce, php_http_message_copy_ex(obj->message, NULL, 0), NULL TSRMLS_CC), 0);
- }
- } end_error_handling();
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ msg_cpy = php_http_message_copy_ex(obj->message, NULL, 0);
+ new_obj = php_http_message_object_new_ex(obj->zo.ce, msg_cpy);
+
+ RETVAL_OBJ(&new_obj->zo);
}
-PHP_METHOD(HttpMessage, prepend)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_prepend, 0, 0, 1)
+ ZEND_ARG_OBJ_INFO(0, message, http\\Message, 0)
+ ZEND_ARG_INFO(0, top)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, prepend)
{
zval *prepend;
zend_bool top = 1;
+ php_http_message_t *msg[2];
+ php_http_message_object_t *obj, *prepend_obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &prepend, php_http_message_class_entry, &top)) {
- php_http_message_t *msg[2];
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- php_http_message_object_t *prepend_obj = zend_object_store_get_object(prepend TSRMLS_CC);
-
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
-
- if (!prepend_obj->message) {
- prepend_obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O|b", &prepend, php_http_message_class_entry, &top), invalid_arg, return);
- /* safety check */
- for (msg[0] = obj->message; msg[0]; msg[0] = msg[0]->parent) {
- for (msg[1] = prepend_obj->message; msg[1]; msg[1] = msg[1]->parent) {
- if (msg[0] == msg[1]) {
- php_http_error(HE_THROW, PHP_HTTP_E_INVALID_PARAM, "Cannot prepend a message located within the same message chain");
- return;
- }
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ prepend_obj = PHP_HTTP_OBJ(NULL, prepend);
+ PHP_HTTP_MESSAGE_OBJECT_INIT(prepend_obj);
+
+ /* safety check */
+ for (msg[0] = obj->message; msg[0]; msg[0] = msg[0]->parent) {
+ for (msg[1] = prepend_obj->message; msg[1]; msg[1] = msg[1]->parent) {
+ if (msg[0] == msg[1]) {
+ php_http_throw(unexpected_val, "Cannot prepend a message located within the same message chain", NULL);
+ return;
}
}
-
- php_http_message_object_prepend(getThis(), prepend, top TSRMLS_CC);
}
+
+ php_http_message_object_prepend(getThis(), prepend, top);
+ RETURN_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpMessage, reverse)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_reverse, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, reverse)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_reverse(getThis(), return_value TSRMLS_CC);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
+
+ php_http_message_object_reverse(getThis(), return_value);
}
-PHP_METHOD(HttpMessage, isMultipart)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_isMultipart, 0, 0, 0)
+ ZEND_ARG_INFO(1, boundary)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, isMultipart)
{
zval *zboundary = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &zboundary)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|z!", &zboundary)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
char *boundary = NULL;
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- RETVAL_BOOL(php_http_message_is_multipart(obj->message, zboundary ? &boundary : NULL));
+ if (php_http_message_is_multipart(obj->message, zboundary ? &boundary : NULL)) {
+ RETVAL_TRUE;
+ } else {
+ RETVAL_FALSE;
+ }
if (zboundary && boundary) {
+ ZVAL_DEREF(zboundary);
zval_dtor(zboundary);
- ZVAL_STRING(zboundary, boundary, 0);
+ ZVAL_STR(zboundary, php_http_cs2zs(boundary, strlen(boundary)));
}
}
}
-PHP_METHOD(HttpMessage, splitMultipartBody)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_splitMultipartBody, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, splitMultipartBody)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- char *boundary = NULL;
+ php_http_message_object_t *obj;
+ php_http_message_t *msg;
+ char *boundary = NULL;
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- if (php_http_message_is_multipart(obj->message, &boundary)) {
- php_http_message_t *msg;
+ obj = PHP_HTTP_OBJ(NULL, getThis());
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- 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);
- }
- }
- STR_FREE(boundary);
+ if (!php_http_message_is_multipart(obj->message, &boundary)) {
+ php_http_throw(bad_method_call, "http\\Message is not a multipart message", NULL);
+ return;
}
+
+ php_http_expect(msg = php_http_message_body_split(obj->message->body, boundary), bad_message, return);
+
+ PTR_FREE(boundary);
+
+ RETURN_OBJ(&php_http_message_object_new_ex(obj->zo.ce, msg)->zo);
}
-PHP_METHOD(HttpMessage, count)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_count, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, count)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- long i = 0;
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ zend_long count_mode = -1;
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &count_mode)) {
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- php_http_message_count(i, obj->message);
- RETURN_LONG(i);
+ RETURN_LONG(php_http_message_count(obj->message));
}
- RETURN_FALSE;
}
-PHP_METHOD(HttpMessage, rewind)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_rewind, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, rewind)
{
if (SUCCESS == zend_parse_parameters_none()) {
zval *zobj = getThis();
- php_http_message_object_t *obj = zend_object_store_get_object(zobj TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
- if (obj->iterator) {
+ if (!Z_ISUNDEF(obj->iterator)) {
zval_ptr_dtor(&obj->iterator);
}
- Z_ADDREF_P(zobj);
- obj->iterator = zobj;
+ ZVAL_COPY(&obj->iterator, zobj);
}
}
-PHP_METHOD(HttpMessage, valid)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_valid, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, valid)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
- RETURN_BOOL(obj->iterator != NULL);
+ RETURN_BOOL(!Z_ISUNDEF(obj->iterator));
}
}
-PHP_METHOD(HttpMessage, next)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_next, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, next)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
- if (obj->iterator) {
- php_http_message_object_t *itr = zend_object_store_get_object(obj->iterator TSRMLS_CC);
+ if (!Z_ISUNDEF(obj->iterator)) {
+ php_http_message_object_t *itr = PHP_HTTP_OBJ(NULL, &obj->iterator);
- if (itr && itr->parent.handle) {
- zval *old = obj->iterator;
- MAKE_STD_ZVAL(obj->iterator);
- ZVAL_OBJVAL(obj->iterator, itr->parent, 1);
- zval_ptr_dtor(&old);
+ if (itr->parent) {
+ zval tmp;
+
+ ZVAL_OBJECT(&tmp, &itr->parent->zo, 1);
+ zval_ptr_dtor(&obj->iterator);
+ obj->iterator = tmp;
} else {
zval_ptr_dtor(&obj->iterator);
- obj->iterator = NULL;
+ ZVAL_UNDEF(&obj->iterator);
}
}
}
}
-PHP_METHOD(HttpMessage, key)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_key, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, key)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
- RETURN_LONG(obj->iterator ? obj->iterator->value.obj.handle:0);
+ RETURN_LONG(Z_ISUNDEF(obj->iterator) ? 0 : Z_OBJ_HANDLE(obj->iterator));
}
}
-PHP_METHOD(HttpMessage, current)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_current, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpMessage, current)
{
if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
- if (obj->iterator) {
- RETURN_ZVAL(obj->iterator, 1, 0);
+ if (!Z_ISUNDEF(obj->iterator)) {
+ RETURN_ZVAL(&obj->iterator, 1, 0);
}
}
}
+static zend_function_entry php_http_message_methods[] = {
+ PHP_ME(HttpMessage, __construct, ai_HttpMessage___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
+ PHP_ME(HttpMessage, getBody, ai_HttpMessage_getBody, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, setBody, ai_HttpMessage_setBody, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, addBody, ai_HttpMessage_addBody, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, getHeader, ai_HttpMessage_getHeader, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, setHeader, ai_HttpMessage_setHeader, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, addHeader, ai_HttpMessage_addHeader, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, getHeaders, ai_HttpMessage_getHeaders, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, setHeaders, ai_HttpMessage_setHeaders, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, addHeaders, ai_HttpMessage_addHeaders, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, getType, ai_HttpMessage_getType, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, setType, ai_HttpMessage_setType, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, getInfo, ai_HttpMessage_getInfo, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, setInfo, ai_HttpMessage_setInfo, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, getResponseCode, ai_HttpMessage_getResponseCode, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, setResponseCode, ai_HttpMessage_setResponseCode, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, getResponseStatus, ai_HttpMessage_getResponseStatus, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, setResponseStatus, ai_HttpMessage_setResponseStatus, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, getRequestMethod, ai_HttpMessage_getRequestMethod, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, setRequestMethod, ai_HttpMessage_setRequestMethod, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, getRequestUrl, ai_HttpMessage_getRequestUrl, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, setRequestUrl, ai_HttpMessage_setRequestUrl, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, getHttpVersion, ai_HttpMessage_getHttpVersion, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, setHttpVersion, ai_HttpMessage_setHttpVersion, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, getParentMessage, ai_HttpMessage_getParentMessage, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, toString, ai_HttpMessage_toString, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, toCallback, ai_HttpMessage_toCallback, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, toStream, ai_HttpMessage_toStream, ZEND_ACC_PUBLIC)
+
+ /* implements Countable */
+ PHP_ME(HttpMessage, count, ai_HttpMessage_count, ZEND_ACC_PUBLIC)
+
+ /* implements Serializable */
+ PHP_ME(HttpMessage, serialize, ai_HttpMessage_serialize, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, unserialize, ai_HttpMessage_unserialize, ZEND_ACC_PUBLIC)
+
+ /* implements Iterator */
+ PHP_ME(HttpMessage, rewind, ai_HttpMessage_rewind, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, valid, ai_HttpMessage_valid, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, current, ai_HttpMessage_current, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, key, ai_HttpMessage_key, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, next, ai_HttpMessage_next, ZEND_ACC_PUBLIC)
+
+ ZEND_MALIAS(HttpMessage, __toString, toString, ai_HttpMessage___toString, ZEND_ACC_PUBLIC)
+
+ PHP_ME(HttpMessage, detach, ai_HttpMessage_detach, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, prepend, ai_HttpMessage_prepend, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, reverse, ai_HttpMessage_reverse, ZEND_ACC_PUBLIC)
+
+ PHP_ME(HttpMessage, isMultipart, ai_HttpMessage_isMultipart, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpMessage, splitMultipartBody, ai_HttpMessage_splitMultipartBody, ZEND_ACC_PUBLIC)
+
+ EMPTY_FUNCTION_ENTRY
+};
+
+zend_class_entry *php_http_message_class_entry;
+
+PHP_MINIT_FUNCTION(http_message)
+{
+ zend_class_entry ce = {0};
+
+ INIT_NS_CLASS_ENTRY(ce, "http", "Message", php_http_message_methods);
+ php_http_message_class_entry = zend_register_internal_class(&ce);
+ php_http_message_class_entry->create_object = php_http_message_object_new;
+ memcpy(&php_http_message_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ php_http_message_object_handlers.offset = XtOffsetOf(php_http_message_object_t, zo);
+ php_http_message_object_handlers.clone_obj = php_http_message_object_clone;
+ php_http_message_object_handlers.free_obj = php_http_message_object_free;
+ php_http_message_object_handlers.read_property = php_http_message_object_read_prop;
+ php_http_message_object_handlers.write_property = php_http_message_object_write_prop;
+ php_http_message_object_handlers.get_debug_info = php_http_message_object_get_debug_info;
+ php_http_message_object_handlers.get_property_ptr_ptr = NULL;
+
+ zend_class_implements(php_http_message_class_entry, 3, spl_ce_Countable, zend_ce_serializable, zend_ce_iterator);
+
+ zend_hash_init(&php_http_message_object_prophandlers, 9, NULL, php_http_message_object_prophandler_hash_dtor, 1);
+ zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("type"), PHP_HTTP_NONE, ZEND_ACC_PROTECTED);
+ php_http_message_object_add_prophandler(ZEND_STRL("type"), php_http_message_object_prophandler_get_type, php_http_message_object_prophandler_set_type);
+ zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("body"), ZEND_ACC_PROTECTED);
+ php_http_message_object_add_prophandler(ZEND_STRL("body"), php_http_message_object_prophandler_get_body, php_http_message_object_prophandler_set_body);
+ zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestMethod"), "", ZEND_ACC_PROTECTED);
+ php_http_message_object_add_prophandler(ZEND_STRL("requestMethod"), php_http_message_object_prophandler_get_request_method, php_http_message_object_prophandler_set_request_method);
+ zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestUrl"), "", ZEND_ACC_PROTECTED);
+ php_http_message_object_add_prophandler(ZEND_STRL("requestUrl"), php_http_message_object_prophandler_get_request_url, php_http_message_object_prophandler_set_request_url);
+ zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("responseStatus"), "", ZEND_ACC_PROTECTED);
+ php_http_message_object_add_prophandler(ZEND_STRL("responseStatus"), php_http_message_object_prophandler_get_response_status, php_http_message_object_prophandler_set_response_status);
+ zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("responseCode"), 0, ZEND_ACC_PROTECTED);
+ php_http_message_object_add_prophandler(ZEND_STRL("responseCode"), php_http_message_object_prophandler_get_response_code, php_http_message_object_prophandler_set_response_code);
+ zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("httpVersion"), ZEND_ACC_PROTECTED);
+ php_http_message_object_add_prophandler(ZEND_STRL("httpVersion"), php_http_message_object_prophandler_get_http_version, php_http_message_object_prophandler_set_http_version);
+ zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("headers"), ZEND_ACC_PROTECTED);
+ php_http_message_object_add_prophandler(ZEND_STRL("headers"), php_http_message_object_prophandler_get_headers, php_http_message_object_prophandler_set_headers);
+ zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("parentMessage"), ZEND_ACC_PROTECTED);
+ php_http_message_object_add_prophandler(ZEND_STRL("parentMessage"), php_http_message_object_prophandler_get_parent_message, php_http_message_object_prophandler_set_parent_message);
+
+ zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_NONE"), PHP_HTTP_NONE);
+ zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_REQUEST"), PHP_HTTP_REQUEST);
+ zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_RESPONSE"), PHP_HTTP_RESPONSE);
+
+ return SUCCESS;
+}
+
+PHP_MSHUTDOWN_FUNCTION(http_message)
+{
+ zend_hash_destroy(&php_http_message_object_prophandlers);
+
+ return SUCCESS;
+}
+
/*
* Local variables:
* tab-width: 4