remove superfluous buffer macros
[m6w6/ext-http] / php_http_env_response.c
index c3cf80b891a4bd7a6fd37144e7f04863ad0192b1..b64aefd1e74d05ee6709d7f1b923e409b4eed8d5 100644 (file)
@@ -166,7 +166,7 @@ PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_last_mod
        ums = php_parse_date(header, NULL);
        efree(header);
 
-       if (ums > 0 && ums <= lm) {
+       if (ums > 0 && ums >= lm) {
                return PHP_HTTP_CACHE_HIT;
        } else {
                return PHP_HTTP_CACHE_MISS;
@@ -189,6 +189,9 @@ static size_t output(void *context, char *buf, size_t len TSRMLS_DC)
                if (!(php_output_get_status(TSRMLS_C) & PHP_OUTPUT_IMPLICITFLUSH)) {
                        sapi_flush(TSRMLS_C);
                }
+#else
+               php_end_ob_buffer(1, 1 TSRMLS_CC);
+               sapi_flush(TSRMLS_C);
 #endif
                php_http_sleep(r->throttle.delay);
        }
@@ -348,16 +351,15 @@ static STATUS php_http_env_response_send_head(php_http_env_response_t *r)
                if (zend_hash_num_elements(&r->range.values) == 1) {
                        zval **range, **begin, **end;
 
-                       if (SUCCESS != zend_hash_index_find(&r->range.values, 0, (void *) &range)
-                       ||      SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(range), 0, (void *) &begin)
-                       ||      SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(range), 1, (void *) &end)
+                       if (    1 == php_http_array_list(&r->range.values TSRMLS_CC, 1, &range)
+                               &&      2 == php_http_array_list(Z_ARRVAL_PP(range) TSRMLS_CC, 2, &begin, &end)
                        ) {
+                               ret = php_http_env_set_response_header_format(206, 1 TSRMLS_CC, "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_PP(begin), Z_LVAL_PP(end), r->content.length);
+                       } else {
                                /* this should never happen */
                                zend_hash_destroy(&r->range.values);
                                php_http_env_set_response_code(500 TSRMLS_CC);
                                ret = FAILURE;
-                       } else {
-                               ret = php_http_env_set_response_header_format(206, 1 TSRMLS_CC, "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_PP(begin), Z_LVAL_PP(end), r->content.length);
                        }
                } else {
                        php_http_boundary(r->range.boundary, sizeof(r->range.boundary) TSRMLS_CC);
@@ -384,11 +386,12 @@ static STATUS php_http_env_response_send_head(php_http_env_response_t *r)
 
                        php_http_buffer_init(&buf);
                        if (php_http_params_to_string(&buf, Z_ARRVAL_P(zoption_copy), ZEND_STRL(","), ZEND_STRL(";"), ZEND_STRL("="), PHP_HTTP_PARAMS_DEFAULT TSRMLS_CC)) {
-                               ret = php_http_env_set_response_header_format(0, 1 TSRMLS_CC, "Content-Disposition: %s", PHP_HTTP_BUFFER_VAL(&buf));
+                               ret = php_http_env_set_response_header_format(0, 1 TSRMLS_CC, "Content-Disposition: %s", buf.data);
                        }
 
                        php_http_buffer_dtor(&buf);
                        zval_ptr_dtor(&zoption_copy);
+                       zval_ptr_dtor(&zoption);
                }
 
                if (ret != SUCCESS) {
@@ -510,7 +513,7 @@ static STATUS php_http_env_response_send_head(php_http_env_response_t *r)
 static STATUS php_http_env_response_send_body(php_http_env_response_t *r)
 {
        STATUS ret = SUCCESS;
-       zval *zbody;
+       zval *zbody, *zoption;
        TSRMLS_FETCH_FROM_CTX(r->ts);
 
        if (r->done) {
@@ -523,26 +526,40 @@ static STATUS php_http_env_response_send_body(php_http_env_response_t *r)
        ) {
                php_http_message_body_object_t *obj = zend_object_store_get_object(zbody TSRMLS_CC);
 
+               if ((zoption = get_option(r->options, ZEND_STRL("throttleDelay") TSRMLS_CC))) {
+                       if (Z_TYPE_P(zoption) == IS_DOUBLE) {
+                               r->throttle.delay =  Z_DVAL_P(zoption);
+                       }
+                       zval_ptr_dtor(&zoption);
+               }
+               if ((zoption = get_option(r->options, ZEND_STRL("throttleChunk") TSRMLS_CC))) {
+                       if (Z_TYPE_P(zoption) == IS_LONG) {
+                               r->throttle.chunk = Z_LVAL_P(zoption);
+                       }
+                       zval_ptr_dtor(&zoption);
+               }
+
                if (r->range.status == PHP_HTTP_RANGE_OK) {
                        if (zend_hash_num_elements(&r->range.values) == 1) {
                                /* single range */
                                zval **range, **begin, **end;
 
-                               if (SUCCESS != zend_hash_index_find(&r->range.values, 0, (void *) &range)
-                               ||      SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(range), 0, (void *) &begin)
-                               ||      SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(range), 1, (void *) &end)
+                               if (    1 == php_http_array_list(&r->range.values TSRMLS_CC, 1, &range)
+                                       &&      2 == php_http_array_list(Z_ARRVAL_PP(range) TSRMLS_CC, 2, &begin, &end)
                                ) {
-                                       /* this should never happen */
-                                       zend_hash_destroy(&r->range.values);
-                                       php_http_env_set_response_code(500 TSRMLS_CC);
-                                       ret = FAILURE;
-                               } else {
                                        /* send chunk */
                                        php_http_message_body_to_callback(obj->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);
                                        zend_hash_destroy(&r->range.values);
                                        ret = SUCCESS;
+                               } else {
+                                       fprintf(stderr, "wut?");
+                                       /* this should never happen */
+                                       zend_hash_destroy(&r->range.values);
+                                       php_http_env_set_response_code(500 TSRMLS_CC);
+                                       ret = FAILURE;
                                }
+
                        } else {
                                /* send multipart/byte-ranges message */
                                HashPosition pos;
@@ -551,12 +568,7 @@ static STATUS php_http_env_response_send_body(php_http_env_response_t *r)
                                FOREACH_HASH_VAL(pos, &r->range.values, chunk) {
                                        zval **begin, **end;
 
-                                       if (IS_ARRAY == Z_TYPE_PP(chunk)
-                                       &&      SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(chunk), 0, (void *) &begin)
-                                       &&      IS_LONG == Z_TYPE_PP(begin)
-                                       &&      SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(chunk), 1, (void *) &end)
-                                       &&      IS_LONG == Z_TYPE_PP(end)
-                                       ) {
+                                       if (2 == php_http_array_list(Z_ARRVAL_PP(chunk) TSRMLS_CC, 2, &begin, &end)) {
                                                php_http_buffer_appendf(r->buffer,
                                                                PHP_HTTP_CRLF
                                                                "--%s" PHP_HTTP_CRLF
@@ -866,10 +878,8 @@ PHP_METHOD(HttpEnvResponse, setThrottleRate)
        double delay = 1;
 
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|d", &chunk_size, &delay)) {
-               long chunk_size_long = (long) chunk_size;
-
                set_option(getThis(), ZEND_STRL("throttleDelay"), IS_DOUBLE, &delay, 0 TSRMLS_CC);
-               set_option(getThis(), ZEND_STRL("throttleChunk"), IS_LONG, &chunk_size_long, 0 TSRMLS_CC);
+               set_option(getThis(), ZEND_STRL("throttleChunk"), IS_LONG, &chunk_size, 0 TSRMLS_CC);
                RETURN_TRUE;
        }
        RETURN_FALSE;