php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
php_stream_filter_api.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Wez Furlong <wez@thebrainroom.com> |
14 | With suggestions from: |
15 | Moriyoshi Koizumi <moriyoshi@at.wakwak.com> |
16 | Sara Golemon <pollita@php.net> |
17 +----------------------------------------------------------------------+
18 */
19
20/* The filter API works on the principle of "Bucket-Brigades". This is
21 * partially inspired by the Apache 2 method of doing things, although
22 * it is intentionally a light-weight implementation.
23 *
24 * Each stream can have a chain of filters for reading and another for writing.
25 *
26 * When data is written to the stream, it is placed into a bucket and placed at
27 * the start of the input brigade.
28 *
29 * The first filter in the chain is invoked on the brigade and (depending on
30 * it's return value), the next filter is invoked and so on.
31 * */
32
33#define PHP_STREAM_FILTER_READ 0x0001
34#define PHP_STREAM_FILTER_WRITE 0x0002
35#define PHP_STREAM_FILTER_ALL (PHP_STREAM_FILTER_READ | PHP_STREAM_FILTER_WRITE)
36
39
43
44 char *buf;
45 size_t buflen;
46 /* if non-zero, buf should be pefreed when the bucket is destroyed */
47 uint8_t own_buf;
49
50 /* destroy this struct when refcount falls to zero */
52};
53
57
58typedef enum {
59 PSFS_ERR_FATAL, /* error in data stream */
60 PSFS_FEED_ME, /* filter needs more data; stop processing chain until more is available */
61 PSFS_PASS_ON /* filter generated output buckets; pass them on to next in chain */
63
64/* Buckets API. */
66PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, size_t buflen, uint8_t own_buf, uint8_t buf_persistent);
69#define php_stream_bucket_addref(bucket) (bucket)->refcount++
75
76#define PSFS_FLAG_NORMAL 0 /* regular read/write */
77#define PSFS_FLAG_FLUSH_INC 1 /* an incremental flush */
78#define PSFS_FLAG_FLUSH_CLOSE 2 /* final flush prior to closing */
79
80typedef struct _php_stream_filter_ops {
81
83 php_stream *stream,
84 php_stream_filter *thisfilter,
85 php_stream_bucket_brigade *buckets_in,
86 php_stream_bucket_brigade *buckets_out,
87 size_t *bytes_consumed,
88 int flags
89 );
90
91 void (*dtor)(php_stream_filter *thisfilter);
92
93 const char *label;
94
96
103
106 zval abstract; /* for use by filter implementation */
110
111 /* link into stream and chain */
113
114 /* buffered buckets */
116
117 /* filters are auto_registered when they're applied */
119};
120
121/* stack filter onto a stream */
127PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish);
132#define php_stream_filter_alloc(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_CC)
133#define php_stream_filter_alloc_rel(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_REL_CC)
134#define php_stream_filter_prepend(chain, filter) _php_stream_filter_prepend((chain), (filter))
135#define php_stream_filter_append(chain, filter) _php_stream_filter_append((chain), (filter))
136#define php_stream_filter_flush(filter, finish) _php_stream_filter_flush((filter), (finish))
137
138#define php_stream_is_filtered(stream) ((stream)->readfilters.head || (stream)->writefilters.head)
139
141 php_stream_filter *(*create_filter)(const char *filtername, zval *filterparams, uint8_t persistent);
143
146PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern);
148PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, uint8_t persistent);
ffi persistent
Definition ffi.c:3633
zend_ffi_ctype_name_buf buf
Definition ffi.c:4685
const php_stream_filter_factory * factory
Definition filters.c:1900
PHPAPI php_stream_bucket * php_stream_bucket_new(php_stream *stream, char *buf, size_t buflen, uint8_t own_buf, uint8_t buf_persistent)
Definition filter.c:71
PHPAPI void php_stream_bucket_delref(php_stream_bucket *bucket)
Definition filter.c:150
PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter)
Definition filter.c:385
PHPAPI int php_stream_filter_register_factory(const char *filterpattern, const php_stream_filter_factory *factory)
Definition filter.c:43
PHPAPI void _php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter)
Definition filter.c:301
PHPAPI int php_stream_filter_register_factory_volatile(zend_string *filterpattern, const php_stream_filter_factory *factory)
Definition filter.c:58
PHPAPI php_stream_filter * php_stream_filter_create(const char *filtername, zval *filterparams, uint8_t persistent)
Definition filter.c:220
PHPAPI int php_stream_bucket_split(php_stream_bucket *in, php_stream_bucket **left, php_stream_bucket **right, size_t length)
Definition filter.c:128
PHPAPI void php_stream_filter_free(php_stream_filter *filter)
Definition filter.c:278
PHPAPI php_stream_filter * _php_stream_filter_alloc(const php_stream_filter_ops *fops, void *abstract, uint8_t persistent STREAMS_DC)
Definition filter.c:264
PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern)
Definition filter.c:52
PHPAPI int php_stream_filter_prepend_ex(php_stream_filter_chain *chain, php_stream_filter *filter)
Definition filter.c:285
PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish)
Definition filter.c:398
PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_stream_filter *filter)
Definition filter.c:306
PHPAPI php_stream_filter * php_stream_filter_remove(php_stream_filter *filter, int call_dtor)
Definition filter.c:483
lu_byte right
Definition minilua.c:4267
lu_byte left
Definition minilua.c:4266
#define PHPAPI
Definition php.h:71
PHPAPI php_stream_bucket * php_stream_bucket_make_writeable(php_stream_bucket *bucket)
Definition filter.c:104
PHPAPI void php_stream_bucket_append(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket)
Definition filter.c:174
PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket)
Definition filter.c:192
struct _php_stream_filter_chain php_stream_filter_chain
PHPAPI void php_stream_bucket_prepend(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket)
Definition filter.c:160
struct _php_stream_filter_ops php_stream_filter_ops
php_stream_filter_status_t
@ PSFS_ERR_FATAL
struct _php_stream_filter_factory php_stream_filter_factory
struct _php_stream_bucket php_stream_bucket
struct _php_stream_bucket_brigade php_stream_bucket_brigade
struct _php_stream php_stream
Definition php_streams.h:96
struct _php_stream_filter php_stream_filter
Definition php_streams.h:99
#define STREAMS_DC
Definition php_streams.h:53
php_stream_bucket * next
php_stream_bucket * prev
php_stream_bucket_brigade * brigade
php_stream_filter_status_t(* filter)(php_stream *stream, php_stream_filter *thisfilter, php_stream_bucket_brigade *buckets_in, php_stream_bucket_brigade *buckets_out, size_t *bytes_consumed, int flags)
void(* dtor)(php_stream_filter *thisfilter)
const php_stream_filter_ops * fops
php_stream_bucket_brigade buffer
php_stream_filter_chain * chain
php_stream_filter * prev
php_stream_filter * next
struct _zval_struct zval
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
struct _zend_string zend_string
#define END_EXTERN_C()
#define BEGIN_EXTERN_C()
struct _zend_resource zend_resource
Definition zend_types.h:99