* melt http_api down
authorMichael Wallner <mike@php.net>
Fri, 25 Feb 2005 21:18:39 +0000 (21:18 +0000)
committerMichael Wallner <mike@php.net>
Fri, 25 Feb 2005 21:18:39 +0000 (21:18 +0000)
http_api.c
http_curl_api.c
http_functions.c
http_methods.c
php_http_api.h
php_http_curl_api.h
php_http_std_defs.h

index 88bb1b2b51404f3fb507c21f700fdcaf4598d894..e1d6e1b43bd9be29c9dbb6a63dd7e34096e664c5 100644 (file)
@@ -298,16 +298,19 @@ static STATUS http_ob_stack_get(php_ob_buffer *o, php_ob_buffer **s)
 PHP_HTTP_API char *_http_date(time_t t TSRMLS_DC)
 {
        struct tm *gmtime, tmbuf;
 PHP_HTTP_API char *_http_date(time_t t TSRMLS_DC)
 {
        struct tm *gmtime, tmbuf;
-       char *date = ecalloc(1, 31);
-
-       gmtime = php_gmtime_r(&t, &tmbuf);
-       snprintf(date, 30,
-               "%s, %02d %s %04d %02d:%02d:%02d GMT",
-               days[gmtime->tm_wday], gmtime->tm_mday,
-               months[gmtime->tm_mon], gmtime->tm_year + 1900,
-               gmtime->tm_hour, gmtime->tm_min, gmtime->tm_sec
-       );
-       return date;
+
+       if (gmtime = php_gmtime_r(&t, &tmbuf)) {
+               char *date = ecalloc(1, 31);
+               snprintf(date, 30,
+                       "%s, %02d %s %04d %02d:%02d:%02d GMT",
+                       days[gmtime->tm_wday], gmtime->tm_mday,
+                       months[gmtime->tm_mon], gmtime->tm_year + 1900,
+                       gmtime->tm_hour, gmtime->tm_min, gmtime->tm_sec
+               );
+               return date;
+       }
+
+       return NULL;
 }
 /* }}} */
 
 }
 /* }}} */
 
@@ -369,7 +372,8 @@ PHP_HTTP_API time_t _http_parse_date(const char *date)
                        /* a digit */
                        int val;
                        char *end;
                        /* a digit */
                        int val;
                        char *end;
-                       if((seconds == -1) && (3 == sscanf(date, "%02d:%02d:%02d", &hours, &minutes, &seconds))) {
+                       if ((seconds == -1) &&
+                               (3 == sscanf(date, "%02d:%02d:%02d", &hours, &minutes, &seconds))) {
                                /* time stamp! */
                                date += 8;
                                found = 1;
                                /* time stamp! */
                                date += 8;
                                found = 1;
@@ -377,7 +381,8 @@ PHP_HTTP_API time_t _http_parse_date(const char *date)
                        else {
                                val = (int) strtol(date, &end, 10);
 
                        else {
                                val = (int) strtol(date, &end, 10);
 
-                               if ((tz_offset == -1) && ((end - date) == 4) && (val < 1300) && (indate < date) && ((date[-1] == '+' || date[-1] == '-'))) {
+                               if ((tz_offset == -1) && ((end - date) == 4) && (val < 1300) &&
+                                       (indate < date) && ((date[-1] == '+' || date[-1] == '-'))) {
                                        /* four digits and a value less than 1300 and it is preceeded with
                                        a plus or minus. This is a time zone indication. */
                                        found = 1;
                                        /* four digits and a value less than 1300 and it is preceeded with
                                        a plus or minus. This is a time zone indication. */
                                        found = 1;
@@ -558,29 +563,6 @@ PHP_HTTP_API time_t _http_lmod(const void *data_ptr, const http_send_mode data_m
 }
 /* }}} */
 
 }
 /* }}} */
 
-/* {{{ int http_is_range_request(void) */
-PHP_HTTP_API int _http_is_range_request(TSRMLS_D)
-{
-       return zend_hash_exists(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]),
-               "HTTP_RANGE", sizeof("HTTP_RANGE"));
-}
-/* }}} */
-
-/* {{{ STATUS http_send_status(int) */
-PHP_HTTP_API STATUS _http_send_status(const int status TSRMLS_DC)
-{
-       int s = status;
-       return sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) s TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ STATUS http_send_header(char *) */
-PHP_HTTP_API STATUS _http_send_header(const char *header TSRMLS_DC)
-{
-       return http_send_status_header(0, header);
-}
-/* }}} */
-
 /* {{{ STATUS http_send_status_header(int, char *) */
 PHP_HTTP_API STATUS _http_send_status_header(const int status, const char *header TSRMLS_DC)
 {
 /* {{{ STATUS http_send_status_header(int, char *) */
 PHP_HTTP_API STATUS _http_send_status_header(const int status, const char *header TSRMLS_DC)
 {
@@ -727,15 +709,18 @@ PHP_HTTP_API int _http_etag_match(const char *entry, const char *etag TSRMLS_DC)
 /* {{{ STATUS http_send_last_modified(int) */
 PHP_HTTP_API STATUS _http_send_last_modified(const time_t t TSRMLS_DC)
 {
 /* {{{ STATUS http_send_last_modified(int) */
 PHP_HTTP_API STATUS _http_send_last_modified(const time_t t TSRMLS_DC)
 {
-       char modified[96] = "Last-Modified: ", *date;
-       date = http_date(t);
-       strcat(modified, date);
-       efree(date);
+       char *date = NULL;
+       if (date = http_date(t)) {
+               char modified[96] = "Last-Modified: ";
+               strcat(modified, date);
+               efree(date);
 
 
-       /* remember */
-       HTTP_G(lmod) = t;
+               /* remember */
+               HTTP_G(lmod) = t;
 
 
-       return http_send_header(modified);
+               return http_send_header(modified);
+       }
+       return FAILURE;
 }
 /* }}} */
 
 }
 /* }}} */
 
@@ -1020,8 +1005,8 @@ PHP_HTTP_API char *_http_negotiate_q(const char *entry, const zval *supported,
 }
 /* }}} */
 
 }
 /* }}} */
 
-/* {{{ http_range_status http_get_request_ranges(zval *zranges, size_t) */
-PHP_HTTP_API http_range_status _http_get_request_ranges(zval *zranges,
+/* {{{ http_range_status http_get_request_ranges(HashTable *ranges, size_t) */
+PHP_HTTP_API http_range_status _http_get_request_ranges(HashTable *ranges,
        const size_t length TSRMLS_DC)
 {
        zval *zrange;
        const size_t length TSRMLS_DC)
 {
        zval *zrange;
@@ -1130,7 +1115,7 @@ PHP_HTTP_API http_range_status _http_get_request_ranges(zval *zranges,
                                        array_init(zentry);
                                        add_index_long(zentry, 0, begin);
                                        add_index_long(zentry, 1, end);
                                        array_init(zentry);
                                        add_index_long(zentry, 0, begin);
                                        add_index_long(zentry, 1, end);
-                                       add_next_index_zval(zranges, zentry);
+                                       zend_hash_next_index_insert(ranges, &zentry, sizeof(zval *), NULL);
 
                                        begin = -1;
                                        end = -1;
 
                                        begin = -1;
                                        end = -1;
@@ -1148,23 +1133,24 @@ PHP_HTTP_API http_range_status _http_get_request_ranges(zval *zranges,
 }
 /* }}} */
 
 }
 /* }}} */
 
-/* {{{ STATUS http_send_ranges(zval *, void *, size_t, http_send_mode) */
-PHP_HTTP_API STATUS _http_send_ranges(zval *zranges, const void *data, const size_t size, const http_send_mode mode TSRMLS_DC)
+/* {{{ STATUS http_send_ranges(HashTable *, void *, size_t, http_send_mode) */
+PHP_HTTP_API STATUS _http_send_ranges(HashTable *ranges, const void *data, const size_t size, const http_send_mode mode TSRMLS_DC)
 {
 {
-       int c;
        long **begin, **end;
        zval **zrange;
 
        long **begin, **end;
        zval **zrange;
 
-       /* Send HTTP 206 Partial Content */
-       http_send_status(206);
-
        /* single range */
        /* single range */
-       if ((c = zend_hash_num_elements(Z_ARRVAL_P(zranges))) == 1) {
+       if (zend_hash_num_elements(ranges) == 1) {
                char range_header[256] = {0};
 
                char range_header[256] = {0};
 
-               zend_hash_index_find(Z_ARRVAL_P(zranges), 0, (void **) &zrange);
-               zend_hash_index_find(Z_ARRVAL_PP(zrange), 0, (void **) &begin);
-               zend_hash_index_find(Z_ARRVAL_PP(zrange), 1, (void **) &end);
+               if (SUCCESS != zend_hash_index_find(ranges, 0, (void **) &zrange) ||
+                       SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(zrange), 0, (void **) &begin) ||
+                       SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(zrange), 1, (void **) &end)) {
+                       return FAILURE;
+               }
+
+               /* Send HTTP 206 Partial Content */
+               http_send_status(206);
 
                /* send content range header */
                snprintf(range_header, 255, "Content-Range: bytes %d-%d/%d", **begin, **end, size);
 
                /* send content range header */
                snprintf(range_header, 255, "Content-Range: bytes %d-%d/%d", **begin, **end, size);
@@ -1176,24 +1162,21 @@ PHP_HTTP_API STATUS _http_send_ranges(zval *zranges, const void *data, const siz
 
        /* multi range */
        else {
 
        /* multi range */
        else {
-               int i;
                char bound[23] = {0}, preface[1024] = {0},
                        multi_header[68] = "Content-Type: multipart/byteranges; boundary=";
 
                char bound[23] = {0}, preface[1024] = {0},
                        multi_header[68] = "Content-Type: multipart/byteranges; boundary=";
 
+               /* Send HTTP 206 Partial Content */
+               http_send_status(206);
+
+               /* send multipart/byteranges header */
                snprintf(bound, 22, "--%d%0.9f", time(NULL), php_combined_lcg(TSRMLS_C));
                strncat(multi_header, bound + 2, 21);
                http_send_header(multi_header);
 
                /* send each requested chunk */
                snprintf(bound, 22, "--%d%0.9f", time(NULL), php_combined_lcg(TSRMLS_C));
                strncat(multi_header, bound + 2, 21);
                http_send_header(multi_header);
 
                /* send each requested chunk */
-               for (   i = 0,  zend_hash_internal_pointer_reset(Z_ARRVAL_P(zranges));
-                               i < c;
-                               i++,    zend_hash_move_forward(Z_ARRVAL_P(zranges))) {
-                       if (    HASH_KEY_NON_EXISTANT == zend_hash_get_current_data(
-                                               Z_ARRVAL_P(zranges), (void **) &zrange) ||
-                                       SUCCESS != zend_hash_index_find(
-                                               Z_ARRVAL_PP(zrange), 0, (void **) &begin) ||
-                                       SUCCESS != zend_hash_index_find(
-                                               Z_ARRVAL_PP(zrange), 1, (void **) &end)) {
+               FOREACH_HASH_VAL(ranges, zrange) {
+                       if (SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(zrange), 0, (void **) &begin) ||
+                               SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(zrange), 1, (void **) &end)) {
                                break;
                        }
 
                                break;
                        }
 
@@ -1216,15 +1199,16 @@ PHP_HTTP_API STATUS _http_send_ranges(zval *zranges, const void *data, const siz
                }
 
                /* write boundary once more */
                }
 
                /* write boundary once more */
-               php_body_write(HTTP_CRLF, 2 TSRMLS_CC);
+               php_body_write(HTTP_CRLF, sizeof(HTTP_CRLF) - 1 TSRMLS_CC);
                php_body_write(bound, strlen(bound) TSRMLS_CC);
                php_body_write(bound, strlen(bound) TSRMLS_CC);
+               php_body_write("--", 2 TSRMLS_CC);
 
                return SUCCESS;
        }
 }
 /* }}} */
 
 
                return SUCCESS;
        }
 }
 /* }}} */
 
-/* {{{ STATUS http_send(void *, sizezo_t, http_send_mode) */
+/* {{{ STATUS http_send(void *, size_t, http_send_mode) */
 PHP_HTTP_API STATUS _http_send(const void *data_ptr, const size_t data_size,
        const http_send_mode data_mode TSRMLS_DC)
 {
 PHP_HTTP_API STATUS _http_send(const void *data_ptr, const size_t data_size,
        const http_send_mode data_mode TSRMLS_DC)
 {
@@ -1233,6 +1217,9 @@ PHP_HTTP_API STATUS _http_send(const void *data_ptr, const size_t data_size,
        if (!data_ptr) {
                return FAILURE;
        }
        if (!data_ptr) {
                return FAILURE;
        }
+       if (!data_size) {
+               return SUCCESS;
+       }
 
        /* etag handling */
        if (HTTP_G(etag_started)) {
 
        /* etag handling */
        if (HTTP_G(etag_started)) {
@@ -1272,28 +1259,24 @@ PHP_HTTP_API STATUS _http_send(const void *data_ptr, const size_t data_size,
                ) {
 
                        STATUS result = FAILURE;
                ) {
 
                        STATUS result = FAILURE;
-                       zval *zranges = NULL;
-                       MAKE_STD_ZVAL(zranges);
-                       array_init(zranges);
+                       HashTable ranges;
+                       zend_hash_init(&ranges, 0, NULL, ZVAL_PTR_DTOR, 0);
 
 
-                       switch (http_get_request_ranges(zranges, data_size))
+                       switch (http_get_request_ranges(&ranges, data_size))
                        {
                                case RANGE_NO:
                        {
                                case RANGE_NO:
-                                       zval_dtor(zranges);
-                                       efree(zranges);
+                                       zend_hash_destroy(&ranges);
                                        /* go ahead and send all */
                                break;
 
                                case RANGE_OK:
                                        /* go ahead and send all */
                                break;
 
                                case RANGE_OK:
-                                       result = http_send_ranges(zranges, data_ptr, data_size, data_mode);
-                                       zval_dtor(zranges);
-                                       efree(zranges);
+                                       result = http_send_ranges(&ranges, data_ptr, data_size, data_mode);
+                                       zend_hash_destroy(&ranges);
                                        return result;
                                break;
 
                                case RANGE_ERR:
                                        return result;
                                break;
 
                                case RANGE_ERR:
-                                       zval_dtor(zranges);
-                                       efree(zranges);
+                                       zend_hash_destroy(&ranges);
                                        http_send_status(416);
                                        return FAILURE;
                                break;
                                        http_send_status(416);
                                        return FAILURE;
                                break;
@@ -1309,49 +1292,23 @@ PHP_HTTP_API STATUS _http_send(const void *data_ptr, const size_t data_size,
 }
 /* }}} */
 
 }
 /* }}} */
 
-/* {{{ STATUS http_send_data(zval *) */
-PHP_HTTP_API STATUS _http_send_data(const zval *zdata TSRMLS_DC)
-{
-       if (!Z_STRLEN_P(zdata)) {
-               return SUCCESS;
-       }
-       if (!Z_STRVAL_P(zdata)) {
-               return FAILURE;
-       }
-
-       return http_send(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata), SEND_DATA);
-}
-/* }}} */
-
 /* {{{ STATUS http_send_stream(php_stream *) */
 /* {{{ STATUS http_send_stream(php_stream *) */
-PHP_HTTP_API STATUS _http_send_stream(const php_stream *file TSRMLS_DC)
+PHP_HTTP_API STATUS _http_send_stream_ex(php_stream *file,
+       zend_bool close_stream TSRMLS_DC)
 {
 {
-       if (php_stream_stat((php_stream *) file, &HTTP_G(ssb))) {
-               return FAILURE;
-       }
-
-       return http_send(file, HTTP_G(ssb).sb.st_size, SEND_RSRC);
-}
-/* }}} */
-
-/* {{{ STATUS http_send_file(zval *) */
-PHP_HTTP_API STATUS _http_send_file(const zval *zfile TSRMLS_DC)
-{
-       php_stream *file;
-       STATUS ret;
+       STATUS status;
 
 
-       if (!Z_STRLEN_P(zfile)) {
+       if ((!file) || php_stream_stat(file, &HTTP_G(ssb))) {
                return FAILURE;
        }
 
                return FAILURE;
        }
 
-       if (!(file = php_stream_open_wrapper(Z_STRVAL_P(zfile), "rb",
-                       REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL))) {
-               return FAILURE;
+       status = http_send(file, HTTP_G(ssb).sb.st_size, SEND_RSRC);
+
+       if (close_stream) {
+               php_stream_close(file);
        }
 
        }
 
-       ret = http_send_stream(file);
-       php_stream_close(file);
-       return ret;
+       return status;
 }
 /* }}} */
 
 }
 /* }}} */
 
@@ -1420,7 +1377,7 @@ PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded,
 /* }}} */
 
 /* {{{ proto STATUS http_split_response_ex(char *, size_t, zval *, zval *) */
 /* }}} */
 
 /* {{{ proto STATUS http_split_response_ex(char *, size_t, zval *, zval *) */
-PHP_HTTP_API STATUS _http_split_response_ex( char *response,
+PHP_HTTP_API STATUS _http_split_response_ex(char *response,
        size_t response_len, zval *zheaders, zval *zbody TSRMLS_DC)
 {
        char *body = NULL;
        size_t response_len, zval *zheaders, zval *zbody TSRMLS_DC)
 {
        char *body = NULL;
index 9bf3857ac1c704008d951c579a665d543f2dea25..288a08473ceb1e830cb8ecaa2f59d1e1c87d181a 100644 (file)
@@ -644,4 +644,4 @@ PHP_HTTP_API STATUS _http_post_curldata_ex(CURL *ch, const char *URL,
  * End:
  * vim600: noet sw=4 ts=4 fdm=marker
  * vim<600: noet sw=4 ts=4
  * End:
  * vim600: noet sw=4 ts=4 fdm=marker
  * vim<600: noet sw=4 ts=4
- */
\ No newline at end of file
+ */
index 5190d5b48bad8e64c61584467239581466ecdc00..6afde9455f8773e917d8403afb1cd068865ad33c 100644 (file)
@@ -269,7 +269,7 @@ PHP_FUNCTION(http_send_content_disposition)
 }
 /* }}} */
 
 }
 /* }}} */
 
-/* {{{ proto bool http_match_modified([int timestamp])
+/* {{{ proto bool http_match_modified([int timestamp[, for_range = false]])
  *
  * Matches the given timestamp against the clients "If-Modified-Since" resp.
  * "If-Unmodified-Since" HTTP headers.
  *
  * Matches the given timestamp against the clients "If-Modified-Since" resp.
  * "If-Unmodified-Since" HTTP headers.
@@ -278,8 +278,9 @@ PHP_FUNCTION(http_send_content_disposition)
 PHP_FUNCTION(http_match_modified)
 {
        long t = -1;
 PHP_FUNCTION(http_match_modified)
 {
        long t = -1;
+       zend_bool for_range = 0;
 
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lb", &t, &for_range) != SUCCESS) {
                RETURN_FALSE;
        }
 
                RETURN_FALSE;
        }
 
@@ -288,11 +289,14 @@ PHP_FUNCTION(http_match_modified)
                t = (long) time(NULL);
        }
 
                t = (long) time(NULL);
        }
 
-       RETURN_BOOL(http_modified_match("HTTP_IF_MODIFIED_SINCE", t) || http_modified_match("HTTP_IF_UNMODIFIED_SINCE", t));
+       if (for_range) {
+               RETURN_BOOL(http_modified_match("HTTP_IF_UNMODIFIED_SINCE", t));
+       }
+       RETURN_BOOL(http_modified_match("HTTP_IF_MODIFIED_SINCE", t));
 }
 /* }}} */
 
 }
 /* }}} */
 
-/* {{{ proto bool http_match_etag(string etag)
+/* {{{ proto bool http_match_etag(string etag[, for_range = false])
  *
  * This matches the given ETag against the clients
  * "If-Match" resp. "If-None-Match" HTTP headers.
  *
  * This matches the given ETag against the clients
  * "If-Match" resp. "If-None-Match" HTTP headers.
@@ -302,12 +306,16 @@ PHP_FUNCTION(http_match_etag)
 {
        int etag_len;
        char *etag;
 {
        int etag_len;
        char *etag;
+       zend_bool for_range = 0;
 
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &etag, &etag_len) != SUCCESS) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &etag, &etag_len, &for_range) != SUCCESS) {
                RETURN_FALSE;
        }
 
                RETURN_FALSE;
        }
 
-       RETURN_BOOL(http_etag_match("HTTP_IF_NONE_MATCH", etag) || http_etag_match("HTTP_IF_MATCH", etag));
+       if (for_range) {
+               RETURN_BOOL(http_etag_match("HTTP_IF_MATCH", etag));
+       }
+       RETURN_BOOL(http_etag_match("HTTP_IF_NONE_MATCH", etag));
 }
 /* }}} */
 
 }
 /* }}} */
 
@@ -493,7 +501,7 @@ PHP_FUNCTION(http_send_data)
 
        convert_to_string_ex(&zdata);
        http_send_header("Accept-Ranges: bytes");
 
        convert_to_string_ex(&zdata);
        http_send_header("Accept-Ranges: bytes");
-       RETURN_SUCCESS(http_send_data(zdata));
+       RETURN_SUCCESS(http_send_data(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata)));
 }
 /* }}} */
 
 }
 /* }}} */
 
@@ -504,15 +512,18 @@ PHP_FUNCTION(http_send_data)
  */
 PHP_FUNCTION(http_send_file)
 {
  */
 PHP_FUNCTION(http_send_file)
 {
-       zval *zfile;
+       char *file;
+       int flen = 0;
 
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zfile) != SUCCESS) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &flen) != SUCCESS) {
+               RETURN_FALSE;
+       }
+       if (!flen) {
                RETURN_FALSE;
        }
 
                RETURN_FALSE;
        }
 
-       convert_to_string_ex(&zfile);
        http_send_header("Accept-Ranges: bytes");
        http_send_header("Accept-Ranges: bytes");
-       RETURN_SUCCESS(http_send_file(zfile));
+       RETURN_SUCCESS(http_send_file(file));
 }
 /* }}} */
 
 }
 /* }}} */
 
@@ -569,6 +580,7 @@ PHP_FUNCTION(http_chunked_decode)
  *     0 => array(
  *         'Status' => '200 Ok',
  *         'Content-Type' => 'text/plain',
  *     0 => array(
  *         'Status' => '200 Ok',
  *         'Content-Type' => 'text/plain',
+
  *         'Content-Language' => 'en-US'
  *     ),
  *     1 => "Hello World!"
  *         'Content-Language' => 'en-US'
  *     ),
  *     1 => "Hello World!"
@@ -934,7 +946,7 @@ PHP_FUNCTION(http_auth_basic_cb)
 /* }}}*/
 
 /* {{{ Sara Golemons http_build_query() */
 /* }}}*/
 
 /* {{{ Sara Golemons http_build_query() */
-#ifndef ZEND_ENGINE_2 
+#ifndef ZEND_ENGINE_2
 
 /* {{{ proto string http_build_query(mixed formdata [, string prefix])
    Generates a form-encoded query string from an associative array or object. */
 
 /* {{{ proto string http_build_query(mixed formdata [, string prefix])
    Generates a form-encoded query string from an associative array or object. */
@@ -980,4 +992,4 @@ PHP_FUNCTION(http_build_query)
  * End:
  * vim600: noet sw=4 ts=4 fdm=marker
  * vim<600: noet sw=4 ts=4
  * End:
  * vim600: noet sw=4 ts=4 fdm=marker
  * vim<600: noet sw=4 ts=4
- */
\ No newline at end of file
+ */
index 3701e1a953f94bdc08bc53ac0bf8e60ec98711db..85d029e675359d70717b8df34de1072c6bac419e 100644 (file)
@@ -438,7 +438,8 @@ PHP_METHOD(HTTPi_Response, send)
                {
                        case SEND_DATA:
                        {
                {
                        case SEND_DATA:
                        {
-                               RETURN_SUCCESS(http_send_data(GET_PROP(obj, data)));
+                               zval *zdata = GET_PROP(obj, data);
+                               RETURN_SUCCESS(http_send_data(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata)));
                        }
 
                        case SEND_RSRC:
                        }
 
                        case SEND_RSRC:
@@ -451,7 +452,8 @@ PHP_METHOD(HTTPi_Response, send)
 
                        default:
                        {
 
                        default:
                        {
-                               RETURN_SUCCESS(http_send_file(GET_PROP(obj, file)));
+                               zval *zfile = GET_PROP(obj, file);
+                               RETURN_SUCCESS(http_send_file(Z_STRVAL_P(zfile)));
                        }
                }
        }
                        }
                }
        }
@@ -1118,4 +1120,5 @@ PHP_METHOD(HTTPi_Request, send)
  * End:
  * vim600: noet sw=4 ts=4 fdm=marker
  * vim<600: noet sw=4 ts=4
  * End:
  * vim600: noet sw=4 ts=4 fdm=marker
  * vim<600: noet sw=4 ts=4
- */
\ No newline at end of file
+ */
+
index 93866f3d7de3b36cf9e5b13cbdbb14a01fb1348a..d7973ac8b7bb0d39b4f906a3c7cf72b3c6d3ccc3 100644 (file)
@@ -45,18 +45,16 @@ typedef enum {
 char *pretty_key(char *key, int key_len, int uctitle, int xhyphen);
 
 /* {{{ public API */
 char *pretty_key(char *key, int key_len, int uctitle, int xhyphen);
 
 /* {{{ public API */
+#define http_is_range_request() zend_hash_exists(HTTP_SERVER_VARS, "HTTP_RANGE", sizeof("HTTP_RANGE"))
+
 #define http_date(t) _http_date((t) TSRMLS_CC)
 PHP_HTTP_API char *_http_date(time_t t TSRMLS_DC);
 
 #define http_parse_date(d) _http_parse_date((d))
 PHP_HTTP_API time_t _http_parse_date(const char *date);
 
 #define http_date(t) _http_date((t) TSRMLS_CC)
 PHP_HTTP_API char *_http_date(time_t t TSRMLS_DC);
 
 #define http_parse_date(d) _http_parse_date((d))
 PHP_HTTP_API time_t _http_parse_date(const char *date);
 
-#define http_send_status(s) _http_send_status((s) TSRMLS_CC)
-PHP_HTTP_API inline STATUS _http_send_status(const int status TSRMLS_DC);
-
-#define http_send_header(h) _http_send_header((h) TSRMLS_CC)
-PHP_HTTP_API inline STATUS _http_send_header(const char *header TSRMLS_DC);
-
+#define http_send_status(s) sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) (s) TSRMLS_CC)
+#define http_send_header(h) http_send_status_header(0, (h))
 #define http_send_status_header(s, h) _http_send_status_header((s), (h) TSRMLS_CC)
 PHP_HTTP_API inline STATUS _http_send_status_header(const int status, const char *header TSRMLS_DC);
 
 #define http_send_status_header(s, h) _http_send_status_header((s), (h) TSRMLS_CC)
 PHP_HTTP_API inline STATUS _http_send_status_header(const int status, const char *header TSRMLS_DC);
 
@@ -69,9 +67,6 @@ PHP_HTTP_API inline char *_http_etag(const void *data_ptr, const size_t data_len
 #define http_lmod(p, m) _http_lmod((p), (m) TSRMLS_CC)
 PHP_HTTP_API inline time_t _http_lmod(const void *data_ptr, const http_send_mode data_mode TSRMLS_DC);
 
 #define http_lmod(p, m) _http_lmod((p), (m) TSRMLS_CC)
 PHP_HTTP_API inline time_t _http_lmod(const void *data_ptr, const http_send_mode data_mode TSRMLS_DC);
 
-#define http_is_range_request() _http_is_range_request(TSRMLS_C)
-PHP_HTTP_API inline int _http_is_range_request(TSRMLS_D);
-
 #define http_ob_etaghandler(o, l, ho, hl, m) _http_ob_etaghandler((o), (l), (ho), (hl), (m) TSRMLS_CC)
 PHP_HTTP_API void _http_ob_etaghandler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC);
 
 #define http_ob_etaghandler(o, l, ho, hl, m) _http_ob_etaghandler((o), (l), (ho), (hl), (m) TSRMLS_CC)
 PHP_HTTP_API void _http_ob_etaghandler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC);
 
@@ -114,22 +109,19 @@ PHP_HTTP_API char *_http_absolute_uri(const char *url, const char *proto TSRMLS_
 PHP_HTTP_API char *_http_negotiate_q(const char *entry, const zval *supported, const char *def TSRMLS_DC);
 
 #define http_get_request_ranges(r, l) _http_get_request_ranges((r), (l) TSRMLS_CC)
 PHP_HTTP_API char *_http_negotiate_q(const char *entry, const zval *supported, const char *def TSRMLS_DC);
 
 #define http_get_request_ranges(r, l) _http_get_request_ranges((r), (l) TSRMLS_CC)
-PHP_HTTP_API http_range_status _http_get_request_ranges(zval *zranges, const size_t length TSRMLS_DC);
+PHP_HTTP_API http_range_status _http_get_request_ranges(HashTable *ranges, const size_t length TSRMLS_DC);
 
 #define http_send_ranges(r, d, s, m) _http_send_ranges((r), (d), (s), (m) TSRMLS_CC)
 
 #define http_send_ranges(r, d, s, m) _http_send_ranges((r), (d), (s), (m) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_send_ranges(zval *zranges, const void *data, const size_t size, const http_send_mode mode TSRMLS_DC);
+PHP_HTTP_API STATUS _http_send_ranges(HashTable *ranges, const void *data, const size_t size, const http_send_mode mode TSRMLS_DC);
 
 
+#define http_send_data(d, l) http_send((d), (l), SEND_DATA)
 #define http_send(d, s, m) _http_send((d), (s), (m) TSRMLS_CC)
 PHP_HTTP_API STATUS _http_send(const void *data, const size_t data_size, const http_send_mode mode TSRMLS_DC);
 
 #define http_send(d, s, m) _http_send((d), (s), (m) TSRMLS_CC)
 PHP_HTTP_API STATUS _http_send(const void *data, const size_t data_size, const http_send_mode mode TSRMLS_DC);
 
-#define http_send_data(z) _http_send_data((z) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_send_data(const zval *zdata TSRMLS_DC);
-
-#define http_send_stream(s) _http_send_stream((s) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_send_stream(const php_stream *s TSRMLS_DC);
-
-#define http_send_file(f) _http_send_file((f) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_send_file(const zval *zfile TSRMLS_DC);
+#define http_send_file(f) http_send_stream_ex(php_stream_open_wrapper(f, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL), 1)
+#define http_send_stream(s) http_send_stream_ex((s), 0)
+#define http_send_stream_ex(s, c) _http_send_stream_ex((s), (c) TSRMLS_CC)
+PHP_HTTP_API STATUS _http_send_stream_ex(php_stream *s, zend_bool close_stream TSRMLS_DC);
 
 #define http_chunked_decode(e, el, d, dl) _http_chunked_decode((e), (el), (d), (dl) TSRMLS_CC)
 PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, const size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC);
 
 #define http_chunked_decode(e, el, d, dl) _http_chunked_decode((e), (el), (d), (dl) TSRMLS_CC)
 PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, const size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC);
@@ -174,4 +166,4 @@ PHP_HTTP_API STATUS php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
  * End:
  * vim600: noet sw=4 ts=4 fdm=marker
  * vim<600: noet sw=4 ts=4
  * End:
  * vim600: noet sw=4 ts=4 fdm=marker
  * vim<600: noet sw=4 ts=4
- */
+ */
\ No newline at end of file
index 3b55c28f6de7d4619007641dca109eac99a97a61..3bcd8abed3182443c51be5282d4ad29f19f32ffc 100644 (file)
@@ -49,4 +49,4 @@ PHP_HTTP_API STATUS _http_post_curldata_ex(CURL *ch, const char *URL, struct cur
  * End:
  * vim600: noet sw=4 ts=4 fdm=marker
  * vim<600: noet sw=4 ts=4
  * End:
  * vim600: noet sw=4 ts=4 fdm=marker
  * vim<600: noet sw=4 ts=4
- */
\ No newline at end of file
+ */
index 7335be33a5ced52789987c5d61487f2716b5eb3d..bff38941e19bcfda71adef75dbbf06fff71e43e8 100644 (file)
  * End:
  * vim600: noet sw=4 ts=4 fdm=marker
  * vim<600: noet sw=4 ts=4
  * End:
  * vim600: noet sw=4 ts=4 fdm=marker
  * vim<600: noet sw=4 ts=4
- */
\ No newline at end of file
+ */