@@ -151,14 +151,14 @@ PHPAPI int php_start_ob_buffer(zval *output_handler, uint chunk_size, zend_bool
151
151
return FAILURE ;
152
152
}
153
153
if (chunk_size > 0 ) {
154
- if (chunk_size == 1 ) {
154
+ if (chunk_size == 1 ) {
155
155
chunk_size = 4096 ;
156
156
}
157
- initial_size = (chunk_size * 3 / 2 );
158
- block_size = chunk_size / 2 ;
157
+ initial_size = (chunk_size * 3 / 2 );
158
+ block_size = chunk_size / 2 ;
159
159
} else {
160
- initial_size = 40 * 1024 ;
161
- block_size = 10 * 1024 ;
160
+ initial_size = 40 * 1024 ;
161
+ block_size = 10 * 1024 ;
162
162
}
163
163
return php_ob_init (initial_size , block_size , output_handler , chunk_size , erase TSRMLS_CC );
164
164
}
@@ -195,9 +195,10 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush TSRMLS
195
195
php_ob_buffer * prev_ob_buffer_p = NULL ;
196
196
php_ob_buffer orig_ob_buffer ;
197
197
198
- if (OG (ob_nesting_level )== 0 ) {
198
+ if (OG (ob_nesting_level ) == 0 ) {
199
199
return ;
200
200
}
201
+
201
202
status = 0 ;
202
203
if (!OG (active_ob_buffer ).status & PHP_OUTPUT_HANDLER_START ) {
203
204
/* our first call */
@@ -229,25 +230,25 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush TSRMLS
229
230
230
231
ALLOC_INIT_ZVAL (orig_buffer );
231
232
ZVAL_STRINGL (orig_buffer , OG (active_ob_buffer ).buffer , OG (active_ob_buffer ).text_length , 1 );
232
- orig_buffer -> refcount = 2 ; /* don't let call_user_function() destroy our buffer */
233
- orig_buffer -> is_ref = 1 ;
233
+ orig_buffer -> refcount = 2 ; /* don't let call_user_function() destroy our buffer */
234
+ orig_buffer -> is_ref = 1 ;
234
235
235
236
ALLOC_INIT_ZVAL (z_status );
236
237
ZVAL_LONG (z_status , status );
237
238
238
239
params [0 ] = & orig_buffer ;
239
240
params [1 ] = & z_status ;
240
241
OG (ob_lock ) = 1 ;
241
- if (call_user_function_ex (CG (function_table ), NULL , OG (active_ob_buffer ).output_handler , & alternate_buffer , 2 , params , 1 , NULL TSRMLS_CC )== SUCCESS ) {
242
- if (!(Z_TYPE_P (alternate_buffer )== IS_BOOL && Z_BVAL_P (alternate_buffer )== 0 )) {
242
+ if (call_user_function_ex (CG (function_table ), NULL , OG (active_ob_buffer ).output_handler , & alternate_buffer , 2 , params , 1 , NULL TSRMLS_CC ) == SUCCESS ) {
243
+ if (!(Z_TYPE_P (alternate_buffer ) == IS_BOOL && Z_BVAL_P (alternate_buffer ) == 0 )) {
243
244
convert_to_string_ex (& alternate_buffer );
244
245
final_buffer = Z_STRVAL_P (alternate_buffer );
245
246
final_buffer_length = Z_STRLEN_P (alternate_buffer );
246
247
}
247
248
}
248
249
OG (ob_lock ) = 0 ;
249
250
zval_ptr_dtor (& OG (active_ob_buffer ).output_handler );
250
- orig_buffer -> refcount -= 2 ;
251
+ orig_buffer -> refcount -= 2 ;
251
252
if (orig_buffer -> refcount <= 0 ) { /* free the zval */
252
253
zval_dtor (orig_buffer );
253
254
FREE_ZVAL (orig_buffer );
@@ -260,7 +261,7 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush TSRMLS
260
261
final_buffer_length = OG (active_ob_buffer ).text_length ;
261
262
}
262
263
263
- if (OG (ob_nesting_level )== 1 ) { /* end buffering */
264
+ if (OG (ob_nesting_level ) == 1 ) { /* end buffering */
264
265
if (SG (headers_sent ) && !SG (request_info ).headers_only ) {
265
266
OG (php_body_write ) = php_ub_body_write_no_header ;
266
267
} else {
@@ -281,12 +282,12 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush TSRMLS
281
282
to_be_destroyed_handled_output [1 ] = OG (active_ob_buffer ).internal_output_handler_buffer ;
282
283
}
283
284
}
284
- if (OG (ob_nesting_level )> 1 ) { /* restore previous buffer */
285
+ if (OG (ob_nesting_level ) > 1 ) { /* restore previous buffer */
285
286
zend_stack_top (& OG (ob_buffers ), (void * * ) & prev_ob_buffer_p );
286
287
orig_ob_buffer = OG (active_ob_buffer );
287
288
OG (active_ob_buffer ) = * prev_ob_buffer_p ;
288
289
zend_stack_del_top (& OG (ob_buffers ));
289
- if (!just_flush && OG (ob_nesting_level )== 2 ) { /* destroy the stack */
290
+ if (!just_flush && OG (ob_nesting_level ) == 2 ) { /* destroy the stack */
290
291
zend_stack_destroy (& OG (ob_buffers ));
291
292
}
292
293
}
@@ -331,7 +332,7 @@ PHPAPI void php_end_ob_buffer(zend_bool send_buffer, zend_bool just_flush TSRMLS
331
332
* End output buffering (all buffers) */
332
333
PHPAPI void php_end_ob_buffers (zend_bool send_buffer TSRMLS_DC )
333
334
{
334
- while (OG (ob_nesting_level )!= 0 ) {
335
+ while (OG (ob_nesting_level ) != 0 ) {
335
336
php_end_ob_buffer (send_buffer , 0 TSRMLS_CC );
336
337
}
337
338
}
@@ -341,23 +342,23 @@ PHPAPI void php_end_ob_buffers(zend_bool send_buffer TSRMLS_DC)
341
342
*/
342
343
PHPAPI void php_start_implicit_flush (TSRMLS_D )
343
344
{
344
- OG (implicit_flush )= 1 ;
345
+ OG (implicit_flush ) = 1 ;
345
346
}
346
347
/* }}} */
347
348
348
349
/* {{{ php_end_implicit_flush
349
350
*/
350
351
PHPAPI void php_end_implicit_flush (TSRMLS_D )
351
352
{
352
- OG (implicit_flush )= 0 ;
353
+ OG (implicit_flush ) = 0 ;
353
354
}
354
355
/* }}} */
355
356
356
357
/* {{{ php_ob_set_internal_handler
357
358
*/
358
359
PHPAPI void php_ob_set_internal_handler (php_output_handler_func_t internal_output_handler , uint buffer_size , char * handler_name , zend_bool erase TSRMLS_DC )
359
360
{
360
- if (OG (ob_nesting_level )== 0 || OG (active_ob_buffer ).internal_output_handler || strcmp (OG (active_ob_buffer ).handler_name , OB_DEFAULT_HANDLER_NAME )) {
361
+ if (OG (ob_nesting_level ) == 0 || OG (active_ob_buffer ).internal_output_handler || strcmp (OG (active_ob_buffer ).handler_name , OB_DEFAULT_HANDLER_NAME )) {
361
362
php_start_ob_buffer (NULL , buffer_size , erase TSRMLS_CC );
362
363
}
363
364
@@ -382,10 +383,10 @@ static inline void php_ob_allocate(TSRMLS_D)
382
383
{
383
384
if (OG (active_ob_buffer ).size < OG (active_ob_buffer ).text_length ) {
384
385
while (OG (active_ob_buffer ).size <= OG (active_ob_buffer ).text_length ) {
385
- OG (active_ob_buffer ).size += OG (active_ob_buffer ).block_size ;
386
+ OG (active_ob_buffer ).size += OG (active_ob_buffer ).block_size ;
386
387
}
387
388
388
- OG (active_ob_buffer ).buffer = (char * ) erealloc (OG (active_ob_buffer ).buffer , OG (active_ob_buffer ).size + 1 );
389
+ OG (active_ob_buffer ).buffer = (char * ) erealloc (OG (active_ob_buffer ).buffer , OG (active_ob_buffer ).size + 1 );
389
390
}
390
391
}
391
392
/* }}} */
@@ -407,27 +408,27 @@ PHPAPI int php_ob_init_conflict(char *handler_new, char *handler_set TSRMLS_DC)
407
408
*/
408
409
static int php_ob_init_named (uint initial_size , uint block_size , char * handler_name , zval * output_handler , uint chunk_size , zend_bool erase TSRMLS_DC )
409
410
{
410
- if (OG (ob_nesting_level )> 0 ) {
411
+ if (OG (ob_nesting_level ) > 0 ) {
411
412
#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB )
412
413
if (!strncmp (handler_name , "ob_gzhandler" , sizeof ("ob_gzhandler" )) && php_ob_gzhandler_check (TSRMLS_C )) {
413
414
return FAILURE ;
414
415
}
415
416
#endif
416
- if (OG (ob_nesting_level )== 1 ) { /* initialize stack */
417
+ if (OG (ob_nesting_level ) == 1 ) { /* initialize stack */
417
418
zend_stack_init (& OG (ob_buffers ));
418
419
}
419
420
zend_stack_push (& OG (ob_buffers ), & OG (active_ob_buffer ), sizeof (php_ob_buffer ));
420
421
}
421
422
OG (ob_nesting_level )++ ;
422
423
OG (active_ob_buffer ).block_size = block_size ;
423
424
OG (active_ob_buffer ).size = initial_size ;
424
- OG (active_ob_buffer ).buffer = (char * ) emalloc (initial_size + 1 );
425
+ OG (active_ob_buffer ).buffer = (char * ) emalloc (initial_size + 1 );
425
426
OG (active_ob_buffer ).text_length = 0 ;
426
427
OG (active_ob_buffer ).output_handler = output_handler ;
427
428
OG (active_ob_buffer ).chunk_size = chunk_size ;
428
429
OG (active_ob_buffer ).status = 0 ;
429
430
OG (active_ob_buffer ).internal_output_handler = NULL ;
430
- OG (active_ob_buffer ).handler_name = estrdup (handler_name && handler_name [0 ]? handler_name : OB_DEFAULT_HANDLER_NAME );
431
+ OG (active_ob_buffer ).handler_name = estrdup (handler_name && handler_name [0 ] ? handler_name : OB_DEFAULT_HANDLER_NAME );
431
432
OG (active_ob_buffer ).erase = erase ;
432
433
OG (php_body_write ) = php_b_body_write ;
433
434
return SUCCESS ;
@@ -470,7 +471,7 @@ static int php_ob_init(uint initial_size, uint block_size, zval *output_handler,
470
471
zval_dtor (handler_zval );
471
472
FREE_ZVAL (handler_zval );
472
473
}
473
- handler_name += len + 1 ;
474
+ handler_name += len + 1 ;
474
475
efree (next_handler_name );
475
476
}
476
477
handler_zval = php_ob_handler_from_string (handler_name TSRMLS_CC );
@@ -489,7 +490,7 @@ static int php_ob_init(uint initial_size, uint block_size, zval *output_handler,
489
490
efree (handler_name );
490
491
/* init all array elements recursively */
491
492
zend_hash_internal_pointer_reset_ex (Z_ARRVAL_P (output_handler ), & pos );
492
- while (zend_hash_get_current_data_ex (Z_ARRVAL_P (output_handler ), (void * * )& tmp , & pos ) == SUCCESS ) {
493
+ while (zend_hash_get_current_data_ex (Z_ARRVAL_P (output_handler ), (void * * ) & tmp , & pos ) == SUCCESS ) {
493
494
result = php_ob_init (initial_size , block_size , * tmp , chunk_size , erase TSRMLS_CC );
494
495
zend_hash_move_forward_ex (Z_ARRVAL_P (output_handler ), & pos );
495
496
}
@@ -518,14 +519,14 @@ static int php_ob_list_each(php_ob_buffer *ob_buffer, zval *ob_handler_array)
518
519
*/
519
520
PHP_FUNCTION (ob_list_handlers )
520
521
{
521
- if (ZEND_NUM_ARGS ()!= 0 ) {
522
+ if (ZEND_NUM_ARGS () != 0 ) {
522
523
ZEND_WRONG_PARAM_COUNT ();
523
524
RETURN_FALSE ;
524
525
}
525
526
526
527
array_init (return_value );
527
528
if (OG (ob_nesting_level )) {
528
- if (OG (ob_nesting_level )> 1 ) {
529
+ if (OG (ob_nesting_level ) > 1 ) {
529
530
zend_stack_apply_with_argument (& OG (ob_buffers ), ZEND_STACK_APPLY_BOTTOMUP , (int (* )(void * element , void * )) php_ob_list_each , return_value );
530
531
}
531
532
php_ob_list_each (& OG (active_ob_buffer ), return_value );
@@ -557,7 +558,7 @@ PHPAPI int php_ob_handler_used(char *handler_name TSRMLS_DC)
557
558
if (!strcmp (OG (active_ob_buffer ).handler_name , handler_name )) {
558
559
return 1 ;
559
560
}
560
- if (OG (ob_nesting_level )> 1 ) {
561
+ if (OG (ob_nesting_level ) > 1 ) {
561
562
zend_stack_apply_with_argument (& OG (ob_buffers ), ZEND_STACK_APPLY_BOTTOMUP , (int (* )(void * element , void * )) php_ob_handler_used_each , & tmp );
562
563
}
563
564
}
@@ -572,17 +573,16 @@ static inline void php_ob_append(const char *text, uint text_length TSRMLS_DC)
572
573
char * target ;
573
574
int original_ob_text_length ;
574
575
575
- original_ob_text_length = OG (active_ob_buffer ).text_length ;
576
+ original_ob_text_length = OG (active_ob_buffer ).text_length ;
576
577
OG (active_ob_buffer ).text_length = OG (active_ob_buffer ).text_length + text_length ;
577
578
578
579
php_ob_allocate (TSRMLS_C );
579
580
target = OG (active_ob_buffer ).buffer + original_ob_text_length ;
580
581
memcpy (target , text , text_length );
581
- target [text_length ]= 0 ;
582
+ target [text_length ] = 0 ;
582
583
583
584
/* If implicit_flush is On or chunked buffering, send contents to next buffer and return. */
584
- if (OG (active_ob_buffer ).chunk_size
585
- && OG (active_ob_buffer ).text_length >= OG (active_ob_buffer ).chunk_size ) {
585
+ if (OG (active_ob_buffer ).chunk_size && OG (active_ob_buffer ).text_length >= OG (active_ob_buffer ).chunk_size ) {
586
586
zval * output_handler = OG (active_ob_buffer ).output_handler ;
587
587
588
588
if (output_handler ) {
@@ -620,7 +620,7 @@ static inline void php_ob_prepend(const char *text, uint text_length)
620
620
* Return the current output buffer */
621
621
PHPAPI int php_ob_get_buffer (zval * p TSRMLS_DC )
622
622
{
623
- if (OG (ob_nesting_level )== 0 ) {
623
+ if (OG (ob_nesting_level ) == 0 ) {
624
624
return FAILURE ;
625
625
}
626
626
ZVAL_STRINGL (p , OG (active_ob_buffer ).buffer , OG (active_ob_buffer ).text_length , 1 );
@@ -716,12 +716,14 @@ PHP_FUNCTION(ob_start)
716
716
RETURN_FALSE ;
717
717
}
718
718
719
- if (chunk_size < 0 )
719
+ if (chunk_size < 0 ) {
720
720
chunk_size = 0 ;
721
+ }
721
722
722
- if (php_start_ob_buffer (output_handler , chunk_size , erase TSRMLS_CC )== FAILURE ) {
723
+ if (php_start_ob_buffer (output_handler , chunk_size , erase TSRMLS_CC ) == FAILURE ) {
723
724
RETURN_FALSE ;
724
725
}
726
+
725
727
RETURN_TRUE ;
726
728
}
727
729
/* }}} */
@@ -821,9 +823,10 @@ PHP_FUNCTION(ob_get_flush)
821
823
}
822
824
823
825
/* get contents */
824
- if (php_ob_get_buffer (return_value TSRMLS_CC )== FAILURE ) {
826
+ if (php_ob_get_buffer (return_value TSRMLS_CC ) == FAILURE ) {
825
827
RETURN_FALSE ;
826
828
}
829
+
827
830
/* error checks */
828
831
if (!OG (ob_nesting_level )) {
829
832
php_error_docref ("ref.outcontrol" TSRMLS_CC , E_NOTICE , "failed to delete and flush buffer. No buffer to delete or flush." );
@@ -833,6 +836,7 @@ PHP_FUNCTION(ob_get_flush)
833
836
php_error_docref ("ref.outcontrol" TSRMLS_CC , E_NOTICE , "failed to delete buffer %s." , OG (active_ob_buffer ).handler_name );
834
837
RETURN_FALSE ;
835
838
}
839
+
836
840
/* flush */
837
841
php_end_ob_buffer (1 , 0 TSRMLS_CC );
838
842
}
@@ -846,9 +850,10 @@ PHP_FUNCTION(ob_get_clean)
846
850
ZEND_WRONG_PARAM_COUNT ();
847
851
848
852
/* get contents */
849
- if (php_ob_get_buffer (return_value TSRMLS_CC )== FAILURE ) {
853
+ if (php_ob_get_buffer (return_value TSRMLS_CC ) == FAILURE ) {
850
854
RETURN_FALSE ;
851
855
}
856
+
852
857
/* error checks */
853
858
if (!OG (ob_nesting_level )) {
854
859
php_error_docref ("ref.outcontrol" TSRMLS_CC , E_NOTICE , "failed to delete buffer. No buffer to delete." );
@@ -858,6 +863,7 @@ PHP_FUNCTION(ob_get_clean)
858
863
php_error_docref ("ref.outcontrol" TSRMLS_CC , E_NOTICE , "failed to delete buffer %s." , OG (active_ob_buffer ).handler_name );
859
864
RETURN_FALSE ;
860
865
}
866
+
861
867
/* delete buffer */
862
868
php_end_ob_buffer (0 , 0 TSRMLS_CC );
863
869
}
@@ -871,7 +877,7 @@ PHP_FUNCTION(ob_get_contents)
871
877
ZEND_WRONG_PARAM_COUNT ();
872
878
}
873
879
874
- if (php_ob_get_buffer (return_value TSRMLS_CC )== FAILURE ) {
880
+ if (php_ob_get_buffer (return_value TSRMLS_CC ) == FAILURE ) {
875
881
RETURN_FALSE ;
876
882
}
877
883
}
@@ -885,7 +891,7 @@ PHP_FUNCTION(ob_get_level)
885
891
ZEND_WRONG_PARAM_COUNT ();
886
892
}
887
893
888
- RETURN_LONG (OG (ob_nesting_level ));
894
+ RETURN_LONG (OG (ob_nesting_level ));
889
895
}
890
896
/* }}} */
891
897
@@ -897,7 +903,7 @@ PHP_FUNCTION(ob_get_length)
897
903
ZEND_WRONG_PARAM_COUNT ();
898
904
}
899
905
900
- if (php_ob_get_length (return_value TSRMLS_CC )== FAILURE ) {
906
+ if (php_ob_get_length (return_value TSRMLS_CC ) == FAILURE ) {
901
907
RETURN_FALSE ;
902
908
}
903
909
}
@@ -940,19 +946,20 @@ PHP_FUNCTION(ob_get_status)
940
946
int argc = ZEND_NUM_ARGS ();
941
947
zend_bool full_status = 0 ;
942
948
943
- if (zend_parse_parameters (argc TSRMLS_CC , "|b" , & full_status ) == FAILURE )
949
+ if (zend_parse_parameters (argc TSRMLS_CC , "|b" , & full_status ) == FAILURE ) {
944
950
RETURN_FALSE ;
951
+ }
945
952
946
953
array_init (return_value );
947
954
948
955
if (full_status ) {
949
- if (OG (ob_nesting_level )> 1 ) {
956
+ if (OG (ob_nesting_level ) > 1 ) {
950
957
zend_stack_apply_with_argument (& OG (ob_buffers ), ZEND_STACK_APPLY_BOTTOMUP , (int (* )(void * elem , void * ))php_ob_buffer_status , return_value );
951
958
}
952
- if (OG (ob_nesting_level )> 0 && php_ob_buffer_status (& OG (active_ob_buffer ), return_value )== FAILURE ) {
959
+ if (OG (ob_nesting_level ) > 0 && php_ob_buffer_status (& OG (active_ob_buffer ), return_value ) == FAILURE ) {
953
960
RETURN_FALSE ;
954
961
}
955
- } else if (OG (ob_nesting_level )> 0 ) {
962
+ } else if (OG (ob_nesting_level ) > 0 ) {
956
963
add_assoc_long (return_value , "level" , OG (ob_nesting_level ));
957
964
if (OG (active_ob_buffer ).internal_output_handler ) {
958
965
add_assoc_long (return_value , "type" , PHP_OUTPUT_HANDLER_INTERNAL );
@@ -974,12 +981,12 @@ PHP_FUNCTION(ob_implicit_flush)
974
981
zval * * zv_flag ;
975
982
int flag ;
976
983
977
- switch (ZEND_NUM_ARGS ()) {
984
+ switch (ZEND_NUM_ARGS ()) {
978
985
case 0 :
979
986
flag = 1 ;
980
987
break ;
981
988
case 1 :
982
- if (zend_get_parameters_ex (1 , & zv_flag )== FAILURE ) {
989
+ if (zend_get_parameters_ex (1 , & zv_flag ) == FAILURE ) {
983
990
RETURN_FALSE ;
984
991
}
985
992
convert_to_long_ex (zv_flag );
0 commit comments