| 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 set_option(zval *options, const char *name_str, size_t name_len, int type, void *value_ptr, size_t value_len TSRMLS_DC)
{
if (Z_TYPE_P(options) == IS_OBJECT) {
- /* stupid non-const api */
- char *name = estrndup(name_str, name_len);
if (value_ptr) {
switch (type) {
case IS_DOUBLE:
- zend_update_property_double(Z_OBJCE_P(options), options, name, name_len, *(double *)value_ptr TSRMLS_CC);
+ zend_update_property_double(Z_OBJCE_P(options), options, name_str, name_len, *(double *)value_ptr TSRMLS_CC);
break;
case IS_LONG:
- zend_update_property_long(Z_OBJCE_P(options), options, name, name_len, *(long *)value_ptr TSRMLS_CC);
+ zend_update_property_long(Z_OBJCE_P(options), options, name_str, name_len, *(long *)value_ptr TSRMLS_CC);
break;
case IS_STRING:
- zend_update_property_stringl(Z_OBJCE_P(options), options, name, name_len, value_ptr, value_len TSRMLS_CC);
+ zend_update_property_stringl(Z_OBJCE_P(options), options, name_str, name_len, value_ptr, value_len TSRMLS_CC);
break;
case IS_OBJECT:
- zend_update_property(Z_OBJCE_P(options), options, name, name_len, value_ptr TSRMLS_CC);
+ zend_update_property(Z_OBJCE_P(options), options, name_str, name_len, value_ptr TSRMLS_CC);
break;
}
} else {
- zend_update_property_null(Z_OBJCE_P(options), options, name, name_len TSRMLS_CC);
+ zend_update_property_null(Z_OBJCE_P(options), options, name_str, name_len TSRMLS_CC);
}
- efree(name);
} else {
convert_to_array(options);
if (value_ptr) {
zval *val, **valptr;
if (Z_TYPE_P(options) == IS_OBJECT) {
- char *name = estrndup(name_str, name_len);
- val = zend_read_property(Z_OBJCE_P(options), options, name, name_len, 0 TSRMLS_CC);
- efree(name);
+ val = zend_read_property(Z_OBJCE_P(options), options, name_str, name_len, 0 TSRMLS_CC);
} else {
if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(options), name_str, name_len + 1, (void *) &valptr)) {
val = *valptr;
php_http_message_body_t *body = NULL;
if ((zbody = get_option(options, ZEND_STRL("body") TSRMLS_CC))) {
- if ((Z_TYPE_P(zbody) == IS_OBJECT) && instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_get_class_entry() TSRMLS_CC)) {
+ if ((Z_TYPE_P(zbody) == IS_OBJECT) && instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry TSRMLS_CC)) {
php_http_message_body_object_t *body_obj = zend_object_store_get_object(zbody TSRMLS_CC);
body = body_obj->body;
php_http_message_t *request = NULL;
if ((zrequest = get_option(options, ZEND_STRL("request") TSRMLS_CC))) {
- if (Z_TYPE_P(zrequest) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zrequest), php_http_message_get_class_entry() TSRMLS_CC)) {
+ if (Z_TYPE_P(zrequest) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zrequest), php_http_message_class_entry TSRMLS_CC)) {
php_http_message_object_t *request_obj = zend_object_store_get_object(zrequest TSRMLS_CC);
request = request_obj->message;
return request;
}
-PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC)
+php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC)
{
php_http_cache_status_t ret = PHP_HTTP_CACHE_NO;
int free_etag = 0;
return ret;
}
-PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC)
+php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC)
{
php_http_cache_status_t ret = PHP_HTTP_CACHE_NO;
char *header;
return 0;
}
- if (php_http_env_got_request_header(ZEND_STRL("Authorizsation"), request TSRMLS_CC)) {
+ if (php_http_env_got_request_header(ZEND_STRL("Authorization"), request TSRMLS_CC)) {
return 0;
}
{
php_http_env_response_t *r = context;
- r->ops->write(r, buf, len);
+ if (SUCCESS != r->ops->write(r, buf, len)) {
+ return (size_t) -1;
+ }
/* we really only need to flush when throttling is enabled,
because we push the data as fast as possible anyway if not */
#define php_http_env_response_send_done(r) php_http_env_response_send_data((r), NULL, 0)
static STATUS php_http_env_response_send_data(php_http_env_response_t *r, const char *buf, size_t len)
{
- size_t chunk = r->throttle.chunk ? r->throttle.chunk : PHP_HTTP_SENDBUF_SIZE;
+ size_t chunks_sent, chunk = r->throttle.chunk ? r->throttle.chunk : PHP_HTTP_SENDBUF_SIZE;
TSRMLS_FETCH_FROM_CTX(r->ts);
if (r->content.encoder) {
}
}
- if (enc_str) {
- php_http_buffer_chunked_output(&r->buffer, enc_str, enc_len, buf ? chunk : 0, output, r TSRMLS_CC);
- STR_FREE(enc_str);
+ if (!enc_str) {
+ return SUCCESS;
}
+ chunks_sent = php_http_buffer_chunked_output(&r->buffer, enc_str, enc_len, buf ? chunk : 0, output, r TSRMLS_CC);
+ STR_FREE(enc_str);
} else {
- php_http_buffer_chunked_output(&r->buffer, buf, len, buf ? chunk : 0, output, r TSRMLS_CC);
+ chunks_sent = php_http_buffer_chunked_output(&r->buffer, buf, len, buf ? chunk : 0, output, r TSRMLS_CC);
}
- return SUCCESS;
+ return chunks_sent != (size_t) -1 ? SUCCESS : FAILURE;
}
-PHP_HTTP_API php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *init_arg TSRMLS_DC)
+php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *init_arg TSRMLS_DC)
{
zend_bool free_r;
return r;
}
-PHP_HTTP_API void php_http_env_response_dtor(php_http_env_response_t *r)
+void php_http_env_response_dtor(php_http_env_response_t *r)
{
if (r->ops->dtor) {
r->ops->dtor(r);
}
}
-PHP_HTTP_API void php_http_env_response_free(php_http_env_response_t **r)
+void php_http_env_response_free(php_http_env_response_t **r)
{
if (*r) {
php_http_env_response_dtor(*r);
return ret;
}
+ if ((zoption = get_option(options, ZEND_STRL("headers") TSRMLS_CC))) {
+ if (Z_TYPE_P(zoption) == IS_ARRAY) {
+ php_http_header_to_callback(Z_ARRVAL_P(zoption), 0, (php_http_pass_format_callback_t) r->ops->set_header, r TSRMLS_CC);
+ }
+ zval_ptr_dtor(&zoption);
+ }
+
+ if (ret != SUCCESS) {
+ return ret;
+ }
+
if ((zoption = get_option(options, ZEND_STRL("responseCode") TSRMLS_CC))) {
zval *zoption_copy = php_http_ztyp(IS_LONG, zoption);
return ret;
}
- if ((zoption = get_option(options, ZEND_STRL("headers") TSRMLS_CC))) {
- if (Z_TYPE_P(zoption) == IS_ARRAY) {
- php_http_headers_to_callback(Z_ARRVAL_P(zoption), 0, (php_http_pass_format_callback_t) r->ops->set_header, r TSRMLS_CC);
- }
- zval_ptr_dtor(&zoption);
- }
-
- if (ret != SUCCESS) {
- return ret;
- }
-
if ((zoption = get_option(options, ZEND_STRL("contentType") TSRMLS_CC))) {
zval *zoption_copy = php_http_ztyp(IS_STRING, zoption);
zval_ptr_dtor(&zoption);
- if (Z_STRLEN_P(zoption_copy)) {
- PHP_HTTP_CHECK_CONTENT_TYPE(Z_STRVAL_P(zoption_copy), ret = FAILURE) else {
- if (SUCCESS == (ret = r->ops->set_header(r, "Content-Type: %.*s", Z_STRLEN_P(zoption_copy), Z_STRVAL_P(zoption_copy)))) {
- r->content.type = estrndup(Z_STRVAL_P(zoption_copy), Z_STRLEN_P(zoption_copy));
- }
+ if (Z_STRLEN_P(zoption_copy) && strchr(Z_STRVAL_P(zoption_copy), '/')) {
+ if (SUCCESS == (ret = r->ops->set_header(r, "Content-Type: %.*s", Z_STRLEN_P(zoption_copy), Z_STRVAL_P(zoption_copy)))) {
+ r->content.type = estrndup(Z_STRVAL_P(zoption_copy), Z_STRLEN_P(zoption_copy));
}
}
zval_ptr_dtor(&zoption_copy);
&& 2 == php_http_array_list(Z_ARRVAL_PP(range) TSRMLS_CC, 2, &begin, &end)
) {
/* send chunk */
- php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1);
- php_http_env_response_send_done(r);
+ ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1);
+ if (ret == SUCCESS) {
+ ret = php_http_env_response_send_done(r);
+ }
zend_hash_destroy(&r->range.values);
- ret = SUCCESS;
} else {
/* this should never happen */
zend_hash_destroy(&r->range.values);
Z_LVAL_PP(end),
r->content.length
);
- php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1);
+ ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1);
}
}
- php_http_buffer_appendf(r->buffer, PHP_HTTP_CRLF "--%s--", r->range.boundary);
- php_http_env_response_send_done(r);
+
+ if (ret == SUCCESS) {
+ php_http_buffer_appendf(r->buffer, PHP_HTTP_CRLF "--%s--", r->range.boundary);
+ ret = php_http_env_response_send_done(r);
+ }
zend_hash_destroy(&r->range.values);
}
} else {
- php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, 0, 0);
- php_http_env_response_send_done(r);
+ ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, 0, 0);
+ if (ret == SUCCESS) {
+ ret = php_http_env_response_send_done(r);
+ }
}
}
return ret;
}
-PHP_HTTP_API STATUS php_http_env_response_send(php_http_env_response_t *r)
+STATUS php_http_env_response_send(php_http_env_response_t *r)
{
php_http_message_t *request;
php_http_message_body_t *body;
}
if (SUCCESS != php_http_env_response_send_head(r, request)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to send response headers");
return FAILURE;
}
if (SUCCESS != php_http_env_response_send_body(r)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to send response body");
return FAILURE;
}
if (SUCCESS != r->ops->finish(r)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to finish response");
return FAILURE;
}
php_http_env_response_sapi_finish
};
-PHP_HTTP_API php_http_env_response_ops_t *php_http_env_response_get_sapi_ops(void)
+php_http_env_response_ops_t *php_http_env_response_get_sapi_ops(void)
{
return &php_http_env_response_sapi_ops;
}
}
}
- php_stream_write(stream_ctx->stream, data_str, data_len);
+ if (data_len != php_stream_write(stream_ctx->stream, data_str, data_len)) {
+ return FAILURE;
+ }
return SUCCESS;
}
php_http_env_response_stream_finish
};
-PHP_HTTP_API php_http_env_response_ops_t *php_http_env_response_get_stream_ops(void)
+php_http_env_response_ops_t *php_http_env_response_get_stream_ops(void)
{
return &php_http_env_response_stream_ops;
}
-#undef PHP_HTTP_BEGIN_ARGS
-#undef PHP_HTTP_EMPTY_ARGS
-#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpEnvResponse, method, 0, req_args)
-#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpEnvResponse, method, 0)
-#define PHP_HTTP_ENV_RESPONSE_ME(method, visibility) PHP_ME(HttpEnvResponse, method, PHP_HTTP_ARGS(HttpEnvResponse, method), visibility)
-
-PHP_HTTP_EMPTY_ARGS(__construct);
-
-PHP_HTTP_BEGIN_ARGS(__invoke, 1)
- PHP_HTTP_ARG_VAL(ob_string, 0)
- PHP_HTTP_ARG_VAL(ob_flags, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(setEnvRequest, 1)
- PHP_HTTP_ARG_OBJ(http\\Message, env_request, 1)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(setContentType, 1)
- PHP_HTTP_ARG_VAL(content_type, 0)
-PHP_HTTP_END_ARGS;
+#define PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj) \
+ do { \
+ if (!obj->message) { \
+ obj->message = php_http_message_init_env(NULL, PHP_HTTP_RESPONSE TSRMLS_CC); \
+ } \
+ } while (0)
-PHP_HTTP_BEGIN_ARGS(setContentEncoding, 1)
- PHP_HTTP_ARG_VAL(content_encoding, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(setContentDisposition, 1)
- PHP_HTTP_ARG_ARR(disposition_params, 1, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(setCacheControl, 1)
- PHP_HTTP_ARG_VAL(cache_control, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(setLastModified, 1)
- PHP_HTTP_ARG_VAL(last_modified, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(isCachedByLastModified, 0)
- PHP_HTTP_ARG_VAL(header_name, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(setEtag, 1)
- PHP_HTTP_ARG_VAL(etag, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(isCachedByEtag, 0)
- PHP_HTTP_ARG_VAL(header_name, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_BEGIN_ARGS(setThrottleRate, 1)
- PHP_HTTP_ARG_VAL(chunk_size, 0)
- PHP_HTTP_ARG_VAL(delay, 0)
-PHP_HTTP_END_ARGS;
-
-PHP_HTTP_EMPTY_ARGS(send);
-
-static zend_class_entry *php_http_env_response_class_entry;
-
-zend_class_entry *php_http_env_response_get_class_entry(void)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse___construct, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, __construct)
{
- return php_http_env_response_class_entry;
-}
+ php_http_message_object_t *obj;
-static zend_function_entry php_http_env_response_method_entry[] = {
- PHP_HTTP_ENV_RESPONSE_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
- PHP_HTTP_ENV_RESPONSE_ME(__invoke, ZEND_ACC_PUBLIC)
- PHP_HTTP_ENV_RESPONSE_ME(setEnvRequest, ZEND_ACC_PUBLIC)
- PHP_HTTP_ENV_RESPONSE_ME(setContentType, ZEND_ACC_PUBLIC)
- PHP_HTTP_ENV_RESPONSE_ME(setContentDisposition, ZEND_ACC_PUBLIC)
- PHP_HTTP_ENV_RESPONSE_ME(setContentEncoding, ZEND_ACC_PUBLIC)
- PHP_HTTP_ENV_RESPONSE_ME(setCacheControl, ZEND_ACC_PUBLIC)
- PHP_HTTP_ENV_RESPONSE_ME(setLastModified, ZEND_ACC_PUBLIC)
- PHP_HTTP_ENV_RESPONSE_ME(isCachedByLastModified, ZEND_ACC_PUBLIC)
- PHP_HTTP_ENV_RESPONSE_ME(setEtag, ZEND_ACC_PUBLIC)
- PHP_HTTP_ENV_RESPONSE_ME(isCachedByEtag, ZEND_ACC_PUBLIC)
- PHP_HTTP_ENV_RESPONSE_ME(setThrottleRate, ZEND_ACC_PUBLIC)
-
- PHP_HTTP_ENV_RESPONSE_ME(send, ZEND_ACC_PUBLIC)
-
- EMPTY_FUNCTION_ENTRY
-};
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-PHP_METHOD(HttpEnvResponse, __construct)
-{
- 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);
-
- with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
- obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE TSRMLS_CC);
- } end_error_handling();
- }
- } end_error_handling();
-
+ php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE TSRMLS_CC), unexpected_val, return);
}
-PHP_METHOD(HttpEnvResponse, __invoke)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse___invoke, 0, 0, 1)
+ ZEND_ARG_INFO(0, ob_string)
+ ZEND_ARG_INFO(0, ob_flags)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, __invoke)
{
char *ob_str;
int ob_len;
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &ob_str, &ob_len, &ob_flags)) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (obj->body.handle || SUCCESS == 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)) {
- php_http_message_body_append(obj->message->body, ob_str, ob_len);
- RETURN_TRUE;
- }
- RETURN_FALSE;
+ PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj);
+
+ php_http_message_object_init_body_object(obj);
+ php_http_message_body_append(obj->message->body, ob_str, ob_len);
+#if PHP_VERSION_ID >= 50400
+ RETURN_TRUE;
+#else
+ RETURN_EMPTY_STRING();
+#endif
}
}
-PHP_METHOD(HttpEnvResponse, setEnvRequest)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setEnvRequest, 0, 0, 1)
+ ZEND_ARG_OBJ_INFO(0, env_request, http\\Message, 1)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, setEnvRequest)
{
zval *env_req = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &env_req, php_http_message_get_class_entry())) {
- set_option(getThis(), ZEND_STRL("request"), IS_OBJECT, env_req, 0 TSRMLS_CC);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &env_req, php_http_message_class_entry), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("request"), IS_OBJECT, env_req, 0 TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpEnvResponse, setContentType)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentType, 0, 0, 1)
+ ZEND_ARG_INFO(0, content_type)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, setContentType)
{
char *ct_str = NULL;
int ct_len = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &ct_str, &ct_len)) {
- set_option(getThis(), ZEND_STRL("contentType"), IS_STRING, ct_str, ct_len TSRMLS_CC);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &ct_str, &ct_len), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("contentType"), IS_STRING, ct_str, ct_len TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpEnvResponse, setContentDisposition)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentDisposition, 0, 0, 1)
+ ZEND_ARG_ARRAY_INFO(0, disposition_params, 1)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, setContentDisposition)
{
zval *zdisposition;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zdisposition)) {
- zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), zdisposition TSRMLS_CC);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zdisposition), invalid_arg, return);
+
+ zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), zdisposition TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpEnvResponse, setContentEncoding)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentEncoding, 0, 0, 1)
+ ZEND_ARG_INFO(0, content_encoding)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, setContentEncoding)
{
long ce;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ce)) {
- set_option(getThis(), ZEND_STRL("contentEncoding"), IS_LONG, &ce, 0 TSRMLS_CC);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ce), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("contentEncoding"), IS_LONG, &ce, 0 TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpEnvResponse, setCacheControl)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setCacheControl, 0, 0, 1)
+ ZEND_ARG_INFO(0, cache_control)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, setCacheControl)
{
char *cc_str = NULL;
int cc_len = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &cc_str, &cc_len)) {
- set_option(getThis(), ZEND_STRL("cacheControl"), IS_STRING, cc_str, cc_len TSRMLS_CC);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &cc_str, &cc_len), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("cacheControl"), IS_STRING, cc_str, cc_len TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpEnvResponse, setLastModified)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setLastModified, 0, 0, 1)
+ ZEND_ARG_INFO(0, last_modified)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, setLastModified)
{
long last_modified;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &last_modified)) {
- set_option(getThis(), ZEND_STRL("lastModified"), IS_LONG, &last_modified, 0 TSRMLS_CC);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &last_modified), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("lastModified"), IS_LONG, &last_modified, 0 TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpEnvResponse, isCachedByLastModified)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_isCachedByLastModified, 0, 0, 0)
+ ZEND_ARG_INFO(0, header_name)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, isCachedByLastModified)
{
char *header_name_str = NULL;
int header_name_len = 0;
RETURN_LONG(php_http_env_is_response_cached_by_last_modified(getThis(), header_name_str, header_name_len, get_request(getThis() TSRMLS_CC) TSRMLS_CC));
}
- RETURN_FALSE;
}
-PHP_METHOD(HttpEnvResponse, setEtag)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setEtag, 0, 0, 1)
+ ZEND_ARG_INFO(0, etag)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, setEtag)
{
char *etag_str = NULL;
int etag_len = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &etag_str, &etag_len)) {
- set_option(getThis(), ZEND_STRL("etag"), IS_STRING, etag_str, etag_len TSRMLS_CC);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &etag_str, &etag_len), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("etag"), IS_STRING, etag_str, etag_len TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpEnvResponse, isCachedByEtag)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_isCachedByEtag, 0, 0, 0)
+ ZEND_ARG_INFO(0, header_name)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, isCachedByEtag)
{
char *header_name_str = NULL;
int header_name_len = 0;
}
RETURN_LONG(php_http_env_is_response_cached_by_etag(getThis(), header_name_str, header_name_len, get_request(getThis() TSRMLS_CC) TSRMLS_CC));
}
- RETURN_FALSE;
}
-PHP_METHOD(HttpEnvResponse, setThrottleRate)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setThrottleRate, 0, 0, 1)
+ ZEND_ARG_INFO(0, chunk_size)
+ ZEND_ARG_INFO(0, delay)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, setThrottleRate)
{
long chunk_size;
double delay = 1;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|d", &chunk_size, &delay)) {
- set_option(getThis(), ZEND_STRL("throttleDelay"), IS_DOUBLE, &delay, 0 TSRMLS_CC);
- set_option(getThis(), ZEND_STRL("throttleChunk"), IS_LONG, &chunk_size, 0 TSRMLS_CC);
- RETURN_TRUE;
- }
- RETURN_FALSE;
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|d", &chunk_size, &delay), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("throttleDelay"), IS_DOUBLE, &delay, 0 TSRMLS_CC);
+ set_option(getThis(), ZEND_STRL("throttleChunk"), IS_LONG, &chunk_size, 0 TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
-PHP_METHOD(HttpEnvResponse, send)
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_send, 0, 0, 0)
+ ZEND_ARG_INFO(0, stream)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, send)
{
zval *zstream = NULL;
php_stream *s = NULL;
- RETVAL_FALSE;
-
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &zstream)) {
+ /* first flush the output layer to avoid conflicting headers and output;
+ * also, ob_start($thisEnvResponse) might have been called */
+#if PHP_VERSION_ID >= 50400
+ php_output_end_all(TSRMLS_C);
+#else
+ php_end_ob_buffers(1 TSRMLS_CC);
+#endif
if (zstream) {
- php_stream_from_zval_no_verify(s, &zstream);
-
- if (s) {
- php_http_env_response_t *r;
+ php_http_env_response_t *r;
- if ((r = php_http_env_response_init(NULL, getThis(), php_http_env_response_get_stream_ops(), s TSRMLS_CC))) {
- RETVAL_SUCCESS(php_http_env_response_send(r));
- php_http_env_response_free(&r);
- }
+ php_stream_from_zval(s, &zstream);
+ r = php_http_env_response_init(NULL, getThis(), php_http_env_response_get_stream_ops(), s TSRMLS_CC);
+ if (!r) {
+ RETURN_FALSE;
}
+
+ RETVAL_BOOL(SUCCESS == php_http_env_response_send(r));
+ php_http_env_response_free(&r);
} else {
php_http_env_response_t r;
- if (php_http_env_response_init(&r, getThis(), NULL, NULL TSRMLS_CC)) {
- RETVAL_SUCCESS(php_http_env_response_send(&r));
- php_http_env_response_dtor(&r);
+ if (!php_http_env_response_init(&r, getThis(), NULL, NULL TSRMLS_CC)) {
+ RETURN_FALSE;
}
+
+ RETVAL_BOOL(SUCCESS == php_http_env_response_send(&r));
+ php_http_env_response_dtor(&r);
}
}
}
+static zend_function_entry php_http_env_response_methods[] = {
+ PHP_ME(HttpEnvResponse, __construct, ai_HttpEnvResponse___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
+ PHP_ME(HttpEnvResponse, __invoke, ai_HttpEnvResponse___invoke, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpEnvResponse, setEnvRequest, ai_HttpEnvResponse_setEnvRequest, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpEnvResponse, setContentType, ai_HttpEnvResponse_setContentType, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpEnvResponse, setContentDisposition, ai_HttpEnvResponse_setContentDisposition, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpEnvResponse, setContentEncoding, ai_HttpEnvResponse_setContentEncoding, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpEnvResponse, setCacheControl, ai_HttpEnvResponse_setCacheControl, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpEnvResponse, setLastModified, ai_HttpEnvResponse_setLastModified, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpEnvResponse, isCachedByLastModified, ai_HttpEnvResponse_isCachedByLastModified, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpEnvResponse, setEtag, ai_HttpEnvResponse_setEtag, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpEnvResponse, isCachedByEtag, ai_HttpEnvResponse_isCachedByEtag, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpEnvResponse, setThrottleRate, ai_HttpEnvResponse_setThrottleRate, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpEnvResponse, send, ai_HttpEnvResponse_send, ZEND_ACC_PUBLIC)
+ EMPTY_FUNCTION_ENTRY
+};
+
+zend_class_entry *php_http_env_response_class_entry;
+
PHP_MINIT_FUNCTION(http_env_response)
{
- PHP_HTTP_REGISTER_CLASS(http\\Env, Response, http_env_response, php_http_message_get_class_entry(), 0);
+ zend_class_entry ce = {0};
+
+ INIT_NS_CLASS_ENTRY(ce, "http\\Env", "Response", php_http_env_response_methods);
+ php_http_env_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry, NULL TSRMLS_CC);
zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_NONE"), PHP_HTTP_CONTENT_ENCODING_NONE TSRMLS_CC);
zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_GZIP"), PHP_HTTP_CONTENT_ENCODING_GZIP TSRMLS_CC);