@@ -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,35 @@ 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 ;
471
+ zend_class_entry * ce = NULL ;
473
472
zend_resource * rsrc ;
474
473
zend_long flags = 0 ;
475
474
476
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "SS |l" , & protocol , & classname , & flags ) == FAILURE ) {
475
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "SC |l" , & protocol , & ce , & flags ) == FAILURE ) {
477
476
RETURN_THROWS ();
478
477
}
479
478
480
479
uwrap = (struct php_user_stream_wrapper * )ecalloc (1 , sizeof (* uwrap ));
480
+ uwrap -> ce = ce ;
481
481
uwrap -> protoname = estrndup (ZSTR_VAL (protocol ), ZSTR_LEN (protocol ));
482
- uwrap -> classname = estrndup (ZSTR_VAL (classname ), ZSTR_LEN (classname ));
483
482
uwrap -> wrapper .wops = & user_stream_wops ;
484
483
uwrap -> wrapper .abstract = uwrap ;
485
484
uwrap -> wrapper .is_url = ((flags & PHP_STREAM_IS_URL ) != 0 );
486
485
487
486
rsrc = zend_register_resource (uwrap , le_protocols );
488
487
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
- }
488
+ if (php_register_url_stream_wrapper_volatile (protocol , & uwrap -> wrapper ) == SUCCESS ) {
489
+ RETURN_TRUE ;
490
+ }
491
+
492
+ /* We failed. But why? */
493
+ if (zend_hash_exists (php_stream_get_url_stream_wrappers_hash (), protocol )) {
494
+ php_error_docref (NULL , E_WARNING , "Protocol %s:// is already defined." , ZSTR_VAL (protocol ));
501
495
} else {
502
- php_error_docref (NULL , E_WARNING , "Class '%s' is undefined" , ZSTR_VAL (classname ));
496
+ /* Hash doesn't exist so it must have been an invalid protocol scheme */
497
+ 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
498
}
504
499
505
500
zend_list_delete (rsrc );
@@ -596,14 +591,14 @@ static ssize_t php_userstreamop_write(php_stream *stream, const char *buf, size_
596
591
}
597
592
} else {
598
593
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_WRITE " is not implemented!" ,
599
- us -> wrapper -> classname );
594
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
600
595
didwrite = -1 ;
601
596
}
602
597
603
598
/* don't allow strange buffer overruns due to bogus return */
604
599
if (didwrite > 0 && didwrite > count ) {
605
600
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 ,
601
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) ,
607
602
(zend_long )(didwrite - count ), (zend_long )didwrite , (zend_long )count );
608
603
didwrite = count ;
609
604
}
@@ -643,7 +638,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
643
638
644
639
if (call_result == FAILURE ) {
645
640
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_READ " is not implemented!" ,
646
- us -> wrapper -> classname );
641
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
647
642
return -1 ;
648
643
}
649
644
@@ -659,7 +654,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
659
654
if (didread > 0 ) {
660
655
if (didread > count ) {
661
656
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 );
657
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) , (zend_long )(didread - count ), (zend_long )didread , (zend_long )count );
663
658
didread = count ;
664
659
}
665
660
memcpy (buf , Z_STRVAL (retval ), didread );
@@ -688,7 +683,7 @@ static ssize_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
688
683
} else if (call_result == FAILURE ) {
689
684
php_error_docref (NULL , E_WARNING ,
690
685
"%s::" USERSTREAM_EOF " is not implemented! Assuming EOF" ,
691
- us -> wrapper -> classname );
686
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
692
687
693
688
stream -> eof = 1 ;
694
689
}
@@ -812,7 +807,7 @@ static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int when
812
807
* newoffs = Z_LVAL (retval );
813
808
ret = 0 ;
814
809
} else if (call_result == FAILURE ) {
815
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_TELL " is not implemented!" , us -> wrapper -> classname );
810
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_TELL " is not implemented!" , ZSTR_VAL ( us -> wrapper -> ce -> name ) );
816
811
ret = -1 ;
817
812
} else {
818
813
ret = -1 ;
@@ -884,7 +879,7 @@ static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb)
884
879
} else {
885
880
if (call_result == FAILURE ) {
886
881
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_STAT " is not implemented!" ,
887
- us -> wrapper -> classname );
882
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
888
883
}
889
884
}
890
885
@@ -913,7 +908,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
913
908
ret = PHP_STREAM_OPTION_RETURN_ERR ;
914
909
php_error_docref (NULL , E_WARNING ,
915
910
"%s::" USERSTREAM_EOF " is not implemented! Assuming EOF" ,
916
- us -> wrapper -> classname );
911
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
917
912
}
918
913
zval_ptr_dtor (& retval );
919
914
zval_ptr_dtor (& func_name );
@@ -954,7 +949,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
954
949
ret = PHP_STREAM_OPTION_RETURN_OK ;
955
950
} else {
956
951
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_LOCK " is not implemented!" ,
957
- us -> wrapper -> classname );
952
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
958
953
ret = PHP_STREAM_OPTION_RETURN_ERR ;
959
954
}
960
955
}
@@ -993,12 +988,12 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
993
988
} else {
994
989
php_error_docref (NULL , E_WARNING ,
995
990
"%s::" USERSTREAM_TRUNCATE " did not return a boolean!" ,
996
- us -> wrapper -> classname );
991
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
997
992
}
998
993
} else {
999
994
php_error_docref (NULL , E_WARNING ,
1000
995
"%s::" USERSTREAM_TRUNCATE " is not implemented!" ,
1001
- us -> wrapper -> classname );
996
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1002
997
}
1003
998
zval_ptr_dtor (& retval );
1004
999
zval_ptr_dtor (& args [0 ]);
@@ -1053,7 +1048,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value
1053
1048
1054
1049
if (call_result == FAILURE ) {
1055
1050
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_SET_OPTION " is not implemented!" ,
1056
- us -> wrapper -> classname );
1051
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1057
1052
ret = PHP_STREAM_OPTION_RETURN_ERR ;
1058
1053
} else if (zend_is_true (& retval )) {
1059
1054
ret = PHP_STREAM_OPTION_RETURN_OK ;
@@ -1104,7 +1099,7 @@ static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
1104
1099
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1105
1100
ret = (Z_TYPE (zretval ) == IS_TRUE );
1106
1101
} else if (call_result == FAILURE ) {
1107
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_UNLINK " is not implemented!" , uwrap -> classname );
1102
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_UNLINK " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1108
1103
}
1109
1104
1110
1105
/* clean up */
@@ -1148,7 +1143,7 @@ static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
1148
1143
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1149
1144
ret = (Z_TYPE (zretval ) == IS_TRUE );
1150
1145
} else if (call_result == FAILURE ) {
1151
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_RENAME " is not implemented!" , uwrap -> classname );
1146
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_RENAME " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1152
1147
}
1153
1148
1154
1149
/* clean up */
@@ -1194,7 +1189,7 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int
1194
1189
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1195
1190
ret = (Z_TYPE (zretval ) == IS_TRUE );
1196
1191
} else if (call_result == FAILURE ) {
1197
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_MKDIR " is not implemented!" , uwrap -> classname );
1192
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_MKDIR " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1198
1193
}
1199
1194
1200
1195
/* clean up */
@@ -1240,7 +1235,7 @@ static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url,
1240
1235
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1241
1236
ret = (Z_TYPE (zretval ) == IS_TRUE );
1242
1237
} else if (call_result == FAILURE ) {
1243
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_RMDIR " is not implemented!" , uwrap -> classname );
1238
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_RMDIR " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1244
1239
}
1245
1240
1246
1241
/* clean up */
@@ -1310,7 +1305,7 @@ static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, i
1310
1305
if (call_result == SUCCESS && (Z_TYPE (zretval ) == IS_FALSE || Z_TYPE (zretval ) == IS_TRUE )) {
1311
1306
ret = Z_TYPE (zretval ) == IS_TRUE ;
1312
1307
} else if (call_result == FAILURE ) {
1313
- php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_METADATA " is not implemented!" , uwrap -> classname );
1308
+ php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_METADATA " is not implemented!" , ZSTR_VAL ( uwrap -> ce -> name ) );
1314
1309
}
1315
1310
1316
1311
/* clean up */
@@ -1361,7 +1356,7 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, i
1361
1356
} else {
1362
1357
if (call_result == FAILURE ) {
1363
1358
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_STATURL " is not implemented!" ,
1364
- uwrap -> classname );
1359
+ ZSTR_VAL ( uwrap -> ce -> name ) );
1365
1360
}
1366
1361
}
1367
1362
@@ -1405,7 +1400,7 @@ static ssize_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t co
1405
1400
didread = sizeof (php_stream_dirent );
1406
1401
} else if (call_result == FAILURE ) {
1407
1402
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_DIR_READ " is not implemented!" ,
1408
- us -> wrapper -> classname );
1403
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1409
1404
}
1410
1405
1411
1406
zval_ptr_dtor (& retval );
@@ -1491,7 +1486,7 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
1491
1486
do {
1492
1487
if (call_result == FAILURE ) {
1493
1488
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_CAST " is not implemented!" ,
1494
- us -> wrapper -> classname );
1489
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1495
1490
break ;
1496
1491
}
1497
1492
if (!zend_is_true (& retval )) {
@@ -1500,12 +1495,12 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr)
1500
1495
php_stream_from_zval_no_verify (intstream , & retval );
1501
1496
if (!intstream ) {
1502
1497
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_CAST " must return a stream resource" ,
1503
- us -> wrapper -> classname );
1498
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1504
1499
break ;
1505
1500
}
1506
1501
if (intstream == stream ) {
1507
1502
php_error_docref (NULL , E_WARNING , "%s::" USERSTREAM_CAST " must not return itself" ,
1508
- us -> wrapper -> classname );
1503
+ ZSTR_VAL ( us -> wrapper -> ce -> name ) );
1509
1504
intstream = NULL ;
1510
1505
break ;
1511
1506
}
0 commit comments