2
+----------------------------------------------------------------------+
4
+----------------------------------------------------------------------+
5
| Copyright (c) 1997-2004 The PHP Group |
6
+----------------------------------------------------------------------+
7
| This source file is subject to version 3.0 of the PHP license, |
8
| that is bundled with this package in the file LICENSE, and is |
9
| available through the world-wide-web at the following url: |
10
| http://www.php.net/license/3_0.txt. |
11
| If you did not receive a copy of the PHP license and are unable to |
12
| obtain it through the world-wide-web, please send a note to |
13
| license@php.net so we can mail you a copy immediately. |
14
+----------------------------------------------------------------------+
15
| Author: Wez Furlong <wez@thebrainroom.com> |
16
| With suggestions from: |
17
| Moriyoshi Koizumi <moriyoshi@at.wakwak.com> |
18
| Sara Golemon <pollita@php.net> |
19
+----------------------------------------------------------------------+
22
/* $Id: php_stream_filter_api.h,v 1.10 2004/06/21 21:08:05 pollita Exp $ */
24
/* The filter API works on the principle of "Bucket-Brigades". This is
25
* partially inspired by the Apache 2 method of doing things, although
26
* it is intentially a light-weight implementation.
28
* Each stream can have a chain of filters for reading and another for writing.
30
* When data is written to the stream, is is placed into a bucket and placed at
31
* the start of the input brigade.
33
* The first filter in the chain is invoked on the brigade and (depending on
34
* it's return value), the next filter is invoked and so on.
37
#define PHP_STREAM_FILTER_READ 0x0001
38
#define PHP_STREAM_FILTER_WRITE 0x0002
39
#define PHP_STREAM_FILTER_ALL (PHP_STREAM_FILTER_READ | PHP_STREAM_FILTER_WRITE)
41
typedef struct _php_stream_bucket php_stream_bucket;
42
typedef struct _php_stream_bucket_brigade php_stream_bucket_brigade;
44
struct _php_stream_bucket {
45
php_stream_bucket *next, *prev;
46
php_stream_bucket_brigade *brigade;
50
/* if non-zero, buf should be pefreed when the bucket is destroyed */
54
/* destroy this struct when refcount falls to zero */
58
struct _php_stream_bucket_brigade {
59
php_stream_bucket *head, *tail;
63
PSFS_ERR_FATAL, /* error in data stream */
64
PSFS_FEED_ME, /* filter needs more data; stop processing chain until more is available */
65
PSFS_PASS_ON, /* filter generated output buckets; pass them on to next in chain */
66
} php_stream_filter_status_t;
70
PHPAPI php_stream_bucket *php_stream_bucket_new(php_stream *stream, char *buf, size_t buflen, int own_buf, int buf_persistent TSRMLS_DC);
71
PHPAPI int php_stream_bucket_split(php_stream_bucket *in, php_stream_bucket **left, php_stream_bucket **right, size_t length TSRMLS_DC);
72
PHPAPI void php_stream_bucket_delref(php_stream_bucket *bucket TSRMLS_DC);
73
#define php_stream_bucket_addref(bucket) (bucket)->refcount++
74
PHPAPI void php_stream_bucket_prepend(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket TSRMLS_DC);
75
PHPAPI void php_stream_bucket_append(php_stream_bucket_brigade *brigade, php_stream_bucket *bucket TSRMLS_DC);
76
PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket TSRMLS_DC);
77
PHPAPI php_stream_bucket *php_stream_bucket_make_writeable(php_stream_bucket *bucket TSRMLS_DC);
80
#define PSFS_FLAG_NORMAL 0 /* regular read/write */
81
#define PSFS_FLAG_FLUSH_INC 1 /* an incremental flush */
82
#define PSFS_FLAG_FLUSH_CLOSE 2 /* final flush prior to closing */
84
typedef struct _php_stream_filter_ops {
86
php_stream_filter_status_t (*filter)(
88
php_stream_filter *thisfilter,
89
php_stream_bucket_brigade *buckets_in,
90
php_stream_bucket_brigade *buckets_out,
91
size_t *bytes_consumed,
95
void (*dtor)(php_stream_filter *thisfilter TSRMLS_DC);
99
} php_stream_filter_ops;
101
typedef struct _php_stream_filter_chain {
102
php_stream_filter *head, *tail;
106
} php_stream_filter_chain;
108
struct _php_stream_filter {
109
php_stream_filter_ops *fops;
110
void *abstract; /* for use by filter implementation */
111
php_stream_filter *next;
112
php_stream_filter *prev;
115
/* link into stream and chain */
116
php_stream_filter_chain *chain;
118
/* buffered buckets */
119
php_stream_bucket_brigade buffer;
122
/* stack filter onto a stream */
124
PHPAPI void _php_stream_filter_prepend(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC);
125
PHPAPI void _php_stream_filter_append(php_stream_filter_chain *chain, php_stream_filter *filter TSRMLS_DC);
126
PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, int call_dtor TSRMLS_DC);
127
PHPAPI void php_stream_filter_free(php_stream_filter *filter TSRMLS_DC);
128
PHPAPI php_stream_filter *_php_stream_filter_alloc(php_stream_filter_ops *fops, void *abstract, int persistent STREAMS_DC TSRMLS_DC);
130
#define php_stream_filter_alloc(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_CC TSRMLS_CC)
131
#define php_stream_filter_alloc_rel(fops, thisptr, persistent) _php_stream_filter_alloc((fops), (thisptr), (persistent) STREAMS_REL_CC TSRMLS_CC)
132
#define php_stream_filter_prepend(chain, filter) _php_stream_filter_prepend((chain), (filter) TSRMLS_CC)
133
#define php_stream_filter_append(chain, filter) _php_stream_filter_append((chain), (filter) TSRMLS_CC)
135
#define php_stream_is_filtered(stream) ((stream)->readfilters.head || (stream)->writefilters.head)
137
typedef struct _php_stream_filter_factory {
138
php_stream_filter *(*create_filter)(const char *filtername, zval *filterparams, int persistent TSRMLS_DC);
139
} php_stream_filter_factory;
142
PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory TSRMLS_DC);
143
PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern TSRMLS_DC);
144
PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory TSRMLS_DC);
145
PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval *filterparams, int persistent TSRMLS_DC);
153
* vim600: sw=4 ts=4 fdm=marker