/*
- +----------------------------------------------------------------------+
- | PECL :: http |
- +----------------------------------------------------------------------+
- | This source file is subject to version 3.0 of the PHP license, that |
- | is bundled with this package in the file LICENSE, and is available |
- | through the world-wide-web at http://www.php.net/license/3_0.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
- +----------------------------------------------------------------------+
+ +--------------------------------------------------------------------+
+ | PECL :: http |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted provided that the conditions mentioned |
+ | in the accompanying LICENSE file are met. |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2004-2005, Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-#include "php.h"
-#include "php_http_std_defs.h"
-#include "php_http_api.h"
-#include "php_http_filter_api.h"
+#include "php_http.h"
-#include "phpstr/phpstr.h"
+#ifdef ZEND_ENGINE_2
#include "php_streams.h"
+#include "php_http_api.h"
+#include "php_http_filter_api.h"
+
+PHP_MINIT_FUNCTION(http_filter)
+{
+ php_stream_filter_register_factory("http.*", &http_filter_factory TSRMLS_CC);
+ return SUCCESS;
+}
/*
- * TODO: allow use with persistent streams
- */
+ -
+*/
typedef struct {
phpstr buffer;
ulong hexlen;
} http_filter_buffer;
-#define PHP_STREAM_FILTER_OP_FILTER_PARAMS \
+#define HTTP_FILTER_PARAMS \
php_stream *stream, \
php_stream_filter *this, \
php_stream_bucket_brigade *buckets_in, \
php_stream_bucket_brigade *buckets_out, \
size_t *bytes_consumed, int flags \
TSRMLS_DC
-#define PHP_STREAM_FILTER_OP_FILTER(function) \
- static php_stream_filter_status_t function(PHP_STREAM_FILTER_OP_FILTER_PARAMS)
+#define HTTP_FILTER_OP(filter) \
+ http_filter_op_ ##filter
+#define HTTP_FILTER_OPS(filter) \
+ php_stream_filter_ops HTTP_FILTER_OP(filter)
+#define HTTP_FILTER_DTOR(filter) \
+ http_filter_ ##filter## _dtor
+#define HTTP_FILTER_DESTRUCTOR(filter) \
+ void HTTP_FILTER_DTOR(filter)(php_stream_filter *this TSRMLS_DC)
+#define HTTP_FILTER_FUNC(filter) \
+ http_filter_ ##filter
+#define HTTP_FILTER_FUNCTION(filter) \
+ php_stream_filter_status_t HTTP_FILTER_FUNC(filter)(HTTP_FILTER_PARAMS)
#define NEW_BUCKET(data, length) \
{ \
php_stream_bucket_append(buckets_out, __buck TSRMLS_CC); \
}
-PHP_STREAM_FILTER_OP_FILTER(http_filter_chunked_decode)
+static HTTP_FILTER_FUNCTION(chunked_decode)
{
int out_avail = 0;
php_stream_bucket *ptr, *nxt;
*bytes_consumed += ptr->buflen;
}
- phpstr_append(PHPSTR(buffer), ptr->buf, ptr->buflen);
+ if ((size_t) -1 == phpstr_append(PHPSTR(buffer), ptr->buf, ptr->buflen)) {
+ return PSFS_ERR_FATAL;
+ }
+
php_stream_bucket_unlink(ptr TSRMLS_CC);
php_stream_bucket_delref(ptr TSRMLS_CC);
-
}
}
- phpstr_fix(PHPSTR(buffer));
+ if (!phpstr_fix(PHPSTR(buffer))) {
+ return PSFS_ERR_FATAL;
+ }
/* we have data in our buffer */
while (PHPSTR_LEN(buffer)) {
/* waiting for less data now */
buffer->hexlen -= PHPSTR_LEN(buffer);
- /* no more buffered data (breaks loop) */
+ /* no more buffered data */
phpstr_reset(PHPSTR(buffer));
+ /* break */
}
/* we have too less data and don't need to flush */
phpstr_cut(PHPSTR(buffer), 0, buffer->hexlen);
/* reset hexlen */
buffer->hexlen = 0;
+ /* continue */
}
}
/* we need eol, so we can be sure we have all hex digits */
phpstr_fix(PHPSTR(buffer));
- if (eolstr = http_locate_eol(PHPSTR_VAL(buffer), &eollen)) {
+ if ((eolstr = http_locate_eol(PHPSTR_VAL(buffer), &eollen))) {
char *stop = NULL;
/* read in chunk size */
phpstr_cut(PHPSTR(buffer), 0, eolstr + eollen - PHPSTR_VAL(buffer));
/* buffer->hexlen is 0 now or contains the size of the next chunk */
/* continue */
+ } else {
+ /* we have not enough data buffered to read in chunk size */
+ break;
}
}
/* break */
return out_avail ? PSFS_PASS_ON : PSFS_FEED_ME;
}
-static void http_filter_chunked_decode_dtor(php_stream_filter *this TSRMLS_DC)
+static HTTP_FILTER_DESTRUCTOR(chunked_decode)
{
http_filter_buffer *b = (http_filter_buffer *) (this->abstract);
pefree(b, this->is_persistent);
}
-PHP_STREAM_FILTER_OP_FILTER(http_filter_chunked_encode)
+static HTTP_FILTER_FUNCTION(chunked_encode)
{
int out_avail = 0;
php_stream_bucket *ptr, *nxt;
/* pass through */
NEW_BUCKET(PHPSTR_VAL(&buf), PHPSTR_LEN(&buf));
/* reset */
- PHPSTR_LEN(&buf) = 0;
+ phpstr_reset(&buf);
php_stream_bucket_unlink(ptr TSRMLS_CC);
php_stream_bucket_delref(ptr TSRMLS_CC);
return out_avail ? PSFS_PASS_ON : PSFS_FEED_ME;
}
-static php_stream_filter_ops http_filter_ops_chunked_decode = {
- http_filter_chunked_decode,
- http_filter_chunked_decode_dtor,
+static HTTP_FILTER_OPS(chunked_decode) = {
+ HTTP_FILTER_FUNC(chunked_decode),
+ HTTP_FILTER_DTOR(chunked_decode),
"http.chunked_decode"
};
-static php_stream_filter_ops http_filter_ops_chunked_encode = {
- http_filter_chunked_encode,
+static HTTP_FILTER_OPS(chunked_encode) = {
+ HTTP_FILTER_FUNC(chunked_encode),
NULL,
"http.chunked_encode"
};
if (!strcasecmp(name, "http.chunked_decode")) {
http_filter_buffer *b = NULL;
- /* FIXXME: allow usage with persistent streams */
- if (p) {
- return NULL;
- }
-
- if (b = pecalloc(1, sizeof(http_filter_buffer), p)) {
- phpstr_init(PHPSTR(b));
- if (!(f = php_stream_filter_alloc(&http_filter_ops_chunked_decode, b, p))) {
+ if ((b = pecalloc(1, sizeof(http_filter_buffer), p))) {
+ phpstr_init_ex(PHPSTR(b), 4096, p ? PHPSTR_INIT_PERSISTENT : 0);
+ if (!(f = php_stream_filter_alloc(&HTTP_FILTER_OP(chunked_decode), b, p))) {
pefree(b, p);
}
}
} else
if (!strcasecmp(name, "http.chunked_encode")) {
- f = php_stream_filter_alloc(&http_filter_ops_chunked_encode, NULL, p);
+ f = php_stream_filter_alloc(&HTTP_FILTER_OP(chunked_encode), NULL, p);
}
return f;
http_filter_create
};
-PHP_MINIT_FUNCTION(http_filter)
-{
- php_stream_filter_register_factory("http.*", &http_filter_factory TSRMLS_CC);
- return SUCCESS;
-}
+#endif /* ZEND_ENGINE_2 */
/*
* Local variables:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
-