@@ -86,41 +86,6 @@ static zend_function_entry brotli_functions[] = {
86
86
87
87
static const size_t PHP_BROTLI_BUFFER_SIZE = 1 << 19 ;
88
88
89
- static int php_brotli_encoder_create (BrotliEncoderState * * encoder ,
90
- long quality , int lgwin , long mode )
91
- {
92
- * encoder = BrotliEncoderCreateInstance (NULL , NULL , NULL );
93
- if (!* encoder ) {
94
- return FAILURE ;
95
- }
96
-
97
- if (quality < BROTLI_MIN_QUALITY || quality > BROTLI_MAX_QUALITY ) {
98
- php_error_docref (NULL , E_WARNING ,
99
- "brotli: compression level (%ld) "
100
- "must be within %d..%d" ,
101
- (long )quality , BROTLI_MIN_QUALITY , BROTLI_MAX_QUALITY );
102
- quality = BROTLI_DEFAULT_QUALITY ;
103
- }
104
- if (lgwin == 0 ) {
105
- lgwin = BROTLI_DEFAULT_WINDOW ;
106
- }
107
- if (mode != BROTLI_MODE_GENERIC &&
108
- mode != BROTLI_MODE_TEXT &&
109
- mode != BROTLI_MODE_FONT ) {
110
- php_error_docref (NULL , E_WARNING ,
111
- "brotli: compression mode (%ld) must be %d, %d, %d" ,
112
- (long )mode , BROTLI_MODE_GENERIC , BROTLI_MODE_TEXT ,
113
- BROTLI_MODE_FONT );
114
- mode = BROTLI_MODE_GENERIC ;
115
- }
116
-
117
- BrotliEncoderSetParameter (* encoder , BROTLI_PARAM_QUALITY , quality );
118
- BrotliEncoderSetParameter (* encoder , BROTLI_PARAM_LGWIN , lgwin );
119
- BrotliEncoderSetParameter (* encoder , BROTLI_PARAM_MODE , mode );
120
-
121
- return SUCCESS ;
122
- }
123
-
124
89
static int php_brotli_decoder_create (BrotliDecoderState * * decoder )
125
90
{
126
91
* decoder = BrotliDecoderCreateInstance (NULL , NULL , NULL );
@@ -153,6 +118,41 @@ static void php_brotli_context_init(php_brotli_context *ctx)
153
118
ctx -> output = NULL ;
154
119
}
155
120
121
+ static int php_brotli_context_create_encoder (php_brotli_context * ctx ,
122
+ long quality , int lgwin , long mode )
123
+ {
124
+ ctx -> encoder = BrotliEncoderCreateInstance (NULL , NULL , NULL );
125
+ if (!ctx -> encoder ) {
126
+ return FAILURE ;
127
+ }
128
+
129
+ if (quality < BROTLI_MIN_QUALITY || quality > BROTLI_MAX_QUALITY ) {
130
+ php_error_docref (NULL , E_WARNING ,
131
+ "brotli: compression level (%ld) "
132
+ "must be within %d..%d" ,
133
+ (long )quality , BROTLI_MIN_QUALITY , BROTLI_MAX_QUALITY );
134
+ quality = BROTLI_DEFAULT_QUALITY ;
135
+ }
136
+ if (lgwin == 0 ) {
137
+ lgwin = BROTLI_DEFAULT_WINDOW ;
138
+ }
139
+ if (mode != BROTLI_MODE_GENERIC &&
140
+ mode != BROTLI_MODE_TEXT &&
141
+ mode != BROTLI_MODE_FONT ) {
142
+ php_error_docref (NULL , E_WARNING ,
143
+ "brotli: compression mode (%ld) must be %d, %d, %d" ,
144
+ (long )mode , BROTLI_MODE_GENERIC , BROTLI_MODE_TEXT ,
145
+ BROTLI_MODE_FONT );
146
+ mode = BROTLI_MODE_GENERIC ;
147
+ }
148
+
149
+ BrotliEncoderSetParameter (ctx -> encoder , BROTLI_PARAM_QUALITY , quality );
150
+ BrotliEncoderSetParameter (ctx -> encoder , BROTLI_PARAM_LGWIN , lgwin );
151
+ BrotliEncoderSetParameter (ctx -> encoder , BROTLI_PARAM_MODE , mode );
152
+
153
+ return SUCCESS ;
154
+ }
155
+
156
156
static void php_brotli_context_close (php_brotli_context * ctx )
157
157
{
158
158
if (ctx -> encoder ) {
@@ -228,8 +228,7 @@ static int php_brotli_output_handler(void **handler_context,
228
228
}
229
229
230
230
if (output_context -> op & PHP_OUTPUT_HANDLER_START ) {
231
- if (php_brotli_encoder_create (& ctx -> encoder ,
232
- quality , 0 , 0 ) != SUCCESS ) {
231
+ if (php_brotli_context_create_encoder (ctx , quality , 0 , 0 ) != SUCCESS ) {
233
232
return FAILURE ;
234
233
}
235
234
}
@@ -301,8 +300,8 @@ static int php_brotli_output_handler(void **handler_context,
301
300
return SUCCESS ;
302
301
} else {
303
302
// restart
304
- if (php_brotli_encoder_create ( & ctx -> encoder ,
305
- quality , 0 , 0 ) != SUCCESS ) {
303
+ if (php_brotli_context_create_encoder ( ctx ,
304
+ quality , 0 , 0 ) != SUCCESS ) {
306
305
return FAILURE ;
307
306
}
308
307
}
@@ -778,8 +777,8 @@ php_stream_brotli_opener(
778
777
779
778
/* File */
780
779
if (compress ) {
781
- if (php_brotli_encoder_create (& self -> ctx . encoder ,
782
- level , 0 , 0 ) != SUCCESS ) {
780
+ if (php_brotli_context_create_encoder (& self -> ctx ,
781
+ level , 0 , 0 ) != SUCCESS ) {
783
782
php_error_docref (NULL , E_WARNING ,
784
783
"brotli: compression context failed" );
785
784
php_stream_close (self -> stream );
@@ -1181,8 +1180,7 @@ static ZEND_FUNCTION(brotli_compress_init)
1181
1180
1182
1181
PHP_BROTLI_CONTEXT_OBJ_INIT_OF_CLASS (php_brotli_compress_context_ce );
1183
1182
1184
- if (php_brotli_encoder_create (& ctx -> encoder ,
1185
- quality , 0 , mode ) != SUCCESS ) {
1183
+ if (php_brotli_context_create_encoder (ctx , quality , 0 , mode ) != SUCCESS ) {
1186
1184
zval_ptr_dtor (return_value );
1187
1185
php_error_docref (NULL , E_WARNING ,
1188
1186
"Brotli incremental compress init failed" );
0 commit comments