@@ -36,7 +36,6 @@ static int le_protocols;
36
36
37
37
struct php_user_stream_wrapper {
38
38
char * protoname ;
39
- char * classname ;
40
39
zend_class_entry * ce ;
41
40
php_stream_wrapper wrapper ;
42
41
};
@@ -71,7 +70,6 @@ static void stream_wrapper_dtor(zend_resource *rsrc)
71
70
struct php_user_stream_wrapper * uwrap = (struct php_user_stream_wrapper * )rsrc -> ptr ;
72
71
73
72
efree (uwrap -> protoname );
74
- efree (uwrap -> classname );
75
73
efree (uwrap );
76
74
}
77
75
@@ -375,7 +373,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *
375
373
ZVAL_COPY (& stream -> wrapperdata , & us -> object );
376
374
} else {
377
375
php_stream_wrapper_log_error (wrapper , options , "\"%s::" USERSTREAM_OPEN "\" call failed" ,
378
- us -> wrapper -> classname );
376
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
379
377
}
380
378
381
379
/* destroy everything else */
@@ -444,7 +442,7 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char
444
442
ZVAL_COPY (& stream -> wrapperdata , & us -> object );
445
443
} else {
446
444
php_stream_wrapper_log_error (wrapper , options , "\"%s::" USERSTREAM_DIR_OPEN "\" call failed" ,
447
- us -> wrapper -> classname );
445
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
448
446
}
449
447
450
448
/* destroy everything else */
@@ -468,38 +466,33 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char
468
466
/* {{{ Registers a custom URL protocol handler class */
469
467
PHP_FUNCTION (stream_wrapper_register )
470
468
{
471
- zend_string * protocol , * classname ;
472
- struct php_user_stream_wrapper * uwrap ;
469
+ zend_string * protocol ;
470
+ struct php_user_stream_wrapper * uwrap = ( struct php_user_stream_wrapper * ) ecalloc ( 1 , sizeof ( * uwrap )); ;
473
471
zend_resource * rsrc ;
474
472
zend_long flags = 0 ;
475
473
476
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "SS|l" , & protocol , & classname , & flags ) == FAILURE ) {
474
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "SC|l" , & protocol , & uwrap -> ce , & flags ) == FAILURE ) {
475
+ efree (uwrap );
477
476
RETURN_THROWS ();
478
477
}
479
478
480
- uwrap = (struct php_user_stream_wrapper * )ecalloc (1 , sizeof (* uwrap ));
481
479
uwrap -> protoname = estrndup (ZSTR_VAL (protocol ), ZSTR_LEN (protocol ));
482
- uwrap -> classname = estrndup (ZSTR_VAL (classname ), ZSTR_LEN (classname ));
483
480
uwrap -> wrapper .wops = & user_stream_wops ;
484
481
uwrap -> wrapper .abstract = uwrap ;
485
482
uwrap -> wrapper .is_url = ((flags & PHP_STREAM_IS_URL ) != 0 );
486
483
487
484
rsrc = zend_register_resource (uwrap , le_protocols );
488
485
489
- if ((uwrap -> ce = zend_lookup_class (classname )) != NULL ) {
490
- if (php_register_url_stream_wrapper_volatile (protocol , & uwrap -> wrapper ) == SUCCESS ) {
491
- RETURN_TRUE ;
492
- } else {
493
- /* We failed. But why? */
494
- if (zend_hash_exists (php_stream_get_url_stream_wrappers_hash (), protocol )) {
495
- php_error_docref (NULL , E_WARNING , "Protocol %s:// is already defined." , ZSTR_VAL (protocol ));
496
- } else {
497
- /* Hash doesn't exist so it must have been an invalid protocol scheme */
498
- php_error_docref (NULL , E_WARNING , "Invalid protocol scheme specified. Unable to register wrapper class %s to %s://" , ZSTR_VAL (classname ), ZSTR_VAL (protocol ));
499
- }
500
- }
486
+ if (php_register_url_stream_wrapper_volatile (protocol , & uwrap -> wrapper ) == SUCCESS ) {
487
+ RETURN_TRUE ;
488
+ }
489
+
490
+ /* We failed. But why? */
491
+ if (zend_hash_exists (php_stream_get_url_stream_wrappers_hash (), protocol )) {
492
+ php_error_docref (NULL , E_WARNING , "Protocol %s:// is already defined." , ZSTR_VAL (protocol ));
501
493
} else {
502
- php_error_docref (NULL , E_WARNING , "Class '%s' is undefined" , ZSTR_VAL (classname ));
494
+ /* Hash doesn't exist so it must have been an invalid protocol scheme */
495
+ php_error_docref (NULL , E_WARNING , "Invalid protocol scheme specified. Unable to register wrapper class %s to %s://" , ZSTR_VAL (uwrap -> ce -> name ), ZSTR_VAL (protocol ));
503
496
}
504
497
505
498
zend_list_delete (rsrc );
@@ -596,14 +589,14 @@ static ssize_t php_userstreamop_write(php_stream *stream, const char *buf, size_
596
589
}
597
590
} else {
598
591
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_WRITE " is not implemented!" ,
599
- us -> wrapper -> classname );
592
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
600
593
didwrite = -1 ;
601
594
}
602
595
603
596
/* don't allow strange buffer overruns due to bogus return */
604
597
if (didwrite > 0 && didwrite > count ) {
605
598
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_WRITE " wrote " ZEND_LONG_FMT " bytes more data than requested (" ZEND_LONG_FMT " written, " ZEND_LONG_FMT " max)" ,
606
- us -> wrapper -> classname ,
599
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) ,
607
600
(zend_long )(didwrite - count ), (zend_long )didwrite , (zend_long )count );
608
601
didwrite = count ;
609
602
}
@@ -643,7 +636,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
643
636
644
637
if (call_result == FAILURE ) {
645
638
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_READ " is not implemented!" ,
646
- us -> wrapper -> classname );
639
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
647
640
return -1 ;
648
641
}
649
642
@@ -659,7 +652,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
659
652
if (didread > 0 ) {
660
653
if (didread > count ) {
661
654
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_READ " - read " ZEND_LONG_FMT " bytes more data than requested (" ZEND_LONG_FMT " read, " ZEND_LONG_FMT " max) - excess data will be lost" ,
662
- us -> wrapper -> classname , (zend_long )(didread - count ), (zend_long )didread , (zend_long )count );
655
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) , (zend_long )(didread - count ), (zend_long )didread , (zend_long )count );
663
656
didread = count ;
664
657
}
665
658
memcpy (buf , Z_STRVAL (retval ), didread );
@@ -688,7 +681,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
688
681
} else if (call_result == FAILURE ) {
689
682
php_error_docref (NULL , E_WARNING ,
690
683
"%s::" USERSTREAM_EOF " is not implemented! Assuming EOF" ,
691
- us -> wrapper -> classname );
684
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
692
685
693
686
stream -> eof = 1 ;
694
687
}
@@ -812,7 +805,7 @@ static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int when
812
805
* newoffs = Z_LVAL (retval );
813
806
ret = 0 ;
814
807
} else if (call_result == FAILURE ) {
815
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_TELL " is not implemented!" , us -> wrapper -> classname );
808
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_TELL " is not implemented!" , ZSTR_VAL ( us -> wrapper -> ce -> name ) );
816
809
ret = -1 ;
817
810
} else {
818
811
ret = -1 ;
@@ -884,7 +877,7 @@ static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb)
884
877
} else {
885
878
if (call_result == FAILURE ) {
886
879
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_STAT " is not implemented!" ,
887
- us -> wrapper -> classname );
880
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
888
881
}
889
882
}
890
883
@@ -913,7 +906,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
913
906
ret = PHP_STREAM_OPTION_RETURN_ERR ;
914
907
php_error_docref (NULL , E_WARNING ,
915
908
"%s::" USERSTREAM_EOF " is not implemented! Assuming EOF" ,
916
- us -> wrapper -> classname );
909
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
917
910
}
918
911
zval_ptr_dtor (& retval );
919
912
zval_ptr_dtor (& func_name );
@@ -954,7 +947,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
954
947
ret = PHP_STREAM_OPTION_RETURN_OK ;
955
948
} else {
956
949
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_LOCK " is not implemented!" ,
957
- us -> wrapper -> classname );
950
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
958
951
ret = PHP_STREAM_OPTION_RETURN_ERR ;
959
952
}
960
953
}
@@ -993,12 +986,12 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
993
986
} else {
994
987
php_error_docref (NULL , E_WARNING ,
995
988
"%s::" USERSTREAM_TRUNCATE " did not return a boolean!" ,
996
- us -> wrapper -> classname );
989
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
997
990
}
998
991
} else {
999
992
php_error_docref (NULL , E_WARNING ,
1000
993
"%s::" USERSTREAM_TRUNCATE " is not implemented!" ,
1001
- us -> wrapper -> classname );
994
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1002
995
}
1003
996
zval_ptr_dtor (& retval );
1004
997
zval_ptr_dtor (& args [0 ]);
@@ -1053,7 +1046,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
1053
1046
1054
1047
if (call_result == FAILURE ) {
1055
1048
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_SET_OPTION " is not implemented!" ,
1056
- us -> wrapper -> classname );
1049
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1057
1050
ret = PHP_STREAM_OPTION_RETURN_ERR ;
1058
1051
} else if (zend_is_true (& retval )) {
1059
1052
ret = PHP_STREAM_OPTION_RETURN_OK ;
@@ -1104,7 +1097,7 @@ static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
1104
1097
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1105
1098
ret = (Z_TYPE (zretval ) == IS_TRUE );
1106
1099
} else if (call_result == FAILURE ) {
1107
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_UNLINK " is not implemented!" , uwrap -> classname );
1100
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_UNLINK " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1108
1101
}
1109
1102
1110
1103
/* clean up */
@@ -1148,7 +1141,7 @@ static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
1148
1141
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1149
1142
ret = (Z_TYPE (zretval ) == IS_TRUE );
1150
1143
} else if (call_result == FAILURE ) {
1151
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_RENAME " is not implemented!" , uwrap -> classname );
1144
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_RENAME " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1152
1145
}
1153
1146
1154
1147
/* clean up */
@@ -1194,7 +1187,7 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int
1194
1187
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1195
1188
ret = (Z_TYPE (zretval ) == IS_TRUE );
1196
1189
} else if (call_result == FAILURE ) {
1197
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_MKDIR " is not implemented!" , uwrap -> classname );
1190
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_MKDIR " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1198
1191
}
1199
1192
1200
1193
/* clean up */
@@ -1240,7 +1233,7 @@ static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url,
1240
1233
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1241
1234
ret = (Z_TYPE (zretval ) == IS_TRUE );
1242
1235
} else if (call_result == FAILURE ) {
1243
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_RMDIR " is not implemented!" , uwrap -> classname );
1236
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_RMDIR " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1244
1237
}
1245
1238
1246
1239
/* clean up */
@@ -1310,7 +1303,7 @@ static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, i
1310
1303
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1311
1304
ret = Z_TYPE (zretval ) == IS_TRUE ;
1312
1305
} else if (call_result == FAILURE ) {
1313
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_METADATA " is not implemented!" , uwrap -> classname );
1306
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_METADATA " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1314
1307
}
1315
1308
1316
1309
/* clean up */
@@ -1361,7 +1354,7 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, i
1361
1354
} else {
1362
1355
if (call_result == FAILURE ) {
1363
1356
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_STATURL " is not implemented!" ,
1364
- uwrap -> classname );
1357
+ ZSTR_VAL ( uwrap -> ce -> name ) );
1365
1358
}
1366
1359
}
1367
1360
@@ -1405,7 +1398,7 @@ static ssize_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t co
1405
1398
didread = sizeof (php_stream_dirent );
1406
1399
} else if (call_result == FAILURE ) {
1407
1400
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_DIR_READ " is not implemented!" ,
1408
- us -> wrapper -> classname );
1401
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1409
1402
}
1410
1403
1411
1404
zval_ptr_dtor (& retval );
@@ -1491,7 +1484,7 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
1491
1484
do {
1492
1485
if (call_result == FAILURE ) {
1493
1486
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_CAST " is not implemented!" ,
1494
- us -> wrapper -> classname );
1487
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1495
1488
break ;
1496
1489
}
1497
1490
if (!zend_is_true (& retval )) {
@@ -1500,12 +1493,12 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
1500
1493
php_stream_from_zval_no_verify (intstream , & retval );
1501
1494
if (!intstream ) {
1502
1495
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_CAST " must return a stream resource" ,
1503
- us -> wrapper -> classname );
1496
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1504
1497
break ;
1505
1498
}
1506
1499
if (intstream == stream ) {
1507
1500
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_CAST " must not return itself" ,
1508
- us -> wrapper -> classname );
1501
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1509
1502
intstream = NULL ;
1510
1503
break ;
1511
1504
}
0 commit comments