fix bad merge; keys were serialized twice
[m6w6/ext-http] / php_http_encoding.h
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #ifndef PHP_HTTP_ENCODING_H
14 #define PHP_HTTP_ENCODING_H
15
16 #include <zlib.h>
17
18 extern PHP_MINIT_FUNCTION(http_encoding);
19 extern PHP_RINIT_FUNCTION(http_encoding);
20 extern PHP_RSHUTDOWN_FUNCTION(http_encoding);
21
22 #define PHP_HTTP_INFLATE_ROUNDS 100
23
24 #define PHP_HTTP_DEFLATE_BUFFER_SIZE_GUESS(S) \
25 (((size_t) ((double) S * (double) 1.015)) + 10 + 8 + 4 + 1)
26 #define PHP_HTTP_INFLATE_BUFFER_SIZE_GUESS(S) \
27 (((S) + 1) << 3)
28 #define PHP_HTTP_INFLATE_BUFFER_SIZE_ALIGN(S) \
29 ((S) += (S) >> (3))
30
31 #define PHP_HTTP_DEFLATE_BUFFER_SIZE 0x8000
32 #define PHP_HTTP_INFLATE_BUFFER_SIZE 0x1000
33
34 #define PHP_HTTP_DEFLATE_LEVEL_DEF 0x00000000
35 #define PHP_HTTP_DEFLATE_LEVEL_MIN 0x00000001
36 #define PHP_HTTP_DEFLATE_LEVEL_MAX 0x00000009
37 #define PHP_HTTP_DEFLATE_TYPE_ZLIB 0x00000000
38 #define PHP_HTTP_DEFLATE_TYPE_GZIP 0x00000010
39 #define PHP_HTTP_DEFLATE_TYPE_RAW 0x00000020
40 #define PHP_HTTP_DEFLATE_STRATEGY_DEF 0x00000000
41 #define PHP_HTTP_DEFLATE_STRATEGY_FILT 0x00000100
42 #define PHP_HTTP_DEFLATE_STRATEGY_HUFF 0x00000200
43 #define PHP_HTTP_DEFLATE_STRATEGY_RLE 0x00000300
44 #define PHP_HTTP_DEFLATE_STRATEGY_FIXED 0x00000400
45
46 #define PHP_HTTP_DEFLATE_LEVEL_SET(flags, level) \
47 switch (flags & 0xf) \
48 { \
49 default: \
50 if ((flags & 0xf) < 10) { \
51 level = flags & 0xf; \
52 break; \
53 } \
54 case PHP_HTTP_DEFLATE_LEVEL_DEF: \
55 level = Z_DEFAULT_COMPRESSION; \
56 break; \
57 }
58
59 #define PHP_HTTP_DEFLATE_WBITS_SET(flags, wbits) \
60 switch (flags & 0xf0) \
61 { \
62 case PHP_HTTP_DEFLATE_TYPE_GZIP: \
63 wbits = PHP_HTTP_WINDOW_BITS_GZIP; \
64 break; \
65 case PHP_HTTP_DEFLATE_TYPE_RAW: \
66 wbits = PHP_HTTP_WINDOW_BITS_RAW; \
67 break; \
68 default: \
69 wbits = PHP_HTTP_WINDOW_BITS_ZLIB; \
70 break; \
71 }
72
73 #define PHP_HTTP_INFLATE_WBITS_SET(flags, wbits) \
74 if (flags & PHP_HTTP_INFLATE_TYPE_RAW) { \
75 wbits = PHP_HTTP_WINDOW_BITS_RAW; \
76 } else { \
77 wbits = PHP_HTTP_WINDOW_BITS_ANY; \
78 }
79
80 #define PHP_HTTP_DEFLATE_STRATEGY_SET(flags, strategy) \
81 switch (flags & 0xf00) \
82 { \
83 case PHP_HTTP_DEFLATE_STRATEGY_FILT: \
84 strategy = Z_FILTERED; \
85 break; \
86 case PHP_HTTP_DEFLATE_STRATEGY_HUFF: \
87 strategy = Z_HUFFMAN_ONLY; \
88 break; \
89 case PHP_HTTP_DEFLATE_STRATEGY_RLE: \
90 strategy = Z_RLE; \
91 break; \
92 case PHP_HTTP_DEFLATE_STRATEGY_FIXED: \
93 strategy = Z_FIXED; \
94 break; \
95 default: \
96 strategy = Z_DEFAULT_STRATEGY; \
97 break; \
98 }
99
100 #define PHP_HTTP_WINDOW_BITS_ZLIB 0x0000000f
101 #define PHP_HTTP_WINDOW_BITS_GZIP 0x0000001f
102 #define PHP_HTTP_WINDOW_BITS_ANY 0x0000002f
103 #define PHP_HTTP_WINDOW_BITS_RAW -0x000000f
104
105 #ifndef Z_FIXED
106 /* Z_FIXED does not exist prior 1.2.2.2 */
107 # define Z_FIXED 0
108 #endif
109
110 #define PHP_HTTP_INFLATE_TYPE_ZLIB 0x00000000
111 #define PHP_HTTP_INFLATE_TYPE_GZIP 0x00000000
112 #define PHP_HTTP_INFLATE_TYPE_RAW 0x00000001
113
114 #define PHP_HTTP_ENCODING_STREAM_FLUSH_NONE 0x00000000
115 #define PHP_HTTP_ENCODING_STREAM_FLUSH_SYNC 0x00100000
116 #define PHP_HTTP_ENCODING_STREAM_FLUSH_FULL 0x00200000
117
118 #define PHP_HTTP_ENCODING_STREAM_FLUSH_FLAG(f) \
119 (((f) & PHP_HTTP_ENCODING_STREAM_FLUSH_FULL) ? Z_FULL_FLUSH : \
120 (((f) & PHP_HTTP_ENCODING_STREAM_FLUSH_SYNC) ? Z_SYNC_FLUSH : Z_NO_FLUSH))
121
122 #define PHP_HTTP_ENCODING_STREAM_PERSISTENT 0x01000000
123
124 typedef struct php_http_encoding_stream php_http_encoding_stream_t;
125
126 typedef php_http_encoding_stream_t *(*php_http_encoding_stream_init_func_t)(php_http_encoding_stream_t *s);
127 typedef php_http_encoding_stream_t *(*php_http_encoding_stream_copy_func_t)(php_http_encoding_stream_t *from, php_http_encoding_stream_t *to);
128 typedef ZEND_RESULT_CODE (*php_http_encoding_stream_update_func_t)(php_http_encoding_stream_t *s, const char *in_str, size_t in_len, char **out_str, size_t *out_len);
129 typedef ZEND_RESULT_CODE (*php_http_encoding_stream_flush_func_t)(php_http_encoding_stream_t *s, char **out_str, size_t *out_len);
130 typedef zend_bool (*php_http_encoding_stream_done_func_t)(php_http_encoding_stream_t *s);
131 typedef ZEND_RESULT_CODE (*php_http_encoding_stream_finish_func_t)(php_http_encoding_stream_t *s, char **out_str, size_t *out_len);
132 typedef void (*php_http_encoding_stream_dtor_func_t)(php_http_encoding_stream_t *s);
133
134 typedef struct php_http_encoding_stream_ops {
135 php_http_encoding_stream_init_func_t init;
136 php_http_encoding_stream_copy_func_t copy;
137 php_http_encoding_stream_update_func_t update;
138 php_http_encoding_stream_flush_func_t flush;
139 php_http_encoding_stream_done_func_t done;
140 php_http_encoding_stream_finish_func_t finish;
141 php_http_encoding_stream_dtor_func_t dtor;
142 } php_http_encoding_stream_ops_t;
143
144 struct php_http_encoding_stream {
145 unsigned flags;
146 void *ctx;
147 php_http_encoding_stream_ops_t *ops;
148 };
149
150 PHP_HTTP_API php_http_encoding_stream_ops_t *php_http_encoding_stream_get_deflate_ops(void);
151 PHP_HTTP_API php_http_encoding_stream_ops_t *php_http_encoding_stream_get_inflate_ops(void);
152 PHP_HTTP_API php_http_encoding_stream_ops_t *php_http_encoding_stream_get_dechunk_ops(void);
153
154 PHP_HTTP_API php_http_encoding_stream_t *php_http_encoding_stream_init(php_http_encoding_stream_t *s, php_http_encoding_stream_ops_t *ops, unsigned flags);
155 PHP_HTTP_API php_http_encoding_stream_t *php_http_encoding_stream_copy(php_http_encoding_stream_t *from, php_http_encoding_stream_t *to);
156 PHP_HTTP_API ZEND_RESULT_CODE php_http_encoding_stream_reset(php_http_encoding_stream_t **s);
157 PHP_HTTP_API ZEND_RESULT_CODE php_http_encoding_stream_update(php_http_encoding_stream_t *s, const char *in_str, size_t in_len, char **out_str, size_t *out_len);
158 PHP_HTTP_API ZEND_RESULT_CODE php_http_encoding_stream_flush(php_http_encoding_stream_t *s, char **out_str, size_t *len);
159 PHP_HTTP_API zend_bool php_http_encoding_stream_done(php_http_encoding_stream_t *s);
160 PHP_HTTP_API ZEND_RESULT_CODE php_http_encoding_stream_finish(php_http_encoding_stream_t *s, char **out_str, size_t *len);
161 PHP_HTTP_API void php_http_encoding_stream_dtor(php_http_encoding_stream_t *s);
162 PHP_HTTP_API void php_http_encoding_stream_free(php_http_encoding_stream_t **s);
163
164 PHP_HTTP_API const char *php_http_encoding_dechunk(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len);
165 PHP_HTTP_API ZEND_RESULT_CODE php_http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len);
166 PHP_HTTP_API ZEND_RESULT_CODE php_http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len);
167
168 typedef struct php_http_encoding_stream_object {
169 php_http_encoding_stream_t *stream;
170 zend_object zo;
171 } php_http_encoding_stream_object_t;
172
173 PHP_HTTP_API zend_class_entry *php_http_encoding_stream_class_entry;
174
175 zend_object *php_http_encoding_stream_object_new(zend_class_entry *ce);
176 php_http_encoding_stream_object_t *php_http_encoding_stream_object_new_ex(zend_class_entry *ce, php_http_encoding_stream_t *s);
177 zend_object *php_http_encoding_stream_object_clone(zval *object);
178 void php_http_encoding_stream_object_free(zend_object *object);
179
180 PHP_HTTP_API zend_class_entry *php_http_deflate_stream_class_entry;
181 PHP_HTTP_API zend_class_entry *php_http_inflate_stream_class_entry;
182 PHP_HTTP_API zend_class_entry *php_http_dechunk_stream_class_entry;
183
184 #endif
185
186 /*
187 * Local variables:
188 * tab-width: 4
189 * c-basic-offset: 4
190 * End:
191 * vim600: noet sw=4 ts=4 fdm=marker
192 * vim<600: noet sw=4 ts=4
193 */