projects
/
m6w6
/
ext-http
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
- path has been copied twice
[m6w6/ext-http]
/
http_encoding_api.c
diff --git
a/http_encoding_api.c
b/http_encoding_api.c
index bff322882ae8c25dbf4566b8f83c95db324bbaa3..efbaa7f8669065d006803847406f01e0a8e85bd1 100644
(file)
--- a/
http_encoding_api.c
+++ b/
http_encoding_api.c
@@
-15,6
+15,8
@@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
+
+#define HTTP_WANT_ZLIB
#include "php_http.h"
#include "php_http_api.h"
#include "php_http.h"
#include "php_http_api.h"
@@
-140,9
+142,10
@@
PHP_HTTP_API STATUS _http_encoding_gzencode(int level, int mtime, const char *da
return FAILURE;
}
return FAILURE;
}
- Z.zalloc = Z_NULL;
- Z.zfree = Z_NULL;
- Z.opaque = Z_NULL;
+ *encoded = NULL;
+ *encoded_len = 0;
+ memset(&Z, 0, sizeof(z_stream));
+
Z.next_in = (Bytef *) data;
Z.avail_in = data_len;
Z.avail_out = HTTP_ENCODING_BUFLEN(data_len) + HTTP_ENCODING_SAFPAD - 1;
Z.next_in = (Bytef *) data;
Z.avail_in = data_len;
Z.avail_out = HTTP_ENCODING_BUFLEN(data_len) + HTTP_ENCODING_SAFPAD - 1;
@@
-188,7
+191,7
@@
PHP_HTTP_API STATUS _http_encoding_gzencode(int level, int mtime, const char *da
}
}
}
}
-
efree(*encoded
);
+
STR_SET(*encoded, NULL
);
http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not gzencode data: %s", zError(status));
return FAILURE;
}
http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not gzencode data: %s", zError(status));
return FAILURE;
}
@@
-213,9
+216,10
@@
PHP_HTTP_API STATUS _http_encoding_deflate(int level, int zhdr, const char *data
z_stream Z;
STATUS status = Z_OK;
z_stream Z;
STATUS status = Z_OK;
- Z.zalloc = Z_NULL;
- Z.zfree = Z_NULL;
- Z.opaque = Z_NULL;
+ *encoded = NULL;
+ *encoded_len = 0;
+ memset(&Z, 0, sizeof(z_stream));
+
Z.data_type = Z_UNKNOWN;
Z.next_in = (Bytef *) data;
Z.avail_in = data_len;
Z.data_type = Z_UNKNOWN;
Z.next_in = (Bytef *) data;
Z.avail_in = data_len;
@@
-234,7
+238,7
@@
PHP_HTTP_API STATUS _http_encoding_deflate(int level, int zhdr, const char *data
}
}
}
}
-
efree(encoded
);
+
STR_SET(*encoded, NULL
);
http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not deflate data: %s", zError(status));
return FAILURE;
}
http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not deflate data: %s", zError(status));
return FAILURE;
}
@@
-245,10
+249,11
@@
PHP_HTTP_API STATUS _http_encoding_inflate(const char *data, size_t data_len, ch
STATUS status;
z_stream Z;
STATUS status;
z_stream Z;
+ *decoded = NULL;
+ *decoded_len = 0;
+ memset(&Z, 0, sizeof(z_stream));
+
do {
do {
- Z.zalloc = Z_NULL;
- Z.zfree = Z_NULL;
-
if (!max) {
*decoded_len = data_len * 2;
*decoded = emalloc(*decoded_len + 1);
if (!max) {
*decoded_len = data_len * 2;
*decoded = emalloc(*decoded_len + 1);
@@
-287,7
+292,7
@@
retry_inflate:
}
} while (status == Z_BUF_ERROR && ++max < HTTP_ENCODING_MAXTRY);
}
} while (status == Z_BUF_ERROR && ++max < HTTP_ENCODING_MAXTRY);
-
efree(*decoded
);
+
STR_SET(*decoded, NULL
);
http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not inflate data: %s", zError(status));
return FAILURE;
}
http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not inflate data: %s", zError(status));
return FAILURE;
}
@@
-408,19
+413,21
@@
PHP_HTTP_API STATUS _http_encoding_gzdecode_verify(const char *data, size_t data
return FAILURE; \
}
return FAILURE; \
}
-PHP_HTTP_API STATUS _http_encoding_stream_init(http_encoding_stream *s, int
gzip
, int level, char **encoded, size_t *encoded_len TSRMLS_DC)
+PHP_HTTP_API STATUS _http_encoding_stream_init(http_encoding_stream *s, int
flags
, int level, char **encoded, size_t *encoded_len TSRMLS_DC)
{
STATUS status;
{
STATUS status;
+ int wbits = (flags & HTTP_ENCODING_STREAM_ZLIB_HEADER) ? MAX_WBITS : -MAX_WBITS;
memset(s, 0, sizeof(http_encoding_stream));
memset(s, 0, sizeof(http_encoding_stream));
- if (Z_OK != (status = deflateInit2(&s->Z, level, Z_DEFLATED,
-MAX_WBITS
, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) {
+ if (Z_OK != (status = deflateInit2(&s->Z, level, Z_DEFLATED,
wbits
, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) {
HTTP_ENCODING_STREAM_ERROR(status, NULL);
}
HTTP_ENCODING_STREAM_ERROR(status, NULL);
}
- if ((s->gzip = gzip)) {
+ s->persistent = (flags & HTTP_ENCODING_STREAM_PERSISTENT);
+ if ((s->gzip = (flags & HTTP_ENCODING_STREAM_GZIP_HEADER))) {
s->crc = crc32(0L, Z_NULL, 0);
*encoded_len = sizeof(http_encoding_gzip_header);
s->crc = crc32(0L, Z_NULL, 0);
*encoded_len = sizeof(http_encoding_gzip_header);
- *encoded =
emalloc(*encoded_len
);
+ *encoded =
pemalloc(*encoded_len, s->persistent
);
memcpy(*encoded, http_encoding_gzip_header, *encoded_len);
} else {
*encoded_len = 0;
memcpy(*encoded, http_encoding_gzip_header, *encoded_len);
} else {
*encoded_len = 0;
@@
-435,7
+442,7
@@
PHP_HTTP_API STATUS _http_encoding_stream_update(http_encoding_stream *s, const
STATUS status;
*encoded_len = HTTP_ENCODING_BUFLEN(data_len);
STATUS status;
*encoded_len = HTTP_ENCODING_BUFLEN(data_len);
- *encoded =
emalloc(*encoded_len
);
+ *encoded =
pemalloc(*encoded_len, s->persistent
);
s->Z.next_in = (Bytef *) data;
s->Z.avail_in = data_len;
s->Z.next_in = (Bytef *) data;
s->Z.avail_in = data_len;
@@
-461,7
+468,7
@@
PHP_HTTP_API STATUS _http_encoding_stream_finish(http_encoding_stream *s, char *
STATUS status;
*encoded_len = 1024;
STATUS status;
*encoded_len = 1024;
- *encoded =
emalloc(*encoded_len
);
+ *encoded =
pemalloc(*encoded_len, s->persistent
);
s->Z.next_out = (Bytef *) *encoded;
s->Z.avail_out = *encoded_len;
s->Z.next_out = (Bytef *) *encoded;
s->Z.avail_out = *encoded_len;
@@
-473,7
+480,7
@@
PHP_HTTP_API STATUS _http_encoding_stream_finish(http_encoding_stream *s, char *
*encoded_len -= s->Z.avail_out;
if (s->gzip) {
if (s->Z.avail_out < 8) {
*encoded_len -= s->Z.avail_out;
if (s->gzip) {
if (s->Z.avail_out < 8) {
- *encoded =
erealloc(*encoded, *encoded_len + 8
);
+ *encoded =
perealloc(*encoded, *encoded_len + 8, s->persistent
);
}
(*encoded)[(*encoded_len)++] = (char) (s->crc & 0xFF);
(*encoded)[(*encoded_len)++] = (char) ((s->crc >> 8) & 0xFF);
}
(*encoded)[(*encoded_len)++] = (char) (s->crc & 0xFF);
(*encoded)[(*encoded_len)++] = (char) ((s->crc >> 8) & 0xFF);
@@
-515,6
+522,7
@@
PHP_HTTP_API zend_bool _http_encoding_response_start(size_t content_length TSRML
INIT_PZVAL(&zsupported);
array_init(&zsupported);
add_next_index_stringl(&zsupported, "gzip", lenof("gzip"), 1);
INIT_PZVAL(&zsupported);
array_init(&zsupported);
add_next_index_stringl(&zsupported, "gzip", lenof("gzip"), 1);
+ add_next_index_stringl(&zsupported, "x-gzip", lenof("x-gzip"), 1);
add_next_index_stringl(&zsupported, "deflate", lenof("deflate"), 1);
HTTP_G(send).gzip_encoding = 0;
add_next_index_stringl(&zsupported, "deflate", lenof("deflate"), 1);
HTTP_G(send).gzip_encoding = 0;
@@
-525,7
+533,7
@@
PHP_HTTP_API zend_bool _http_encoding_response_start(size_t content_length TSRML
ulong idx;
if (HASH_KEY_IS_STRING == zend_hash_get_current_key(selected, &encoding, &idx, 0) && encoding) {
ulong idx;
if (HASH_KEY_IS_STRING == zend_hash_get_current_key(selected, &encoding, &idx, 0) && encoding) {
- if (!strcmp(encoding, "gzip")) {
+ if (!strcmp(encoding, "gzip")
|| !strcmp(encoding, "x-gzip")
) {
if (SUCCESS == (hs = http_send_header_string("Content-Encoding: gzip"))) {
HTTP_G(send).gzip_encoding = HTTP_ENCODING_GZIP;
}
if (SUCCESS == (hs = http_send_header_string("Content-Encoding: gzip"))) {
HTTP_G(send).gzip_encoding = HTTP_ENCODING_GZIP;
}