X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_api.c;h=0e73eb3682594c2533358181624c385726009f81;hb=405c97a03c1949e59a154520d2cc24a297aa6ea1;hp=6d21ca47e524f1601a3972171a5b98607b0b17e0;hpb=96d32e2bd4a5d2b0741addf6f59b46d7d8749937;p=m6w6%2Fext-http diff --git a/http_api.c b/http_api.c index 6d21ca4..0e73eb3 100644 --- a/http_api.c +++ b/http_api.c @@ -18,7 +18,7 @@ #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #ifdef HAVE_CONFIG_H -#include "config.h" +# include "config.h" #endif #include @@ -37,9 +37,9 @@ #include "SAPI.h" #ifdef ZEND_ENGINE_2 -#include "ext/standard/php_http.h" +# include "ext/standard/php_http.h" #else -#include "http_build_query.c" + #include "http_build_query.c" #endif #include "php_http.h" @@ -47,13 +47,14 @@ #ifdef HTTP_HAVE_CURL -#ifdef PHP_WIN32 -#include -#include -#endif +# ifdef PHP_WIN32 +# include +# include +# endif + +# include +# include -#include -#include #endif @@ -762,6 +763,9 @@ static inline void _http_curl_getinfo(CURL *ch, HashTable *info TSRMLS_DC) } /* }}} */ +#endif +/* }}} HAVE_CURL */ + /* {{{ Day/Month/TZ checks for http_parse_date() Originally by libcurl, Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. */ static int check_day(char *day, size_t len) @@ -807,9 +811,6 @@ static int check_tzone(char *tzone) } /* }}} */ -#endif -/* }}} HAVE_CURL */ - /* }}} internals */ /* {{{ public API */ @@ -1418,16 +1419,17 @@ 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) { - zval **zrange; + int c; long **begin, **end; - char range_header[255], multi_header[68] = "Content-Type: multipart/byteranges; boundary=", bound[23], preface[1024]; - int i, c; + zval **zrange; /* Send HTTP 206 Partial Content */ http_send_status(206); /* single range */ if ((c = zend_hash_num_elements(Z_ARRVAL_P(zranges))) == 1) { + 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); @@ -1441,37 +1443,52 @@ PHP_HTTP_API STATUS _http_send_ranges(zval *zranges, const void *data, const siz } /* multi range */ + else { + int i; + char bound[23] = {0}, preface[1024] = {0}, + multi_header[68] = "Content-Type: multipart/byteranges; boundary="; + + 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)) { + break; + } - snprintf(bound, 23, "--%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)) { - break; - } + snprintf(preface, 1023, + HTTP_CRLF "%s" + HTTP_CRLF "Content-Type: %s" + HTTP_CRLF "Content-Range: bytes %ld-%ld/%ld" + HTTP_CRLF + HTTP_CRLF, + + bound, + HTTP_G(ctype) ? HTTP_G(ctype) : "application/x-octetstream", + **begin, + **end, + size + ); - snprintf(preface, 1024, - "\r\n%s\r\nContent-Type: %s\r\nContent-Range: bytes %d-%d/%d\r\n\r\n", bound, - HTTP_G(ctype) ? HTTP_G(ctype) : "application/x-octetstream", - **begin, **end, size); - php_body_write(preface, strlen(preface) TSRMLS_CC); - http_send_chunk(data, **begin, **end + 1, mode); - } + php_body_write(preface, strlen(preface) TSRMLS_CC); + http_send_chunk(data, **begin, **end + 1, mode); + } - /* write boundary once more */ - php_body_write(HTTP_CRLF, 1 TSRMLS_CC); - php_body_write(bound, strlen(bound) TSRMLS_CC); + /* write boundary once more */ + php_body_write(HTTP_CRLF, 2 TSRMLS_CC); + php_body_write(bound, strlen(bound) TSRMLS_CC); - return SUCCESS; + return SUCCESS; + } } /* }}} */ @@ -1717,7 +1734,7 @@ PHP_HTTP_API STATUS _http_parse_headers(char *header, int header_len, zval *arra end - (header + strlen("HTTP/1.x ")), 1); header = end + 2; } - + line = header; while (header_len > (line - begin)) { @@ -1727,7 +1744,8 @@ PHP_HTTP_API STATUS _http_parse_headers(char *header, int header_len, zval *arra case '\n': if (colon && (*line != ' ') && (*line != '\t')) { char *key = estrndup(header, colon - header); - add_assoc_stringl(array, key, colon + 2, line - colon - 4, 1); + while (isspace(*(++colon))); + add_assoc_stringl(array, key, colon, line - colon - 2, 1); efree(key); colon = NULL; @@ -1874,12 +1892,12 @@ PHP_HTTP_API STATUS _http_post_array(const char *URL, HashTable *postarray, #endif /* }}} HAVE_CURL */ -/* {{{ void http_auth_header(char *, char*) */ -PHP_HTTP_API void _http_auth_header(const char *type, const char *realm TSRMLS_DC) +/* {{{ STATUS http_auth_header(char *, char*) */ +PHP_HTTP_API STATUS _http_auth_header(const char *type, const char *realm TSRMLS_DC) { - char realm_header[1024]; - snprintf(realm_header, 1024, "WWW-Authenticate: %s realm=\"%s\"", type, realm); - http_send_status_header(401, realm_header); + char realm_header[1024] = {0}; + snprintf(realm_header, 1023, "WWW-Authenticate: %s realm=\"%s\"", type, realm); + return http_send_status_header(401, realm_header); } /* }}} */