- fix INI entries
[m6w6/ext-http] / http_response_object.c
index 5303d2d0ed76bd1c934b2428dad2ad8a5d3dc652..5bdbf14fc2c22509be1da373c374cfe0dda012aa 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "SAPI.h"
 #include "php_ini.h"
+#include "ext/standard/head.h"
 
 #include "php_http.h"
 #include "php_http_api.h"
@@ -47,6 +48,7 @@ ZEND_EXTERN_MODULE_GLOBALS(http);
 #define HTTP_BEGIN_ARGS(method, req_args)              HTTP_BEGIN_ARGS_EX(HttpResponse, method, 0, req_args)
 #define HTTP_EMPTY_ARGS(method, ret_ref)               HTTP_EMPTY_ARGS_EX(HttpResponse, method, ret_ref)
 #define HTTP_RESPONSE_ME(method, visibility)   PHP_ME(HttpResponse, method, HTTP_ARGS(HttpResponse, method), visibility|ZEND_ACC_STATIC)
+#define HTTP_RESPONSE_ALIAS(method, func)              HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpResponse, method))
 
 HTTP_EMPTY_ARGS(getETag, 0);
 HTTP_BEGIN_ARGS(setETag, 1)
@@ -111,6 +113,26 @@ HTTP_END_ARGS;
 
 HTTP_EMPTY_ARGS(capture, 0);
 
+HTTP_BEGIN_ARGS(redirect, 0)
+       HTTP_ARG_VAL(url, 0)
+       HTTP_ARG_VAL(params, 0)
+       HTTP_ARG_VAL(session, 0)
+       HTTP_ARG_VAL(permanent, 0)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(sendStatus, 1)
+       HTTP_ARG_VAL(status, 0)
+HTTP_END_ARGS;
+
+HTTP_BEGIN_ARGS(sendHeader, 1)
+       HTTP_ARG_VAL(header, 0)
+       HTTP_ARG_VAL(replace, 0)
+       HTTP_ARG_VAL(status, 0)
+HTTP_END_ARGS;
+
+HTTP_EMPTY_ARGS(getRequestHeaders, 0);
+HTTP_EMPTY_ARGS(getRequestBody, 0);
+
 #define http_response_object_declare_default_properties() _http_response_object_declare_default_properties(TSRMLS_C)
 static inline void _http_response_object_declare_default_properties(TSRMLS_D);
 
@@ -153,6 +175,14 @@ zend_function_entry http_response_object_fe[] = {
        HTTP_RESPONSE_ME(send, ZEND_ACC_PUBLIC)
        HTTP_RESPONSE_ME(capture, ZEND_ACC_PUBLIC)
 
+       HTTP_RESPONSE_ALIAS(redirect, http_redirect)
+
+       HTTP_RESPONSE_ALIAS(sendStatus, http_send_status)
+       HTTP_RESPONSE_ALIAS(sendHeader, header)
+
+       HTTP_RESPONSE_ALIAS(getRequestHeaders, http_get_request_headers)
+       HTTP_RESPONSE_ALIAS(getRequestBody, http_get_request_body)
+
        {NULL, NULL, NULL}
 };
 
@@ -181,8 +211,6 @@ static inline void _http_response_object_declare_default_properties(TSRMLS_D)
        DCL_STATIC_PROP_N(PROTECTED, contentDisposition);
        DCL_STATIC_PROP(PROTECTED, long, bufferSize, HTTP_SENDBUF_SIZE);
        DCL_STATIC_PROP(PROTECTED, double, throttleDelay, 0.0);
-
-       DCL_STATIC_PROP(PUBLIC, string, dummy, "EMPTY");
 }
 
 /* ### USERLAND ### */
@@ -273,7 +301,7 @@ PHP_METHOD(HttpResponse, setCacheControl)
        }
 
        if (strcmp(ccontrol, "public") && strcmp(ccontrol, "private") && strcmp(ccontrol, "no-cache")) {
-               http_error_ex(E_WARNING, HTTP_E_PARAM, "Cache-Control '%s' doesn't match public, private or no-cache", ccontrol);
+               http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Cache-Control '%s' doesn't match public, private or no-cache", ccontrol);
                RETURN_FALSE;
        } else {
                USE_STATIC_PROP();
@@ -313,7 +341,7 @@ PHP_METHOD(HttpResponse, setContentType)
        }
 
        if (!strchr(ctype, '/')) {
-               http_error_ex(E_WARNING, HTTP_E_PARAM, "Content type '%s' doesn't seem to contain a primary and a secondary part", ctype);
+               http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Content type '%s' doesn't seem to contain a primary and a secondary part", ctype);
                RETURN_FALSE;
        }
 
@@ -469,7 +497,7 @@ PHP_METHOD(HttpResponse, getBufferSize)
  */
 PHP_METHOD(HttpResponse, setData)
 {
-       zval *the_data, **data;
+       zval *the_data;
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &the_data)) {
                RETURN_FALSE;
@@ -601,20 +629,20 @@ PHP_METHOD(HttpResponse, getFile)
  */
 PHP_METHOD(HttpResponse, send)
 {
-       zval *do_cache, *do_gzip, *sent;
+       zval *sent;
        zend_bool clean_ob = 1;
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &clean_ob)) {
                RETURN_FALSE;
        }
        if (SG(headers_sent)) {
-               http_error(E_WARNING, HTTP_E_HEADER, "Cannot send HttpResponse, headers have already been sent");
+               http_error(HE_WARNING, HTTP_E_RESPONSE, "Cannot send HttpResponse, headers have already been sent");
                RETURN_FALSE;
        }
 
        sent = GET_STATIC_PROP(sent);
        if (Z_LVAL_P(sent)) {
-               http_error(E_WARNING, HTTP_E_UNKOWN, "Cannot send HttpResponse, response has already been sent");
+               http_error(HE_WARNING, HTTP_E_RESPONSE, "Cannot send HttpResponse, response has already been sent");
                RETURN_FALSE;
        } else {
                Z_LVAL_P(sent) = 1;
@@ -655,8 +683,6 @@ PHP_METHOD(HttpResponse, send)
 
        /* caching */
        if (Z_LVAL_P(GET_STATIC_PROP(cache))) {
-               char *cc_hdr;
-               int cc_len;
                zval *cctl, *etag, *lmod;
 
                etag = GET_STATIC_PROP(eTag);