#include "php_http.h"
+#include <zlib.h>
+
static inline int eol_match(char **line, int *eol_len)
{
char *ptr = *line;
static inline int php_http_inflate_rounds(z_stream *Z, int flush, char **buf, size_t *len)
{
int status = 0, round = 0;
- php_http_buffer buffer;
+ php_http_buffer_t buffer;
*buf = NULL;
*len = 0;
PHP_HTTP_API STATUS php_http_encoding_stream_flush(php_http_encoding_stream_t *s, char **out_str, size_t *out_len)
{
if (!s->ops->flush) {
+ *out_str = NULL;
+ *out_len = 0;
return SUCCESS;
}
return s->ops->flush(s, out_str, out_len);
PHP_HTTP_API STATUS php_http_encoding_stream_finish(php_http_encoding_stream_t *s, char **out_str, size_t *out_len)
{
if (!s->ops->finish) {
+ *out_str = NULL;
+ *out_len = 0;
return SUCCESS;
}
return s->ops->finish(s, out_str, out_len);
}
struct dechunk_ctx {
- php_http_buffer buffer;
+ php_http_buffer_t buffer;
ulong hexlen;
unsigned zeroed:1;
};
/* append input to buffer */
php_http_buffer_append(PHP_HTTP_BUFFER(ctx->opaque), data, data_len);
-
+
retry_raw_inflate:
ctx->next_in = (Bytef *) PHP_HTTP_BUFFER_VAL(ctx->opaque);
ctx->avail_in = PHP_HTTP_BUFFER_LEN(ctx->opaque);
static STATUS dechunk_update(php_http_encoding_stream_t *s, const char *data, size_t data_len, char **decoded, size_t *decoded_len)
{
- php_http_buffer tmp;
+ php_http_buffer_t tmp;
struct dechunk_ctx *ctx = s->ctx;
TSRMLS_FETCH_FROM_CTX(s->ts);
if (ctx->zeroed) {
+ php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Dechunk encoding stream has already reached the end of chunked input");
return FAILURE;
}
- if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(&ctx->buffer, data, data_len)) {
- return FAILURE;
- }
- if (!php_http_buffer_fix(&ctx->buffer)) {
+ if ((PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(&ctx->buffer, data, data_len)) || !php_http_buffer_fix(&ctx->buffer)) {
+ /* OOM */
return FAILURE;
}
/* if strtoul() stops at the beginning of the buffered data
there's domething oddly wrong, i.e. bad input */
if (stop == PHP_HTTP_BUFFER_VAL(&ctx->buffer)) {
+ php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Failed to parse chunk len from '%.*s'", MIN(16, ctx->buffer.used), ctx->buffer.data);
php_http_buffer_dtor(&tmp);
return FAILURE;
}
z_streamp ctx = s->ctx;
if (ctx->opaque) {
- php_http_buffer_free((php_http_buffer **) &ctx->opaque);
+ php_http_buffer_free((php_http_buffer_t **) &ctx->opaque);
}
deflateEnd(ctx);
pefree(ctx, (s->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT));
z_streamp ctx = s->ctx;
if (ctx->opaque) {
- php_http_buffer_free((php_http_buffer **) &ctx->opaque);
+ php_http_buffer_free((php_http_buffer_t **) &ctx->opaque);
}
inflateEnd(ctx);
pefree(ctx, (s->flags & PHP_HTTP_ENCODING_STREAM_PERSISTENT));
PHP_METHOD(HttpEncodingStream, __construct)
{
- with_error_handling(EH_THROW, PHP_HTTP_EX_CE(runtime)) {
+ with_error_handling(EH_THROW, php_http_exception_class_entry) {
long flags = 0;
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags)) {
- with_error_handling(EH_THROW, PHP_HTTP_EX_CE(encoding)) {
+ with_error_handling(EH_THROW, php_http_exception_class_entry) {
php_http_encoding_stream_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->stream) {