@@ -947,6 +947,48 @@ static zend_class_entry *php_brotli_compress_context_register_class(void)
947
947
return class_entry ;
948
948
}
949
949
950
+ /* Brotli UnCompress Context */
951
+ zend_class_entry * php_brotli_uncompress_context_ce ;
952
+ static zend_object_handlers php_brotli_uncompress_context_object_handlers ;
953
+
954
+ static zend_object *
955
+ php_brotli_uncompress_context_create_object (zend_class_entry * class_type )
956
+ {
957
+ return php_brotli_context_create_object (
958
+ class_type ,
959
+ & php_brotli_uncompress_context_object_handlers );
960
+ }
961
+
962
+ static zend_function *
963
+ php_brotli_uncompress_context_get_constructor (zend_object * object )
964
+ {
965
+ zend_throw_error (NULL ,
966
+ "Cannot directly construct Brotli\\UnCompress\\Context, "
967
+ "use brotli_uncompress_init() instead" );
968
+ return NULL ;
969
+ }
970
+
971
+ static zend_class_entry * php_brotli_uncompress_context_register_class (void )
972
+ {
973
+ zend_class_entry ce , * class_entry ;
974
+
975
+ INIT_NS_CLASS_ENTRY (ce , "Brotli\\UnCompress" , "Context" , NULL );
976
+ #if PHP_VERSION_ID >= 80000
977
+ class_entry = zend_register_internal_class_ex (& ce , NULL );
978
+ #if PHP_VERSION_ID >= 80100
979
+ class_entry -> ce_flags |= ZEND_ACC_FINAL |ZEND_ACC_NO_DYNAMIC_PROPERTIES |ZEND_ACC_NOT_SERIALIZABLE ;
980
+ #else
981
+ class_entry -> ce_flags |= ZEND_ACC_FINAL |ZEND_ACC_NO_DYNAMIC_PROPERTIES ;
982
+ #endif
983
+ #else
984
+ ce .create_object = php_brotli_uncompress_context_create_object ;
985
+ class_entry = zend_register_internal_class (& ce );
986
+ class_entry -> ce_flags |= ZEND_ACC_FINAL ;
987
+ #endif
988
+
989
+ return class_entry ;
990
+ }
991
+
950
992
ZEND_MINIT_FUNCTION (brotli )
951
993
{
952
994
ZEND_INIT_MODULE_GLOBALS (brotli , php_brotli_init_globals , NULL );
@@ -1010,6 +1052,34 @@ ZEND_MINIT_FUNCTION(brotli)
1010
1052
= zend_objects_not_comparable ;
1011
1053
#endif
1012
1054
1055
+ php_brotli_uncompress_context_ce
1056
+ = php_brotli_uncompress_context_register_class ();
1057
+ #if PHP_VERSION_ID >= 80000
1058
+ php_brotli_uncompress_context_ce -> create_object
1059
+ = php_brotli_uncompress_context_create_object ;
1060
+ #if PHP_VERSION_ID >= 80300
1061
+ php_brotli_uncompress_context_ce -> default_object_handlers
1062
+ = & php_brotli_uncompress_context_object_handlers ;
1063
+ #endif
1064
+ #if PHP_VERSION_ID < 80100
1065
+ php_brotli_uncompress_context_ce -> serialize = zend_class_serialize_deny ;
1066
+ php_brotli_uncompress_context_ce -> unserialize = zend_class_unserialize_deny ;
1067
+ #endif
1068
+ #endif
1069
+ memcpy (& php_brotli_uncompress_context_object_handlers ,
1070
+ & std_object_handlers , sizeof (zend_object_handlers ));
1071
+ php_brotli_uncompress_context_object_handlers .offset
1072
+ = XtOffsetOf (php_brotli_context , std );
1073
+ php_brotli_uncompress_context_object_handlers .free_obj
1074
+ = php_brotli_context_free_obj ;
1075
+ php_brotli_uncompress_context_object_handlers .get_constructor
1076
+ = php_brotli_uncompress_context_get_constructor ;
1077
+ php_brotli_uncompress_context_object_handlers .clone_obj = NULL ;
1078
+ #if PHP_VERSION_ID >= 80000
1079
+ php_brotli_uncompress_context_object_handlers .compare
1080
+ = zend_objects_not_comparable ;
1081
+ #endif
1082
+
1013
1083
REGISTER_INI_ENTRIES ();
1014
1084
1015
1085
php_register_url_stream_wrapper (STREAM_NAME ,
@@ -1323,42 +1393,51 @@ static ZEND_FUNCTION(brotli_uncompress)
1323
1393
1324
1394
static ZEND_FUNCTION (brotli_uncompress_init )
1325
1395
{
1326
- php_brotli_state_context * ctx ;
1327
-
1328
1396
if (zend_parse_parameters_none () == FAILURE ) {
1329
1397
RETURN_FALSE ;
1330
1398
}
1331
1399
1332
- ctx = php_brotli_state_init ( );
1400
+ PHP_BROTLI_CONTEXT_OBJ_INIT_OF_CLASS ( php_brotli_uncompress_context_ce );
1333
1401
1334
- if (php_brotli_decoder_create (& ctx -> decoder ) != SUCCESS ) {
1402
+ if (php_brotli_decoder_create (& ctx -> state . decoder ) != SUCCESS ) {
1335
1403
php_error_docref (NULL , E_WARNING ,
1336
1404
"Brotli incremental uncompress init failed" );
1337
1405
RETURN_FALSE ;
1338
1406
}
1339
-
1340
- RETURN_RES (zend_register_resource (ctx , le_state ));
1341
1407
}
1342
1408
1343
1409
static ZEND_FUNCTION (brotli_uncompress_add )
1344
1410
{
1345
1411
zval * res ;
1346
- php_brotli_state_context * ctx ;
1412
+ php_brotli_context * ctx ;
1347
1413
size_t buffer_size ;
1348
1414
zend_long mode = BROTLI_OPERATION_FLUSH ;
1415
+ #if PHP_VERSION_ID >= 80000
1416
+ zend_object * obj ;
1417
+ #else
1418
+ zval * obj ;
1419
+ #endif
1349
1420
char * in_buf ;
1350
1421
size_t in_size ;
1351
1422
smart_string out = {0 };
1352
1423
1353
1424
ZEND_PARSE_PARAMETERS_START (2 , 3 )
1354
- Z_PARAM_RESOURCE (res )
1425
+ #if PHP_VERSION_ID >= 80000
1426
+ Z_PARAM_OBJ_OF_CLASS (obj , php_brotli_uncompress_context_ce )
1427
+ #else
1428
+ Z_PARAM_OBJECT_OF_CLASS (obj , php_brotli_uncompress_context_ce )
1429
+ #endif
1355
1430
Z_PARAM_STRING (in_buf , in_size )
1356
1431
Z_PARAM_OPTIONAL
1357
1432
Z_PARAM_LONG (mode )
1358
1433
ZEND_PARSE_PARAMETERS_END ();
1359
1434
1360
- ctx = zend_fetch_resource (Z_RES_P (res ), NULL , le_state );
1361
- if (ctx == NULL || ctx -> decoder == NULL) {
1435
+ #if PHP_VERSION_ID >= 80000
1436
+ ctx = php_brotli_context_from_obj (obj );
1437
+ #else
1438
+ ctx = php_brotli_context_from_obj (Z_OBJ_P (obj ));
1439
+ #endif
1440
+ if (ctx == NULL || ctx -> state .decoder == NULL ) {
1362
1441
php_error_docref (NULL , E_WARNING ,
1363
1442
"Brotli incremental uncompress resource failed" );
1364
1443
RETURN_FALSE ;
@@ -1371,18 +1450,20 @@ static ZEND_FUNCTION(brotli_uncompress_add)
1371
1450
buffer_size = PHP_BROTLI_BUFFER_SIZE ;
1372
1451
uint8_t * buffer = (uint8_t * )emalloc (buffer_size );
1373
1452
1374
- const uint8_t * next_in = (const uint8_t * )in_buf ;
1375
- size_t available_in = in_size ;
1453
+ ctx -> next_in = (const uint8_t * )in_buf ;
1454
+ ctx -> available_in = in_size ;
1376
1455
1377
1456
BrotliDecoderResult result = BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT ;
1378
1457
while (result == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT ) {
1379
- size_t available_out = buffer_size ;
1380
- uint8_t * next_out = buffer ;
1381
- result = BrotliDecoderDecompressStream (ctx -> decoder ,
1382
- & available_in , & next_in ,
1383
- & available_out , & next_out ,
1458
+ ctx -> available_out = buffer_size ;
1459
+ ctx -> next_out = buffer ;
1460
+ result = BrotliDecoderDecompressStream (ctx -> state .decoder ,
1461
+ & ctx -> available_in ,
1462
+ & ctx -> next_in ,
1463
+ & ctx -> available_out ,
1464
+ & ctx -> next_out ,
1384
1465
0 );
1385
- size_t buffer_used = buffer_size - available_out ;
1466
+ size_t buffer_used = buffer_size - ctx -> available_out ;
1386
1467
if (buffer_used ) {
1387
1468
smart_string_appendl (& out , buffer , buffer_used );
1388
1469
}
0 commit comments