#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-#include "php.h"
-
-#include "php_http_encoding_api.h"
#include "php_http.h"
-#include "php_http_api.h"
-#ifdef HTTP_HAVE_ZLIB
-# include "php_http_send_api.h"
-# include "php_http_headers_api.h"
-# include <zlib.h>
-#endif
+#include "php_http_api.h"
+#include "php_http_encoding_api.h"
+#include "php_http_send_api.h"
+#include "php_http_headers_api.h"
ZEND_EXTERN_MODULE_GLOBALS(http);
*decoded = ecalloc(1, encoded_len);
while ((encoded + encoded_len - e_ptr) > 0) {
- unsigned long chunk_len = 0, rest;
+ ulong chunk_len = 0, rest;
chunk_len = strtoul(e_ptr, &n_ptr, 16);
return encoded + encoded_len;
} else {
efree(*decoded);
- http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected chunk size at pos %lu of %lu but got trash", (unsigned long) (n_ptr - encoded), (unsigned long) encoded_len);
+ http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected chunk size at pos %tu of %zu but got trash", n_ptr - encoded, encoded_len);
return NULL;
}
}
/* reached the end */
if (!chunk_len) {
+ /* move over '0' chunked encoding terminator */
+ while (*e_ptr == '0') ++e_ptr;
break;
}
/* there should be CRLF after the chunk size, but we'll ignore SP+ too */
if (*n_ptr && !eol_match(&n_ptr, &eol_len)) {
if (eol_len == 2) {
- http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected CRLF at pos %lu of %lu but got 0x%02X 0x%02X", (unsigned long) (n_ptr - encoded), (unsigned long) encoded_len, *n_ptr, *(n_ptr + 1));
+ http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected CRLF at pos %tu of %zu but got 0x%02X 0x%02X", n_ptr - encoded, encoded_len, *n_ptr, *(n_ptr + 1));
} else {
- http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected LF at pos %lu of %lu but got 0x%02X", (unsigned long) (n_ptr - encoded), (unsigned long) encoded_len, *n_ptr);
+ http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected LF at pos %tu of %zu but got 0x%02X", n_ptr - encoded, encoded_len, *n_ptr);
}
}
n_ptr += eol_len;
/* chunk size pretends more data than we actually got, so it's probably a truncated message */
if (chunk_len > (rest = encoded + encoded_len - n_ptr)) {
- http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Truncated message: chunk size %lu exceeds remaining data size %lu at pos %lu of %lu", chunk_len, rest, (unsigned long) (n_ptr - encoded), (unsigned long) encoded_len);
+ http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Truncated message: chunk size %lu exceeds remaining data size %lu at pos %tu of %zu", chunk_len, rest, n_ptr - encoded, encoded_len);
chunk_len = rest;
}
inline size_t http_finish_gzencode_buffer(z_stream *Z, const char *data, size_t data_len, char **buf_ptr)
{
- unsigned long crc;
+ ulong crc;
char *trailer;
crc = crc32(0L, Z_NULL, 0);
if (data_len <= offset) {
goto really_bad_gzip_header;
} else {
- unsigned long crc, cmp;
+ ulong crc, cmp;
cmp = (unsigned) ((data[offset-2] & 0xFF));
cmp += (unsigned) ((data[offset-1] & 0xFF) << 8);
inline STATUS http_verify_gzdecode_buffer(const char *data, size_t data_len, const char *decoded, size_t decoded_len, int error_level TSRMLS_DC)
{
STATUS status = SUCCESS;
- unsigned long len, cmp, crc;
+ ulong len, cmp, crc;
crc = crc32(0L, Z_NULL, 0);
crc = crc32(crc, (const Bytef *) decoded, decoded_len);
http_init_gzencode_buffer(&Z, data, data_len, encoded);
- if ( (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) &&
- (Z_STREAM_END == (status = deflate(&Z, Z_FINISH))) &&
- (Z_OK == (status = deflateEnd(&Z)))) {
- *encoded_len = http_finish_gzencode_buffer(&Z, data, data_len, encoded);
- return SUCCESS;
+ if (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) {
+ status = deflate(&Z, Z_FINISH);
+ deflateEnd(&Z);
+
+ if (Z_STREAM_END == status) {
+ *encoded_len = http_finish_gzencode_buffer(&Z, data, data_len, encoded);
+ return SUCCESS;
+ }
}
efree(*encoded);
http_init_deflate_buffer(&Z, data, data_len, encoded);
- if ( (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) &&
- (Z_STREAM_END == (status = deflate(&Z, Z_FINISH))) &&
- (Z_OK == (status = deflateEnd(&Z)))) {
- *encoded_len = http_finish_buffer(Z.total_out, encoded);
- return SUCCESS;
+ if (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) {
+ status = deflate(&Z, Z_FINISH);
+ deflateEnd(&Z);
+
+ if (Z_STREAM_END == status) {
+ *encoded_len = http_finish_buffer(Z.total_out, encoded);
+ return SUCCESS;
+ }
}
efree(encoded);
do {
http_init_inflate_buffer(&Z, data, data_len, decoded, decoded_len, &max);
if (Z_OK == (status = inflateInit2(&Z, -MAX_WBITS))) {
- if (Z_STREAM_END == (status = inflate(&Z, Z_FINISH))) {
- if (Z_OK == (status = inflateEnd(&Z))) {
- *decoded_len = http_finish_buffer(Z.total_out, decoded);
- return SUCCESS;
- }
+ status = inflate(&Z, Z_FINISH);
+ inflateEnd(&Z);
+
+ if (Z_STREAM_END == status) {
+ *decoded_len = http_finish_buffer(Z.total_out, decoded);
+ return SUCCESS;
}
}
} while (++max < HTTP_ENCODING_MAXTRY && status == Z_BUF_ERROR);
HTTP_ENCODING_STREAM_ERROR(status, NULL);
}
- if (s->gzip = gzip) {
+ if ((s->gzip = gzip)) {
s->crc = crc32(0L, Z_NULL, 0);
*encoded_len = sizeof(http_encoding_gzip_header);
*encoded = emalloc(*encoded_len);
if (content_length) {
char cl_header_str[128];
size_t cl_header_len;
- cl_header_len = snprintf(cl_header_str, lenof(cl_header_str), "Content-Length: %lu", (unsigned long) content_length);
+ cl_header_len = snprintf(cl_header_str, lenof(cl_header_str), "Content-Length: %zu", content_length);
http_send_header_string_ex(cl_header_str, cl_header_len, 1);
}
} else {
HTTP_G(send).gzip_encoding = 0;
- if (selected = http_negotiate_encoding(&zsupported)) {
+ if ((selected = http_negotiate_encoding(&zsupported))) {
STATUS hs = FAILURE;
char *encoding = NULL;
ulong idx;