diff --git a/rsync.c b/rsync.c index e623882..3e3e3e5 100755 --- a/rsync.c +++ b/rsync.c @@ -20,7 +20,7 @@ #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" - +#include "zend_exceptions.h" #include #include "php_rsync.h" @@ -154,12 +154,12 @@ static zend_object_handlers Rsync_object_handlers; /* {{{ Rsync_methods[] */ const zend_function_entry Rsync_methods[] = { PHP_ME(Rsync, __construct, NULL, ZEND_ACC_PUBLIC) - PHP_ME(Rsync, generateSignature, NULL, ZEND_ACC_PUBLIC) - PHP_ME(Rsync, generateDelta, NULL, ZEND_ACC_PUBLIC) - PHP_ME(Rsync, patchFile, NULL, ZEND_ACC_PUBLIC) - PHP_ME(Rsync, setLogCallback, NULL, ZEND_ACC_PUBLIC) - PHP_ME(Rsync, setLogLevel, NULL, ZEND_ACC_PUBLIC) - PHP_ME(Rsync, getError, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Rsync, generateSignature, arginfo_rsync_generate_signature, ZEND_ACC_PUBLIC) + PHP_ME(Rsync, generateDelta, arginfo_rsync_generate_delta, ZEND_ACC_PUBLIC) + PHP_ME(Rsync, patchFile, arginfo_rsync_patch_file, ZEND_ACC_PUBLIC) + PHP_ME(Rsync, setLogCallback, arginfo_rsync_set_log_callback, ZEND_ACC_PUBLIC) + PHP_ME(Rsync, setLogLevel, arginfo_rsync_set_log_level, ZEND_ACC_PUBLIC) + PHP_ME(Rsync, getError, arginfo_rsync_error, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* }}} */ @@ -218,29 +218,21 @@ php_rsync_object_destroy(void *obj TSRMLS_DC) /* }}} */ /* {{{ php_rsync_object_init */ -zend_object_value +zend_object * php_rsync_object_init(zend_class_entry *ze TSRMLS_DC) { - zend_object_value ret; struct ze_rsync_main_obj *zrmo; - zval *tmp; - - zrmo = (struct ze_rsync_main_obj*) emalloc(sizeof(struct ze_rsync_main_obj)); - memset(&zrmo->zo, 0, sizeof(zend_object)); + zrmo = ecalloc(1, sizeof(struct ze_rsync_main_obj) + zend_object_properties_size(ze)); - zend_object_std_init(&zrmo->zo, ze TSRMLS_CC); + zend_object_std_init(&zrmo->zo, ze); object_properties_init(&zrmo->zo, ze); zrmo->block_length = RS_DEFAULT_BLOCK_LEN; zrmo->strong_length = RS_DEFAULT_STRONG_LEN; - ret.handle = zend_objects_store_put(zrmo, NULL, - (zend_objects_free_object_storage_t) php_rsync_object_destroy, - NULL TSRMLS_CC); - - ret.handlers = (zend_object_handlers *) &Rsync_object_handlers; - - return ret; + zrmo->zo.handlers = &Rsync_object_handlers; + return &zrmo->zo; + } /* }}} */ @@ -248,7 +240,7 @@ php_rsync_object_init(zend_class_entry *ze TSRMLS_DC) * */ php_stream * -php_rsync_file_open(zval **file, char *mode TSRMLS_DC) +php_rsync_file_open(zval *file, char *mode TSRMLS_DC) { zval *return_value; php_stream *stream = NULL; @@ -258,7 +250,7 @@ php_rsync_file_open(zval **file, char *mode TSRMLS_DC) char *type_string; int options = STREAM_MUST_SEEK | STREAM_WILL_CAST; - if (Z_TYPE_PP(file) == IS_RESOURCE) { + if (Z_TYPE_P(file) == IS_RESOURCE) { php_stream_from_zval(stream, file); if (FAILURE == php_stream_can_cast(stream, PHP_STREAM_AS_STDIO)) { zend_throw_exception_ex( @@ -268,9 +260,9 @@ php_rsync_file_open(zval **file, char *mode TSRMLS_DC) (stream && stream->orig_path) ? estrdup(stream->orig_path) : "''" ); } - } else if (Z_TYPE_PP(file) == IS_STRING) { - string = Z_STRVAL_PP(file); - strlen = Z_STRLEN_PP(file); + } else if (Z_TYPE_P(file) == IS_STRING) { + string = Z_STRVAL_P(file); + strlen = Z_STRLEN_P(file); is_write = mode[0] == 'w'; stream = php_stream_open_wrapper(string, mode, options, NULL); @@ -287,12 +279,12 @@ php_rsync_file_open(zval **file, char *mode TSRMLS_DC) ); } } else { - convert_to_string(*file); + convert_to_string(file); zend_throw_exception_ex( RsyncInvalidArgumentException_ce, 0 TSRMLS_CC, "Expected string or stream, \"%s\" was given", /* XXX give file and line */ - estrdup(Z_STRVAL_PP(file)) + estrdup(Z_STRVAL_P(file)) ); } @@ -362,15 +354,16 @@ void php_rsync_log(int level, const char *msg) message += 2; if (RSYNC_G(has_log_cb)) { - MAKE_STD_ZVAL(params); + params = (zval *) safe_emalloc(sizeof(zval), 1, 0); array_init_size(params, 2); add_next_index_long(params, (long)level); - add_next_index_string(params, message, 1); + add_next_index_string(params, message); zend_fcall_info_argn(&RSYNC_G(log_cb).fci TSRMLS_CC, 2, &level, &message); - zend_fcall_info_call(&RSYNC_G(log_cb).fci, &RSYNC_G(log_cb).fcc, &retval_ptr, params TSRMLS_CC); + zend_fcall_info_call(&RSYNC_G(log_cb).fci, &RSYNC_G(log_cb).fcc, retval_ptr, params TSRMLS_CC); zend_fcall_info_args_clear(&RSYNC_G(log_cb).fci, 1); + efree(params); } else { type = php_rsync_map_log_level(level TSRMLS_CC); php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Rsync %s: %s", type, message); @@ -397,9 +390,9 @@ void php_rsync_globals_ctor(zend_rsync_globals *rsync_globals TSRMLS_DC) rsync_globals->log_stats = 0; rsync_globals->has_log_cb = 0; rsync_globals->error = 0; - rsync_globals->log_cb.fci.function_name = NULL; + zval_ptr_dtor(&rsync_globals->log_cb.fci.function_name); #if PHP_VERSION_ID >= 50300 - rsync_globals->log_cb.fci.object_ptr = NULL; + //rsync_globals->log_cb.fci.object_ptr = NULL; #endif } /* }}} */ @@ -409,7 +402,7 @@ void php_rsync_globals_ctor(zend_rsync_globals *rsync_globals TSRMLS_DC) void php_rsync_globals_dtor(zend_rsync_globals *rsync_globals TSRMLS_DC) { if (rsync_globals->has_log_cb) { - efree(&rsync_globals->log_cb); + //efree(&rsync_globals->log_cb); } } /* }}} */ @@ -423,6 +416,7 @@ PHP_MINIT_FUNCTION(rsync) zend_class_entry ce; memcpy(&Rsync_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + Rsync_object_handlers.offset = XtOffsetOf(struct ze_rsync_main_obj, zo); Rsync_object_handlers.clone_obj = NULL; INIT_CLASS_ENTRY(ce, "Rsync", Rsync_methods); @@ -431,23 +425,26 @@ PHP_MINIT_FUNCTION(rsync) INIT_CLASS_ENTRY(ce, "RsyncException", NULL); RsyncException_ce = zend_register_internal_class_ex( - &ce, NULL, "exception" TSRMLS_CC + &ce, zend_exception_get_default(TSRMLS_C) ); + zend_class_implements(RsyncException_ce TSRMLS_CC, 1, zend_ce_throwable); + INIT_CLASS_ENTRY(ce, "RsyncStreamNotCastableException", NULL); RsyncStreamNotCastableException_ce = zend_register_internal_class_ex( - &ce, RsyncException_ce, NULL TSRMLS_CC + &ce, RsyncException_ce ); INIT_CLASS_ENTRY(ce, "RsyncFileIoException", NULL); RsyncFileIoException_ce = zend_register_internal_class_ex( - &ce, RsyncException_ce, NULL TSRMLS_CC + &ce, RsyncException_ce ); INIT_CLASS_ENTRY(ce, "RsyncInvalidArgumentException", NULL); RsyncInvalidArgumentException_ce = zend_register_internal_class_ex( - &ce, RsyncException_ce, NULL TSRMLS_CC + &ce, RsyncException_ce ); + REGISTER_LONG_CONSTANT("RSYNC_DONE", RS_DONE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("RSYNC_BLOCKED", RS_BLOCKED, CONST_CS | CONST_PERSISTENT); @@ -534,7 +531,7 @@ PHP_MINFO_FUNCTION(rsync) /* {{{ php_rsync_generate_signature */ static int -php_rsync_generate_signature(zval **file, zval **sigfile, long block_length, long strong_length TSRMLS_DC) +php_rsync_generate_signature(zval *file, zval *sigfile, long block_length, long strong_length TSRMLS_DC) { php_stream *infile_stream, *sigfile_stream; FILE *infile, *signaturfile; @@ -557,8 +554,8 @@ php_rsync_generate_signature(zval **file, zval **sigfile, long block_length, lon ret = rs_sig_file(infile, signaturfile, block_length, strong_length, &RSYNC_G(stats)); php_rsync_log_stats(TSRMLS_C); - if (Z_TYPE_PP(file) != IS_RESOURCE) php_stream_close(infile_stream); - if (Z_TYPE_PP(file) != IS_RESOURCE) php_stream_close(sigfile_stream); + if (Z_TYPE_P(file) != IS_RESOURCE) php_stream_close(infile_stream); + if (Z_TYPE_P(file) != IS_RESOURCE) php_stream_close(sigfile_stream); return ret; } @@ -568,10 +565,10 @@ php_rsync_generate_signature(zval **file, zval **sigfile, long block_length, lon Generate a signatur file from the given file */ PHP_FUNCTION(rsync_generate_signature) { - zval **file = NULL, **sigfile = NULL; + zval *file = NULL, *sigfile = NULL; int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "ZZ", &file, &sigfile) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &file, &sigfile) == FAILURE) { RETURN_LONG(RS_INTERNAL_ERROR); return; } @@ -584,7 +581,7 @@ PHP_FUNCTION(rsync_generate_signature) /* {{{ php_rsync_generate_delta */ static int -php_rsync_generate_delta(zval **sigfile, zval **file, zval **deltafile TSRMLS_DC) +php_rsync_generate_delta(zval *sigfile, zval *file, zval *deltafile TSRMLS_DC) { php_stream *infile_stream, *sigfile_stream, *deltafile_stream; FILE *signaturfile, *infile, *delta; @@ -629,9 +626,9 @@ php_rsync_generate_delta(zval **sigfile, zval **file, zval **deltafile TSRMLS_DC ret = rs_delta_file(sumset, infile, delta, &RSYNC_G(stats)); php_rsync_log_stats(TSRMLS_C); - if (Z_TYPE_PP(file) != IS_RESOURCE) php_stream_close(sigfile_stream); - if (Z_TYPE_PP(file) != IS_RESOURCE) php_stream_close(infile_stream); - if (Z_TYPE_PP(file) != IS_RESOURCE) php_stream_close(deltafile_stream); + if (Z_TYPE_P(file) != IS_RESOURCE) php_stream_close(sigfile_stream); + if (Z_TYPE_P(file) != IS_RESOURCE) php_stream_close(infile_stream); + if (Z_TYPE_P(file) != IS_RESOURCE) php_stream_close(deltafile_stream); return ret; } @@ -641,10 +638,10 @@ php_rsync_generate_delta(zval **sigfile, zval **file, zval **deltafile TSRMLS_DC Generate the delta from signature to the file */ PHP_FUNCTION(rsync_generate_delta) { - zval **sigfile = NULL, **file = NULL, **deltafile = NULL; + zval *sigfile = NULL, *file = NULL, *deltafile = NULL; int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "ZZZ", &sigfile, &file, &deltafile) == FAILURE) { + if (zend_parse_parameters(argc TSRMLS_CC, "zzz", &sigfile, &file, &deltafile) == FAILURE) { RETURN_LONG(RS_INTERNAL_ERROR); return; } @@ -657,7 +654,7 @@ PHP_FUNCTION(rsync_generate_delta) /* {{{ php_rsync_patch_file */ static int -php_rsync_patch_file(zval **file, zval **deltafile, zval **newfile TSRMLS_DC) +php_rsync_patch_file(zval *file, zval *deltafile, zval *newfile TSRMLS_DC) { FILE *basis_file, *delta_file, *new_file; php_stream *basisfile_stream, *newfile_stream, *deltafile_stream; @@ -686,9 +683,9 @@ php_rsync_patch_file(zval **file, zval **deltafile, zval **newfile TSRMLS_DC) ret = rs_patch_file(basis_file, delta_file, new_file, &RSYNC_G(stats)); php_rsync_log_stats(TSRMLS_C); - if (Z_TYPE_PP(file) != IS_RESOURCE) php_stream_close(basisfile_stream); - if (Z_TYPE_PP(file) != IS_RESOURCE) php_stream_close(newfile_stream); - if (Z_TYPE_PP(file) != IS_RESOURCE) php_stream_close(deltafile_stream); + if (Z_TYPE_P(file) != IS_RESOURCE) php_stream_close(basisfile_stream); + if (Z_TYPE_P(file) != IS_RESOURCE) php_stream_close(newfile_stream); + if (Z_TYPE_P(file) != IS_RESOURCE) php_stream_close(deltafile_stream); return ret; } @@ -698,10 +695,10 @@ php_rsync_patch_file(zval **file, zval **deltafile, zval **newfile TSRMLS_DC) Patch the file with delta and write the resulte in newfile */ PHP_FUNCTION(rsync_patch_file) { - zval **file = NULL, **deltafile = NULL, **newfile = NULL; + zval *file = NULL, *deltafile = NULL, *newfile = NULL; int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "ZZZ", &file, &deltafile, &newfile) == FAILURE) { + if (zend_parse_parameters(argc TSRMLS_CC, "zzz", &file, &deltafile, &newfile) == FAILURE) { RETURN_LONG(RS_INTERNAL_ERROR); return; } @@ -726,12 +723,12 @@ PHP_FUNCTION(rsync_set_log_callback) RSYNC_G(log_cb).fci = fci; RSYNC_G(log_cb).fcc = fcc; - Z_ADDREF_P(RSYNC_G(log_cb).fci.function_name); + Z_ADDREF_P(&RSYNC_G(log_cb).fci.function_name); #if PHP_VERSION_ID >= 50300 - if (RSYNC_G(log_cb).fci.object_ptr) { - Z_ADDREF_P(RSYNC_G(log_cb).fci.object_ptr); - } + /*if (RSYNC_G(log_cb).fci.object_ptr) { + Z_TRY_ADDREF_P(RSYNC_G(log_cb).fci.object_ptr); + }*/ #endif RSYNC_G(has_log_cb) = 1; @@ -774,31 +771,31 @@ PHP_FUNCTION(rsync_error) result = RSYNC_G(ret); } - RETVAL_STRING(rs_strerror(result), 1); + RETVAL_STRING(rs_strerror(result)); } /* }}} */ /* {{{ proto Rsync::__costruct(array options) the main rsync class constructor */ PHP_METHOD(Rsync, __construct) { - zval *opts = NULL, **blen, **slen; + zval *opts = NULL, *blen, *slen; struct ze_rsync_main_obj *zrmo; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", &opts) == FAILURE) { return; } - zrmo = (struct ze_rsync_main_obj *) zend_object_store_get_object(getThis() TSRMLS_CC); + zrmo = (struct ze_rsync_main_obj *) ((char*)Z_OBJ_P(getThis()) - XtOffsetOf(struct ze_rsync_main_obj, zo)); zrmo->block_length = RS_DEFAULT_BLOCK_LEN; zrmo->strong_length = RS_DEFAULT_STRONG_LEN; if (opts) { - if (zend_hash_find(Z_ARRVAL_P(opts), "block_length", sizeof("block_length"), (void **)&blen) != FAILURE) { - zrmo->block_length = Z_LVAL_PP(blen); + if (zend_hash_find(Z_ARRVAL_P(opts), zend_string_init("block_length", sizeof("block_length")-1, 0)) != NULL) { + zrmo->block_length = Z_LVAL_P(blen); } - if (zend_hash_find(Z_ARRVAL_P(opts), "strong_length", sizeof("strong_length"), (void **)&slen) != FAILURE) { - zrmo->strong_length = Z_LVAL_PP(slen); + if (zend_hash_find(Z_ARRVAL_P(opts), zend_string_init("strong_length", sizeof("strong_length")-1, 0)) != NULL) { + zrmo->strong_length = Z_LVAL_P(slen); } } /* XXX init also filenames or streams internally and make some method arguments optional */ @@ -809,16 +806,15 @@ PHP_METHOD(Rsync, __construct) Generate a signatur file from the given file */ PHP_METHOD(Rsync, generateSignature) { - zval **file = NULL, **sigfile = NULL; + zval *file = NULL, *sigfile = NULL; int argc = ZEND_NUM_ARGS(); struct ze_rsync_main_obj *zrmo; - if (zend_parse_parameters(argc TSRMLS_CC, "ZZ", &file, &sigfile) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &file, &sigfile) == FAILURE) { RETURN_LONG(RS_INTERNAL_ERROR); return; } - - zrmo = (struct ze_rsync_main_obj *) zend_object_store_get_object(getThis() TSRMLS_CC); + zrmo = (struct ze_rsync_main_obj *) ((char*)Z_OBJ_P(getThis()) - XtOffsetOf(struct ze_rsync_main_obj, zo)); zrmo->ret = php_rsync_generate_signature(file, sigfile, zrmo->block_length, zrmo->strong_length TSRMLS_CC); @@ -830,16 +826,16 @@ PHP_METHOD(Rsync, generateSignature) Generate the delta from signature to the file */ PHP_METHOD(Rsync, generateDelta) { - zval **sigfile = NULL, **file = NULL, **deltafile = NULL; - int argc = ZEND_NUM_ARGS(); + zval *sigfile = NULL, *file = NULL, *deltafile = NULL; + //int argc = ZEND_NUM_ARGS(); struct ze_rsync_main_obj *zrmo; - if (zend_parse_parameters(argc TSRMLS_CC, "ZZZ", &sigfile, &file, &deltafile) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ZZZ", &sigfile, &file, &deltafile) == FAILURE) { RETURN_LONG(RS_INTERNAL_ERROR); return; } - zrmo = (struct ze_rsync_main_obj *) zend_object_store_get_object(getThis() TSRMLS_CC); + zrmo = (struct ze_rsync_main_obj *) ((char*)Z_OBJ_P(getThis()) - XtOffsetOf(struct ze_rsync_main_obj, zo)); zrmo->ret = php_rsync_generate_delta(sigfile, file, deltafile TSRMLS_CC); @@ -851,16 +847,16 @@ PHP_METHOD(Rsync, generateDelta) Patch the file with delta and write the resulte in newfile */ PHP_METHOD(Rsync, patchFile) { - zval **file = NULL, **deltafile = NULL, **newfile = NULL; - int argc = ZEND_NUM_ARGS(); + zval *file = NULL, *deltafile = NULL, *newfile = NULL; + //int argc = ZEND_NUM_ARGS(); struct ze_rsync_main_obj *zrmo; - if (zend_parse_parameters(argc TSRMLS_CC, "ZZZ", &file, &deltafile, &newfile) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "zzz", &file, &deltafile, &newfile) == FAILURE) { RETURN_LONG(RS_INTERNAL_ERROR); return; } - zrmo = (struct ze_rsync_main_obj *) zend_object_store_get_object(getThis() TSRMLS_CC); + zrmo = (struct ze_rsync_main_obj *) ((char*)Z_OBJ_P(getThis()) - XtOffsetOf(struct ze_rsync_main_obj, zo)); zrmo->ret = php_rsync_patch_file(file, deltafile, newfile TSRMLS_CC);