@@ -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
@@ -395,7 +393,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *
395
393
ZVAL_COPY (& stream -> wrapperdata , & us -> object );
396
394
} else {
397
395
php_stream_wrapper_log_error (wrapper , options , "\"%s::" USERSTREAM_OPEN "\" call failed" ,
398
- us -> wrapper -> classname );
396
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
399
397
}
400
398
401
399
/* destroy everything else */
@@ -464,7 +462,7 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char
464
462
ZVAL_COPY (& stream -> wrapperdata , & us -> object );
465
463
} else {
466
464
php_stream_wrapper_log_error (wrapper , options , "\"%s::" USERSTREAM_DIR_OPEN "\" call failed" ,
467
- us -> wrapper -> classname );
465
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
468
466
}
469
467
470
468
/* destroy everything else */
@@ -488,38 +486,33 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char
488
486
/* {{{ Registers a custom URL protocol handler class */
489
487
PHP_FUNCTION (stream_wrapper_register )
490
488
{
491
- zend_string * protocol , * classname ;
492
- struct php_user_stream_wrapper * uwrap ;
489
+ zend_string * protocol ;
490
+ struct php_user_stream_wrapper * uwrap = ( struct php_user_stream_wrapper * ) ecalloc ( 1 , sizeof ( * uwrap )); ;
493
491
zend_resource * rsrc ;
494
492
zend_long flags = 0 ;
495
493
496
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "SS|l" , & protocol , & classname , & flags ) == FAILURE ) {
494
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "SC|l" , & protocol , & uwrap -> ce , & flags ) == FAILURE ) {
495
+ efree (uwrap );
497
496
RETURN_THROWS ();
498
497
}
499
498
500
- uwrap = (struct php_user_stream_wrapper * )ecalloc (1 , sizeof (* uwrap ));
501
499
uwrap -> protoname = estrndup (ZSTR_VAL (protocol ), ZSTR_LEN (protocol ));
502
- uwrap -> classname = estrndup (ZSTR_VAL (classname ), ZSTR_LEN (classname ));
503
500
uwrap -> wrapper .wops = & user_stream_wops ;
504
501
uwrap -> wrapper .abstract = uwrap ;
505
502
uwrap -> wrapper .is_url = ((flags & PHP_STREAM_IS_URL ) != 0 );
506
503
507
504
rsrc = zend_register_resource (uwrap , le_protocols );
508
505
509
- if ((uwrap -> ce = zend_lookup_class (classname )) != NULL ) {
510
- if (php_register_url_stream_wrapper_volatile (protocol , & uwrap -> wrapper ) == SUCCESS ) {
511
- RETURN_TRUE ;
512
- } else {
513
- /* We failed. But why? */
514
- if (zend_hash_exists (php_stream_get_url_stream_wrappers_hash (), protocol )) {
515
- php_error_docref (NULL , E_WARNING , "Protocol %s:// is already defined." , ZSTR_VAL (protocol ));
516
- } else {
517
- /* Hash doesn't exist so it must have been an invalid protocol scheme */
518
- php_error_docref (NULL , E_WARNING , "Invalid protocol scheme specified. Unable to register wrapper class %s to %s://" , ZSTR_VAL (classname ), ZSTR_VAL (protocol ));
519
- }
520
- }
506
+ if (php_register_url_stream_wrapper_volatile (protocol , & uwrap -> wrapper ) == SUCCESS ) {
507
+ RETURN_TRUE ;
508
+ }
509
+
510
+ /* We failed. But why? */
511
+ if (zend_hash_exists (php_stream_get_url_stream_wrappers_hash (), protocol )) {
512
+ php_error_docref (NULL , E_WARNING , "Protocol %s:// is already defined." , ZSTR_VAL (protocol ));
521
513
} else {
522
- php_error_docref (NULL , E_WARNING , "Class '%s' is undefined" , ZSTR_VAL (classname ));
514
+ /* Hash doesn't exist so it must have been an invalid protocol scheme */
515
+ 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 ));
523
516
}
524
517
525
518
zend_list_delete (rsrc );
@@ -616,14 +609,14 @@ static ssize_t php_userstreamop_write(php_stream *stream, const char *buf, size_
616
609
}
617
610
} else {
618
611
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_WRITE " is not implemented!" ,
619
- us -> wrapper -> classname );
612
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
620
613
didwrite = -1 ;
621
614
}
622
615
623
616
/* don't allow strange buffer overruns due to bogus return */
624
617
if (didwrite > 0 && didwrite > count ) {
625
618
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)" ,
626
- us -> wrapper -> classname ,
619
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) ,
627
620
(zend_long )(didwrite - count ), (zend_long )didwrite , (zend_long )count );
628
621
didwrite = count ;
629
622
}
@@ -663,7 +656,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
663
656
664
657
if (call_result == FAILURE ) {
665
658
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_READ " is not implemented!" ,
666
- us -> wrapper -> classname );
659
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
667
660
return -1 ;
668
661
}
669
662
@@ -679,7 +672,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
679
672
if (didread > 0 ) {
680
673
if (didread > count ) {
681
674
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" ,
682
- us -> wrapper -> classname , (zend_long )(didread - count ), (zend_long )didread , (zend_long )count );
675
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) , (zend_long )(didread - count ), (zend_long )didread , (zend_long )count );
683
676
didread = count ;
684
677
}
685
678
memcpy (buf , Z_STRVAL (retval ), didread );
@@ -708,7 +701,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
708
701
} else if (call_result == FAILURE ) {
709
702
php_error_docref (NULL , E_WARNING ,
710
703
"%s::" USERSTREAM_EOF " is not implemented! Assuming EOF" ,
711
- us -> wrapper -> classname );
704
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
712
705
713
706
stream -> eof = 1 ;
714
707
}
@@ -832,7 +825,7 @@ static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int when
832
825
* newoffs = Z_LVAL (retval );
833
826
ret = 0 ;
834
827
} else if (call_result == FAILURE ) {
835
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_TELL " is not implemented!" , us -> wrapper -> classname );
828
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_TELL " is not implemented!" , ZSTR_VAL ( us -> wrapper -> ce -> name ) );
836
829
ret = -1 ;
837
830
} else {
838
831
ret = -1 ;
@@ -904,7 +897,7 @@ static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb)
904
897
} else {
905
898
if (call_result == FAILURE ) {
906
899
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_STAT " is not implemented!" ,
907
- us -> wrapper -> classname );
900
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
908
901
}
909
902
}
910
903
@@ -933,7 +926,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
933
926
ret = PHP_STREAM_OPTION_RETURN_ERR ;
934
927
php_error_docref (NULL , E_WARNING ,
935
928
"%s::" USERSTREAM_EOF " is not implemented! Assuming EOF" ,
936
- us -> wrapper -> classname );
929
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
937
930
}
938
931
zval_ptr_dtor (& retval );
939
932
zval_ptr_dtor (& func_name );
@@ -974,7 +967,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
974
967
ret = PHP_STREAM_OPTION_RETURN_OK ;
975
968
} else {
976
969
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_LOCK " is not implemented!" ,
977
- us -> wrapper -> classname );
970
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
978
971
ret = PHP_STREAM_OPTION_RETURN_ERR ;
979
972
}
980
973
}
@@ -1013,12 +1006,12 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
1013
1006
} else {
1014
1007
php_error_docref (NULL , E_WARNING ,
1015
1008
"%s::" USERSTREAM_TRUNCATE " did not return a boolean!" ,
1016
- us -> wrapper -> classname );
1009
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1017
1010
}
1018
1011
} else {
1019
1012
php_error_docref (NULL , E_WARNING ,
1020
1013
"%s::" USERSTREAM_TRUNCATE " is not implemented!" ,
1021
- us -> wrapper -> classname );
1014
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1022
1015
}
1023
1016
zval_ptr_dtor (& retval );
1024
1017
zval_ptr_dtor (& args [0 ]);
@@ -1073,7 +1066,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
1073
1066
1074
1067
if (call_result == FAILURE ) {
1075
1068
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_SET_OPTION " is not implemented!" ,
1076
- us -> wrapper -> classname );
1069
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1077
1070
ret = PHP_STREAM_OPTION_RETURN_ERR ;
1078
1071
} else if (zend_is_true (& retval )) {
1079
1072
ret = PHP_STREAM_OPTION_RETURN_OK ;
@@ -1124,7 +1117,7 @@ static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
1124
1117
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1125
1118
ret = (Z_TYPE (zretval ) == IS_TRUE );
1126
1119
} else if (call_result == FAILURE ) {
1127
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_UNLINK " is not implemented!" , uwrap -> classname );
1120
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_UNLINK " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1128
1121
}
1129
1122
1130
1123
/* clean up */
@@ -1168,7 +1161,7 @@ static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
1168
1161
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1169
1162
ret = (Z_TYPE (zretval ) == IS_TRUE );
1170
1163
} else if (call_result == FAILURE ) {
1171
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_RENAME " is not implemented!" , uwrap -> classname );
1164
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_RENAME " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1172
1165
}
1173
1166
1174
1167
/* clean up */
@@ -1214,7 +1207,7 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int
1214
1207
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1215
1208
ret = (Z_TYPE (zretval ) == IS_TRUE );
1216
1209
} else if (call_result == FAILURE ) {
1217
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_MKDIR " is not implemented!" , uwrap -> classname );
1210
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_MKDIR " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1218
1211
}
1219
1212
1220
1213
/* clean up */
@@ -1260,7 +1253,7 @@ static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url,
1260
1253
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1261
1254
ret = (Z_TYPE (zretval ) == IS_TRUE );
1262
1255
} else if (call_result == FAILURE ) {
1263
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_RMDIR " is not implemented!" , uwrap -> classname );
1256
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_RMDIR " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1264
1257
}
1265
1258
1266
1259
/* clean up */
@@ -1330,7 +1323,7 @@ static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, i
1330
1323
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1331
1324
ret = Z_TYPE (zretval ) == IS_TRUE ;
1332
1325
} else if (call_result == FAILURE ) {
1333
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_METADATA " is not implemented!" , uwrap -> classname );
1326
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_METADATA " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1334
1327
}
1335
1328
1336
1329
/* clean up */
@@ -1381,7 +1374,7 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, i
1381
1374
} else {
1382
1375
if (call_result == FAILURE ) {
1383
1376
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_STATURL " is not implemented!" ,
1384
- uwrap -> classname );
1377
+ ZSTR_VAL ( uwrap -> ce -> name ) );
1385
1378
}
1386
1379
}
1387
1380
@@ -1425,7 +1418,7 @@ static ssize_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t co
1425
1418
didread = sizeof (php_stream_dirent );
1426
1419
} else if (call_result == FAILURE ) {
1427
1420
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_DIR_READ " is not implemented!" ,
1428
- us -> wrapper -> classname );
1421
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1429
1422
}
1430
1423
1431
1424
zval_ptr_dtor (& retval );
@@ -1511,7 +1504,7 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
1511
1504
do {
1512
1505
if (call_result == FAILURE ) {
1513
1506
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_CAST " is not implemented!" ,
1514
- us -> wrapper -> classname );
1507
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1515
1508
break ;
1516
1509
}
1517
1510
if (!zend_is_true (& retval )) {
@@ -1520,12 +1513,12 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
1520
1513
php_stream_from_zval_no_verify (intstream , & retval );
1521
1514
if (!intstream ) {
1522
1515
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_CAST " must return a stream resource" ,
1523
- us -> wrapper -> classname );
1516
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1524
1517
break ;
1525
1518
}
1526
1519
if (intstream == stream ) {
1527
1520
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_CAST " must not return itself" ,
1528
- us -> wrapper -> classname );
1521
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1529
1522
intstream = NULL ;
1530
1523
break ;
1531
1524
}
0 commit comments