[libvirt] [libvirt-php PATCH 00/35] Add PHP7 support and unit tests

First, I apologize if this was sent twice to anyone. I had an error in my git send-email configuration. This patch set primarily adds support for PHP 7 to libvirt-php, but also adds the capability for libvirt-php to be built using the standard PHP extension build system method. Several tests have been updated and added by Remi Collet (Fedora PHP stack maintainer) and Frederic Mora (my colleague who graciously assisted in this effort). I intend to provide more tests over time, but I think this is a good start. These tests can be run through `make tests` in the new build system. Instructions for using the new build system is also included. The original build system still properly builds libvirt-php on either PHP 5.6 or PHP 7.0. This was tested using Remi's PHP 5.6 and PHP 7.0 software collections on CentOS 7.2. Most of this work was done by Remi Collet several weeks ago, with Chuck Roydhouse doing work to ensure that Vasiliy Tolstov's patches from the current git master could be incorporated into this work. They are included in this patch set, but should be the same as what is in the tree now. This work started before he posted his commits and they were merged, and were merged in to ensure that it could remain working. The version number was bumped to 0.5.2 by Remi, and I bumped it in the main build system simply for consistency. I would greatly appreciate a quick review and merge of this patch set. Chuck Roydhouse (1): add arginfo for libvirt_domain_block_commit and libvirt_domain_block_job_info Frederic Mora (1): Add more tests Neal Gompa (2): Commit short instructions to using the php extension build method Bump version to 0.5.2 Remi Collet (28): add config.m4 to allow standard PHP extension build system include config.h earlier add missing arginfo (wip) fix typo in config.m4 add missing arginfo, part 2 adapt RETURN_STRING work on zpp register + fetch resources + hash adapt add_assoc_string_ex clean ALLOC_INIT_ZVAL zend_hash_update add_next_index_string buildable with PHP 7 bump version 0.5.2-dev fix zpp fix missed (hidden) zpp calls fix PHP 5 compat fix libvirt_version + add test port test-connect.phpt to real phpt Switch all add_assoc_string_ex to add_assoc_string to avoid nul char management Fix max_connections management add test-conn-limit.phpt (as real phpt) add test-connect-get-emulator.phpt fix parse_array + build warnings convert test-install.phpt to real phpt convert test-domain-create-and-coredump.phpt to real phpt convert test-domain-create-and-get-xpath.phpt to real phpt fix PHP 5 compat again (nested macro issue) Vasiliy Tolstov (3): add some checks to prevent overflow add block_commit support and needed const add libvirt_domain_block_job_info

From: Remi Collet <fedora@famillecollet.com> --- src/config.m4 | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/config.m4 diff --git a/src/config.m4 b/src/config.m4 new file mode 100644 index 0000000..ee2b47d --- /dev/null +++ b/src/config.m4 @@ -0,0 +1,52 @@ +PHP_ARG_WITH(libvirt, for libvirt support, +[ --with-libvirt Include varnish support]) + +if test "$PHP_LIBVIRT" != "no"; then + + AC_PATH_PROG(PKG_CONFIG, pkg-config, no) + + if test -x "$PKG_CONFIG" && $PKG_CONFIG varnishapi --exists ; then + AC_MSG_CHECKING(libvirt version) + if $PKG_CONFIG libvirt --atleast-version=1.2.8 ; then + LIBVIRT_INCLUDE=`$PKG_CONFIG libvirt --cflags` + LIBVIRT_LIBRARY=`$PKG_CONFIG libvirt --libs` + LIBVIRT_VERSION=`$PKG_CONFIG libvirt --modversion` + AC_MSG_RESULT($LIBVIRT_VERSION) + else + AC_MSG_ERROR(version too old) + fi + PHP_EVAL_INCLINE($LIBVIRT_INCLUDE) + PHP_EVAL_LIBLINE($LIBVIRT_LIBRARY, LIBVIRT_SHARED_LIBADD) + + AC_MSG_CHECKING(libvirt-qemu version) + if $PKG_CONFIG libvirt-qemu --atleast-version=1.2.8 ; then + QEMU_INCLUDE=`$PKG_CONFIG libvirt-qemu --cflags` + QEMU_LIBRARY=`$PKG_CONFIG libvirt-qemu --libs` + QEMU_VERSION=`$PKG_CONFIG libvirt-qemu --modversion` + AC_MSG_RESULT($QEMU_VERSION) + else + AC_MSG_ERROR(version too old) + fi + PHP_EVAL_INCLINE($QEMU_INCLUDE) + PHP_EVAL_LIBLINE($QEMU_LIBRARY, LIBVIRT_SHARED_LIBADD) + + AC_MSG_CHECKING(libxml version) + if $PKG_CONFIG libxml-2.0 --atleast-version=1.2.8 ; then + LIBXML_INCLUDE=`$PKG_CONFIG libxml-2.0 --cflags` + LIBXML_LIBRARY=`$PKG_CONFIG libxml-2.0 --libs` + LIBXML_VERSION=`$PKG_CONFIG libxml-2.0 --modversion` + AC_MSG_RESULT($LIBXML_VERSION) + else + AC_MSG_ERROR(version too old) + fi + PHP_EVAL_INCLINE($LIBXML_INCLUDE) + PHP_EVAL_LIBLINE($LIBXML_LIBRARY, LIBVIRT_SHARED_LIBADD) + + CFLAGS="$CFLAGS -DCOMPILE_DL_LIBVIRT=1" + + PHP_SUBST(LIBVIRT_SHARED_LIBADD) + PHP_NEW_EXTENSION(libvirt, libvirt-php.c sockets.c vncfunc.c, $ext_shared) + else + AC_MSG_ERROR(pkg-config not found) + fi +fi -- 2.5.5

On 09.04.2016 00:08, Neal Gompa wrote:
From: Remi Collet <fedora@famillecollet.com>
--- src/config.m4 | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/config.m4
diff --git a/src/config.m4 b/src/config.m4 new file mode 100644 index 0000000..ee2b47d --- /dev/null +++ b/src/config.m4 @@ -0,0 +1,52 @@ +PHP_ARG_WITH(libvirt, for libvirt support, +[ --with-libvirt Include varnish support])
What's varnish? It should have been libvirt instead.
+ +if test "$PHP_LIBVIRT" != "no"; then + + AC_PATH_PROG(PKG_CONFIG, pkg-config, no) + + if test -x "$PKG_CONFIG" && $PKG_CONFIG varnishapi --exists ; then + AC_MSG_CHECKING(libvirt version) + if $PKG_CONFIG libvirt --atleast-version=1.2.8 ; then + LIBVIRT_INCLUDE=`$PKG_CONFIG libvirt --cflags` + LIBVIRT_LIBRARY=`$PKG_CONFIG libvirt --libs` + LIBVIRT_VERSION=`$PKG_CONFIG libvirt --modversion` + AC_MSG_RESULT($LIBVIRT_VERSION) + else + AC_MSG_ERROR(version too old) + fi + PHP_EVAL_INCLINE($LIBVIRT_INCLUDE) + PHP_EVAL_LIBLINE($LIBVIRT_LIBRARY, LIBVIRT_SHARED_LIBADD) + + AC_MSG_CHECKING(libvirt-qemu version) + if $PKG_CONFIG libvirt-qemu --atleast-version=1.2.8 ; then + QEMU_INCLUDE=`$PKG_CONFIG libvirt-qemu --cflags` + QEMU_LIBRARY=`$PKG_CONFIG libvirt-qemu --libs` + QEMU_VERSION=`$PKG_CONFIG libvirt-qemu --modversion` + AC_MSG_RESULT($QEMU_VERSION) + else + AC_MSG_ERROR(version too old) + fi + PHP_EVAL_INCLINE($QEMU_INCLUDE) + PHP_EVAL_LIBLINE($QEMU_LIBRARY, LIBVIRT_SHARED_LIBADD) + + AC_MSG_CHECKING(libxml version) + if $PKG_CONFIG libxml-2.0 --atleast-version=1.2.8 ; then + LIBXML_INCLUDE=`$PKG_CONFIG libxml-2.0 --cflags` + LIBXML_LIBRARY=`$PKG_CONFIG libxml-2.0 --libs` + LIBXML_VERSION=`$PKG_CONFIG libxml-2.0 --modversion` + AC_MSG_RESULT($LIBXML_VERSION) + else + AC_MSG_ERROR(version too old) + fi + PHP_EVAL_INCLINE($LIBXML_INCLUDE) + PHP_EVAL_LIBLINE($LIBXML_LIBRARY, LIBVIRT_SHARED_LIBADD) + + CFLAGS="$CFLAGS -DCOMPILE_DL_LIBVIRT=1" + + PHP_SUBST(LIBVIRT_SHARED_LIBADD) + PHP_NEW_EXTENSION(libvirt, libvirt-php.c sockets.c vncfunc.c, $ext_shared) + else + AC_MSG_ERROR(pkg-config not found) + fi +fi
Michal

From: Remi Collet <fedora@famillecollet.com> --- src/config.m4 | 2 -- src/libvirt-php.h | 14 ++++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/config.m4 b/src/config.m4 index ee2b47d..d255f77 100644 --- a/src/config.m4 +++ b/src/config.m4 @@ -42,8 +42,6 @@ if test "$PHP_LIBVIRT" != "no"; then PHP_EVAL_INCLINE($LIBXML_INCLUDE) PHP_EVAL_LIBLINE($LIBXML_LIBRARY, LIBVIRT_SHARED_LIBADD) - CFLAGS="$CFLAGS -DCOMPILE_DL_LIBVIRT=1" - PHP_SUBST(LIBVIRT_SHARED_LIBADD) PHP_NEW_EXTENSION(libvirt, libvirt-php.c sockets.c vncfunc.c, $ext_shared) else diff --git a/src/libvirt-php.h b/src/libvirt-php.h index eb4b7f4..6b56547 100644 --- a/src/libvirt-php.h +++ b/src/libvirt-php.h @@ -48,14 +48,18 @@ #define COMPILE_DL_LIBVIRT #endif +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #ifdef COMPILE_DL_LIBVIRT -#include "php.h" #undef PACKAGE_BUGREPORT #undef PACKAGE_NAME #undef PACKAGE_STRING #undef PACKAGE_TARNAME #undef PACKAGE_URL #undef PACKAGE_VERSION +#include "php.h" #ifdef ZTS #include "TSRM.h" @@ -69,13 +73,11 @@ #endif #endif -#ifdef HAVE_CONFIG_H -#include "../config.h" -#else -#define VERSION "0.5.0" +#ifndef VERSION +#define VERSION "0.5.1" #define VERSION_MAJOR 0 #define VERSION_MINOR 5 -#define VERSION_MICRO 0 +#define VERSION_MICRO 1 #endif #include <libvirt/libvirt.h> -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 458 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 371 insertions(+), 87 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 57e1b83..5f330f8 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -70,99 +70,370 @@ ZEND_DECLARE_MODULE_GLOBALS(libvirt) ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_connect, 0, 0, 0) ZEND_ARG_INFO(0, url) ZEND_ARG_INFO(0, readonly) +ZEND_ARG_INFO(0, credentials) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_void, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn, 0, 0, 1) +ZEND_ARG_INFO(0, conn) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_connect_get_capabilities, 0, 0, 1) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, xpath) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_connect_get_emulator, 0, 0, 1) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, arch) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_connect_get_soundhw_models, 0, 0, 1) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, arch) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_connect_get_all_domain_stats, 0, 0, 1) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, stats) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_stream_send, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, data) +ZEND_ARG_INFO(0, len) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_new, 0, 0, 9) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, name) +ZEND_ARG_INFO(0, arch) +ZEND_ARG_INFO(0, memMB) +ZEND_ARG_INFO(0, maxmemMB) +ZEND_ARG_INFO(0, vcpus) +ZEND_ARG_INFO(0, iso) +ZEND_ARG_INFO(0, disks) +ZEND_ARG_INFO(0, networks) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_lookup_by_name, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_change_vcpus, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, numCpus) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_change_memory, 0, 0, 3) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, allocMem) +ZEND_ARG_INFO(0, allocMax) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_change_boot_devices, 0, 0, 3) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, first) +ZEND_ARG_INFO(0, second) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_disk_add, 0, 0, 5) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, img) +ZEND_ARG_INFO(0, dev) +ZEND_ARG_INFO(0, type) +ZEND_ARG_INFO(0, driver) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_disk_remove, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, dev) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_nic_add, 0, 0, 4) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, mac) +ZEND_ARG_INFO(0, network) +ZEND_ARG_INFO(0, model) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_nic_remove, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, dev) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_lookup_by_id, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, id) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_lookup_by_uuid, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, uuid) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_conn_xml, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, xml) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_core_dump, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, to) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn_flags, 0, 0, 1) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_memory_peek, 0, 0, 4) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, start) +ZEND_ARG_INFO(0, size) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_set_memory, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, memory) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_set_memory_flags, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, memory) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn_path, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_block_resize, 0, 0, 3) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, path) +ZEND_ARG_INFO(0, size) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_block_job_abort, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, path) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_block_job_set_speed, 0, 0, 3) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, path) +ZEND_ARG_INFO(0, bandwidth) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_migrate, 0, 0, 3) +ZEND_ARG_INFO(0, res) +ZEND_ARG_INFO(0, dest_conn) +ZEND_ARG_INFO(0, flags) +ZEND_ARG_INFO(0, dname) +ZEND_ARG_INFO(0, bandwidth) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_migrate_to_uri, 0, 0, 3) +ZEND_ARG_INFO(0, res) +ZEND_ARG_INFO(0, dest_uri) +ZEND_ARG_INFO(0, flags) +ZEND_ARG_INFO(0, dname) +ZEND_ARG_INFO(0, bandwidth) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_migrate_to_uri2, 0, 0, 1) +ZEND_ARG_INFO(0, res) +ZEND_ARG_INFO(0, dconn_uri) +ZEND_ARG_INFO(0, mig_uri) +ZEND_ARG_INFO(0, dxml) +ZEND_ARG_INFO(0, flags) +ZEND_ARG_INFO(0, dname) +ZEND_ARG_INFO(0, bandwidth) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_xml_xpath, 0, 0, 2) +ZEND_ARG_INFO(0, res) +ZEND_ARG_INFO(0, xpath) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_get_block_info, 0, 0, 2) +ZEND_ARG_INFO(0, res) +ZEND_ARG_INFO(0, dev) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_get_network_info, 0, 0, 2) +ZEND_ARG_INFO(0, res) +ZEND_ARG_INFO(0, mac) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_set_autostart, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_get_metadata, 0, 0, 4) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, type) +ZEND_ARG_INFO(0, uri) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_set_metadata, 0, 0, 6) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, type) +ZEND_ARG_INFO(0, metadata) +ZEND_ARG_INFO(0, key) +ZEND_ARG_INFO(0, uri) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_get_screenshot, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, server) +ZEND_ARG_INFO(0, scancode) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_get_screenshot_api, 0, 0, 1) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, screenID) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_get_screen_dimensions, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, server) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_send_keys, 0, 0, 3) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, server) +ZEND_ARG_INFO(0, scancode) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_send_pointer_event, 0, 0, 5) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, server) +ZEND_ARG_INFO(0, pos_x) +ZEND_ARG_INFO(0, pox_y) +ZEND_ARG_INFO(0, clicked) +ZEND_ARG_INFO(0, release) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_update_device, 0, 0, 3) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, xml) +ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() static zend_function_entry libvirt_functions[] = { /* Common functions */ - PHP_FE(libvirt_get_last_error,NULL) + PHP_FE(libvirt_get_last_error, arginfo_libvirt_void) /* Connect functions */ - PHP_FE(libvirt_connect, arginfo_libvirt_connect) - PHP_FE(libvirt_connect_get_uri, NULL) - PHP_FE(libvirt_connect_get_hostname, NULL) - PHP_FE(libvirt_connect_get_capabilities, NULL) - PHP_FE(libvirt_connect_get_emulator, NULL) - PHP_FE(libvirt_connect_get_nic_models, NULL) - PHP_FE(libvirt_connect_get_soundhw_models, NULL) - PHP_FE(libvirt_connect_get_information, NULL) - PHP_FE(libvirt_connect_get_machine_types, NULL) - PHP_FE(libvirt_connect_get_hypervisor, NULL) - PHP_FE(libvirt_connect_get_sysinfo, NULL) - PHP_FE(libvirt_connect_get_maxvcpus, NULL) - PHP_FE(libvirt_connect_get_encrypted, NULL) - PHP_FE(libvirt_connect_get_secure, NULL) - PHP_FE(libvirt_connect_get_all_domain_stats, NULL) + PHP_FE(libvirt_connect, arginfo_libvirt_connect) + PHP_FE(libvirt_connect_get_uri, arginfo_libvirt_conn) + PHP_FE(libvirt_connect_get_hostname, arginfo_libvirt_conn) + PHP_FE(libvirt_connect_get_capabilities, arginfo_libvirt_connect_get_capabilities) + PHP_FE(libvirt_connect_get_emulator, arginfo_libvirt_connect_get_emulator) + PHP_FE(libvirt_connect_get_nic_models, arginfo_libvirt_connect_get_emulator) + PHP_FE(libvirt_connect_get_soundhw_models, arginfo_libvirt_connect_get_soundhw_models) + PHP_FE(libvirt_connect_get_information, arginfo_libvirt_conn) + PHP_FE(libvirt_connect_get_machine_types, arginfo_libvirt_conn) + PHP_FE(libvirt_connect_get_hypervisor, arginfo_libvirt_conn) + PHP_FE(libvirt_connect_get_sysinfo, arginfo_libvirt_conn) + PHP_FE(libvirt_connect_get_maxvcpus, arginfo_libvirt_conn) + PHP_FE(libvirt_connect_get_encrypted, arginfo_libvirt_conn) + PHP_FE(libvirt_connect_get_secure, arginfo_libvirt_conn) + PHP_FE(libvirt_connect_get_all_domain_stats, arginfo_libvirt_connect_get_all_domain_stats) /* Stream functions */ - PHP_FE(libvirt_stream_create, NULL) - PHP_FE(libvirt_stream_close, NULL) - PHP_FE(libvirt_stream_abort, NULL) - PHP_FE(libvirt_stream_finish, NULL) - PHP_FE(libvirt_stream_send, NULL) - PHP_FE(libvirt_stream_recv, NULL) + PHP_FE(libvirt_stream_create, arginfo_libvirt_conn) + PHP_FE(libvirt_stream_close, arginfo_libvirt_conn) + PHP_FE(libvirt_stream_abort, arginfo_libvirt_conn) + PHP_FE(libvirt_stream_finish, arginfo_libvirt_conn) + PHP_FE(libvirt_stream_send, arginfo_libvirt_stream_send) + PHP_FE(libvirt_stream_recv, arginfo_libvirt_stream_send) /* Domain functions */ - PHP_FE(libvirt_domain_new, NULL) - PHP_FE(libvirt_domain_new_get_vnc, NULL) - PHP_FE(libvirt_domain_get_counts, NULL) - PHP_FE(libvirt_domain_is_persistent, NULL) - PHP_FE(libvirt_domain_lookup_by_name, NULL) - PHP_FE(libvirt_domain_get_xml_desc, NULL) - PHP_FE(libvirt_domain_get_disk_devices, NULL) - PHP_FE(libvirt_domain_get_interface_devices, NULL) - PHP_FE(libvirt_domain_change_vcpus, NULL) - PHP_FE(libvirt_domain_change_memory, NULL) - PHP_FE(libvirt_domain_change_boot_devices, NULL) - PHP_FE(libvirt_domain_disk_add, NULL) - PHP_FE(libvirt_domain_disk_remove, NULL) - PHP_FE(libvirt_domain_nic_add, NULL) - PHP_FE(libvirt_domain_nic_remove, NULL) - PHP_FE(libvirt_domain_get_info, NULL) - PHP_FE(libvirt_domain_get_name, NULL) - PHP_FE(libvirt_domain_get_uuid, NULL) - PHP_FE(libvirt_domain_get_uuid_string, NULL) - PHP_FE(libvirt_domain_get_id, NULL) - PHP_FE(libvirt_domain_lookup_by_id, NULL) - PHP_FE(libvirt_domain_lookup_by_uuid, NULL) - PHP_FE(libvirt_domain_lookup_by_uuid_string, NULL) - PHP_FE(libvirt_domain_destroy, NULL) - PHP_FE(libvirt_domain_create, NULL) - PHP_FE(libvirt_domain_resume, NULL) - PHP_FE(libvirt_domain_core_dump, NULL) - PHP_FE(libvirt_domain_shutdown, NULL) - PHP_FE(libvirt_domain_suspend, NULL) - PHP_FE(libvirt_domain_managedsave, NULL) - PHP_FE(libvirt_domain_undefine, NULL) - PHP_FE(libvirt_domain_reboot, NULL) - PHP_FE(libvirt_domain_define_xml, NULL) - PHP_FE(libvirt_domain_create_xml, NULL) - PHP_FE(libvirt_domain_memory_peek,NULL) - PHP_FE(libvirt_domain_memory_stats,NULL) - PHP_FE(libvirt_domain_set_memory,NULL) - PHP_FE(libvirt_domain_set_max_memory,NULL) - PHP_FE(libvirt_domain_set_memory_flags,NULL) - PHP_FE(libvirt_domain_block_stats,NULL) - PHP_FE(libvirt_domain_block_resize,NULL) - PHP_FE(libvirt_domain_block_job_abort,NULL) - PHP_FE(libvirt_domain_block_job_set_speed,NULL) - PHP_FE(libvirt_domain_interface_stats,NULL) - PHP_FE(libvirt_domain_get_connect, NULL) - PHP_FE(libvirt_domain_migrate, NULL) - PHP_FE(libvirt_domain_migrate_to_uri, NULL) - PHP_FE(libvirt_domain_migrate_to_uri2, NULL) - PHP_FE(libvirt_domain_get_job_info, NULL) - PHP_FE(libvirt_domain_xml_xpath, NULL) - PHP_FE(libvirt_domain_get_block_info, NULL) - PHP_FE(libvirt_domain_get_network_info, NULL) - PHP_FE(libvirt_domain_get_autostart, NULL) - PHP_FE(libvirt_domain_set_autostart, NULL) - PHP_FE(libvirt_domain_get_metadata, NULL) - PHP_FE(libvirt_domain_set_metadata, NULL) - PHP_FE(libvirt_domain_is_active, NULL) - PHP_FE(libvirt_domain_get_next_dev_ids, NULL) - PHP_FE(libvirt_domain_get_screenshot, NULL) - PHP_FE(libvirt_domain_get_screenshot_api, NULL) - PHP_FE(libvirt_domain_get_screen_dimensions, NULL) - PHP_FE(libvirt_domain_send_keys, NULL) - PHP_FE(libvirt_domain_send_pointer_event, NULL) - PHP_FE(libvirt_domain_update_device, NULL) + PHP_FE(libvirt_domain_new, arginfo_libvirt_domain_new) + PHP_FE(libvirt_domain_new_get_vnc, arginfo_libvirt_void) + PHP_FE(libvirt_domain_get_counts, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_is_persistent, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_lookup_by_name, arginfo_libvirt_domain_lookup_by_name) + PHP_FE(libvirt_domain_get_xml_desc, arginfo_libvirt_connect_get_capabilities) + PHP_FE(libvirt_domain_get_disk_devices, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_get_interface_devices, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_change_vcpus, arginfo_libvirt_domain_change_vcpus) + PHP_FE(libvirt_domain_change_memory, arginfo_libvirt_domain_change_memory) + PHP_FE(libvirt_domain_change_boot_devices, arginfo_libvirt_domain_change_boot_devices) + PHP_FE(libvirt_domain_disk_add, arginfo_libvirt_domain_disk_add) + PHP_FE(libvirt_domain_disk_remove, arginfo_libvirt_domain_disk_remove) + PHP_FE(libvirt_domain_nic_add, arginfo_libvirt_domain_nic_add) + PHP_FE(libvirt_domain_nic_remove, arginfo_libvirt_domain_nic_remove) + PHP_FE(libvirt_domain_get_info, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_get_name, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_get_uuid, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_get_uuid_string, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_get_id, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_lookup_by_id, arginfo_libvirt_domain_lookup_by_id) + PHP_FE(libvirt_domain_lookup_by_uuid, arginfo_libvirt_domain_lookup_by_uuid) + PHP_FE(libvirt_domain_lookup_by_uuid_string, arginfo_libvirt_domain_lookup_by_uuid) + PHP_FE(libvirt_domain_destroy, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_create, arginfo_libvirt_domain_conn_xml) + PHP_FE(libvirt_domain_resume, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_core_dump, arginfo_libvirt_domain_core_dump) + PHP_FE(libvirt_domain_shutdown, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_suspend, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_managedsave, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_undefine, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_reboot, arginfo_libvirt_conn_flags) + PHP_FE(libvirt_domain_define_xml, arginfo_libvirt_domain_conn_xml) + PHP_FE(libvirt_domain_create_xml, arginfo_libvirt_domain_conn_xml) + PHP_FE(libvirt_domain_memory_peek, arginfo_libvirt_domain_memory_peek) + PHP_FE(libvirt_domain_memory_stats, arginfo_libvirt_conn_flags) + PHP_FE(libvirt_domain_set_memory, arginfo_libvirt_domain_set_memory) + PHP_FE(libvirt_domain_set_max_memory, arginfo_libvirt_domain_set_memory) + PHP_FE(libvirt_domain_set_memory_flags, arginfo_libvirt_domain_set_memory_flags) + PHP_FE(libvirt_domain_block_stats, arginfo_libvirt_conn_path) + PHP_FE(libvirt_domain_block_resize, arginfo_libvirt_domain_block_resize) + PHP_FE(libvirt_domain_block_job_abort, arginfo_libvirt_domain_block_job_abort) + PHP_FE(libvirt_domain_block_job_set_speed, arginfo_libvirt_domain_block_job_set_speed) + PHP_FE(libvirt_domain_interface_stats, arginfo_libvirt_conn_path) + PHP_FE(libvirt_domain_get_connect, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_migrate, arginfo_libvirt_domain_migrate) + PHP_FE(libvirt_domain_migrate_to_uri, arginfo_libvirt_domain_migrate_to_uri) + PHP_FE(libvirt_domain_migrate_to_uri2, arginfo_libvirt_domain_migrate_to_uri2) + PHP_FE(libvirt_domain_get_job_info, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_xml_xpath, arginfo_libvirt_domain_xml_xpath) + PHP_FE(libvirt_domain_get_block_info, arginfo_libvirt_domain_get_block_info) + PHP_FE(libvirt_domain_get_network_info, arginfo_libvirt_domain_get_network_info) + PHP_FE(libvirt_domain_get_autostart, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_set_autostart, arginfo_libvirt_domain_set_autostart) + PHP_FE(libvirt_domain_get_metadata, arginfo_libvirt_domain_get_metadata) + PHP_FE(libvirt_domain_set_metadata, arginfo_libvirt_domain_set_metadata) + PHP_FE(libvirt_domain_is_active, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_get_next_dev_ids, arginfo_libvirt_conn) + PHP_FE(libvirt_domain_get_screenshot, arginfo_libvirt_domain_get_screenshot) + PHP_FE(libvirt_domain_get_screenshot_api, arginfo_libvirt_domain_get_screenshot_api) + PHP_FE(libvirt_domain_get_screen_dimensions, arginfo_libvirt_domain_get_screen_dimensions) + PHP_FE(libvirt_domain_send_keys, arginfo_libvirt_domain_send_keys) + PHP_FE(libvirt_domain_send_pointer_event, arginfo_libvirt_domain_send_pointer_event) + PHP_FE(libvirt_domain_update_device, arginfo_libvirt_domain_update_device) /* Domain snapshot functions */ PHP_FE(libvirt_domain_has_current_snapshot, NULL) PHP_FE(libvirt_domain_snapshot_create, NULL) @@ -245,7 +516,11 @@ static zend_function_entry libvirt_functions[] = { PHP_FE(libvirt_print_binding_resources, NULL) /* Agent functions */ PHP_FE(libvirt_domain_qemu_agent_command, NULL) +#ifdef PHP_FE_END + PHP_FE_END +#else {NULL, NULL, NULL} +#endif }; @@ -5166,6 +5441,7 @@ PHP_FUNCTION(libvirt_domain_change_vcpus) * Arguments: @res [resource]: libvirt domain resource * @allocMem [int]: number of MiBs to be set as immediate memory value * @allocMax [int]: number of MiBs to be set as the maximum allocation + * @flags [int]: flags * Returns: new domain resource */ PHP_FUNCTION(libvirt_domain_change_memory) @@ -5246,6 +5522,7 @@ PHP_FUNCTION(libvirt_domain_change_memory) * Arguments: @res [resource]: libvirt domain resource * @first [string]: first boot device to be set * @second [string]: second boot device to be set + * @flags [int]: flags * Returns: new domain resource */ PHP_FUNCTION(libvirt_domain_change_boot_devices) @@ -5751,6 +6028,7 @@ PHP_FUNCTION(libvirt_domain_resume) * Since version: 0.4.1(-2) * Description: Function is used to dump core of the domain identified by it's resource * Arguments: @res [resource]: libvirt domain resource, e.g. from libvirt_domain_lookup_by_*() + * @to [string]: to * Returns: TRUE for success, FALSE on error */ PHP_FUNCTION(libvirt_domain_core_dump) @@ -5857,6 +6135,7 @@ PHP_FUNCTION(libvirt_domain_undefine) * Since version: 0.4.1(-1) * Description: Function is used to reboot the domain identified by it's resource * Arguments: @res [resource]: libvirt domain resource, e.g. from libvirt_domain_lookup_by_*() + * @flags [int]: optional flags * Returns: TRUE for success, FALSE on error */ PHP_FUNCTION(libvirt_domain_reboot) @@ -5943,6 +6222,9 @@ PHP_FUNCTION(libvirt_domain_create_xml) * Since version: 0.4.1(-1) * Description: Function is used to get the domain's memory peek value * Arguments: @res [resource]: libvirt domain resource, e.g. from libvirt_domain_lookup_by_*() + * @start [int]: start + * @size [int]: size + * @flags [int]: optional flags * Returns: domain memory peek */ PHP_FUNCTION(libvirt_domain_memory_peek) @@ -5951,7 +6233,7 @@ PHP_FUNCTION(libvirt_domain_memory_peek) zval *zdomain; int retval; long flags=0; - long long start; + long start; long size; char *buff; @@ -5967,6 +6249,7 @@ PHP_FUNCTION(libvirt_domain_memory_peek) * Since version: 0.4.1(-1) * Description: Function is used to get the domain's memory stats * Arguments: @res [resource]: libvirt domain resource, e.g. from libvirt_domain_lookup_by_*() + * @flags [int]: optional flags * Returns: domain memory stats array (same fields as virDomainMemoryStats, please see libvirt documentation) */ PHP_FUNCTION(libvirt_domain_memory_stats) @@ -6319,6 +6602,7 @@ PHP_FUNCTION(libvirt_domain_get_block_info) * Description: Function is used to get the result of xPath expression that's run against the domain * Arguments: @res [resource]: libvirt domain resource, e.g. from libvirt_domain_lookup_by_*() * @xpath [string]: xPath expression to parse against the domain + * @flags [int]: optional flags * Returns: result of the expression in an array */ PHP_FUNCTION(libvirt_domain_xml_xpath) -- 2.5.5

On 09.04.2016 00:08, Neal Gompa wrote:
From: Remi Collet <fedora@famillecollet.com>
--- src/libvirt-php.c | 458 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 371 insertions(+), 87 deletions(-)
This is not rebased onto current HEAD. Michal

On Tue, Apr 12, 2016 at 11:13 AM, Michal Privoznik <mprivozn@redhat.com> wrote:
This is not rebased onto current HEAD.
Michal
Hello Michal, I've rebased the patch set on the current HEAD as well as done some patch squashing to reduce the number of patches[1]. Would you like for me to resend the patch set based on top of the current HEAD? [1]: https://gitlab.com/Conan_Kudo/libvirt-php7/compare/master...php7-review -- 真実はいつも一つ!/ Always, there's only one truth!

From: Remi Collet <fedora@famillecollet.com> --- install-sh | 366 +++++++++++++++++++++++++++++++--------------------------- missing | 2 +- src/config.m4 | 12 +- 3 files changed, 204 insertions(+), 176 deletions(-) diff --git a/install-sh b/install-sh index 0b0fdcb..377bb86 100755 --- a/install-sh +++ b/install-sh @@ -1,7 +1,7 @@ #!/bin/sh # install - install a program, script, or datafile -scriptversion=2013-12-25.23; # UTC +scriptversion=2011-11-20.07; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the @@ -41,15 +41,19 @@ scriptversion=2013-12-25.23; # UTC # This script is compatible with the BSD install script, but was written # from scratch. -tab=' ' nl=' ' -IFS=" $tab$nl" +IFS=" "" $nl" -# Set DOITPROG to "echo" to test this script. +# set DOITPROG to echo to test this script +# Don't use :- since 4.3BSD and earlier shells don't like it. doit=${DOITPROG-} -doit_exec=${doit:-exec} +if test -z "$doit"; then + doit_exec=exec +else + doit_exec=$doit +fi # Put in absolute file names if you don't have them in your path; # or use environment vars. @@ -64,6 +68,17 @@ mvprog=${MVPROG-mv} rmprog=${RMPROG-rm} stripprog=${STRIPPROG-strip} +posix_glob='?' +initialize_posix_glob=' + test "$posix_glob" != "?" || { + if (set -f) 2>/dev/null; then + posix_glob= + else + posix_glob=: + fi + } +' + posix_mkdir= # Desired mode of installed file. @@ -82,7 +97,7 @@ dir_arg= dst_arg= copy_on_change=false -is_target_a_directory=possibly +no_target_directory= usage="\ Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE @@ -122,57 +137,46 @@ while test $# -ne 0; do -d) dir_arg=true;; -g) chgrpcmd="$chgrpprog $2" - shift;; + shift;; --help) echo "$usage"; exit $?;; -m) mode=$2 - case $mode in - *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) - echo "$0: invalid mode: $mode" >&2 - exit 1;; - esac - shift;; + case $mode in + *' '* | *' '* | *' +'* | *'*'* | *'?'* | *'['*) + echo "$0: invalid mode: $mode" >&2 + exit 1;; + esac + shift;; -o) chowncmd="$chownprog $2" - shift;; + shift;; -s) stripcmd=$stripprog;; - -t) - is_target_a_directory=always - dst_arg=$2 - # Protect names problematic for 'test' and other utilities. - case $dst_arg in - -* | [=\(\)!]) dst_arg=./$dst_arg;; - esac - shift;; + -t) dst_arg=$2 + # Protect names problematic for 'test' and other utilities. + case $dst_arg in + -* | [=\(\)!]) dst_arg=./$dst_arg;; + esac + shift;; - -T) is_target_a_directory=never;; + -T) no_target_directory=true;; --version) echo "$0 $scriptversion"; exit $?;; - --) shift - break;; + --) shift + break;; - -*) echo "$0: invalid option: $1" >&2 - exit 1;; + -*) echo "$0: invalid option: $1" >&2 + exit 1;; *) break;; esac shift done -# We allow the use of options -d and -T together, by making -d -# take the precedence; this is for compatibility with GNU install. - -if test -n "$dir_arg"; then - if test -n "$dst_arg"; then - echo "$0: target directory not allowed when installing a directory." >&2 - exit 1 - fi -fi - if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then # When -d is used, all remaining arguments are directories to create. # When -t is used, the destination is already specified. @@ -204,15 +208,6 @@ if test $# -eq 0; then fi if test -z "$dir_arg"; then - if test $# -gt 1 || test "$is_target_a_directory" = always; then - if test ! -d "$dst_arg"; then - echo "$0: $dst_arg: Is not a directory." >&2 - exit 1 - fi - fi -fi - -if test -z "$dir_arg"; then do_exit='(exit $ret); exit $ret' trap "ret=129; $do_exit" 1 trap "ret=130; $do_exit" 2 @@ -228,16 +223,16 @@ if test -z "$dir_arg"; then *[0-7]) if test -z "$stripcmd"; then - u_plus_rw= + u_plus_rw= else - u_plus_rw='% 200' + u_plus_rw='% 200' fi cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; *) if test -z "$stripcmd"; then - u_plus_rw= + u_plus_rw= else - u_plus_rw=,u+rw + u_plus_rw=,u+rw fi cp_umask=$mode$u_plus_rw;; esac @@ -274,15 +269,41 @@ do # If destination is a directory, append the input filename; won't work # if double slashes aren't ignored. if test -d "$dst"; then - if test "$is_target_a_directory" = never; then - echo "$0: $dst_arg: Is a directory" >&2 - exit 1 + if test -n "$no_target_directory"; then + echo "$0: $dst_arg: Is a directory" >&2 + exit 1 fi dstdir=$dst dst=$dstdir/`basename "$src"` dstdir_status=0 else - dstdir=`dirname "$dst"` + # Prefer dirname, but fall back on a substitute if dirname fails. + dstdir=` + (dirname "$dst") 2>/dev/null || + expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$dst" : 'X\(//\)[^/]' \| \ + X"$dst" : 'X\(//\)$' \| \ + X"$dst" : 'X\(/\)' \| . 2>/dev/null || + echo X"$dst" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q' + ` + test -d "$dstdir" dstdir_status=$? fi @@ -293,74 +314,74 @@ do if test $dstdir_status != 0; then case $posix_mkdir in '') - # Create intermediate dirs using mode 755 as modified by the umask. - # This is like FreeBSD 'install' as of 1997-10-28. - umask=`umask` - case $stripcmd.$umask in - # Optimize common cases. - *[2367][2367]) mkdir_umask=$umask;; - .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; - - *[0-7]) - mkdir_umask=`expr $umask + 22 \ - - $umask % 100 % 40 + $umask % 20 \ - - $umask % 10 % 4 + $umask % 2 - `;; - *) mkdir_umask=$umask,go-w;; - esac - - # With -d, create the new directory with the user-specified mode. - # Otherwise, rely on $mkdir_umask. - if test -n "$dir_arg"; then - mkdir_mode=-m$mode - else - mkdir_mode= - fi - - posix_mkdir=false - case $umask in - *[123567][0-7][0-7]) - # POSIX mkdir -p sets u+wx bits regardless of umask, which - # is incompatible with FreeBSD 'install' when (umask & 300) != 0. - ;; - *) - tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ - trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 - - if (umask $mkdir_umask && - exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 - then - if test -z "$dir_arg" || { - # Check for POSIX incompatibilities with -m. - # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or - # other-writable bit of parent directory when it shouldn't. - # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. - ls_ld_tmpdir=`ls -ld "$tmpdir"` - case $ls_ld_tmpdir in - d????-?r-*) different_mode=700;; - d????-?--*) different_mode=755;; - *) false;; - esac && - $mkdirprog -m$different_mode -p -- "$tmpdir" && { - ls_ld_tmpdir_1=`ls -ld "$tmpdir"` - test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" - } - } - then posix_mkdir=: - fi - rmdir "$tmpdir/d" "$tmpdir" - else - # Remove any dirs left behind by ancient mkdir implementations. - rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null - fi - trap '' 0;; - esac;; + # Create intermediate dirs using mode 755 as modified by the umask. + # This is like FreeBSD 'install' as of 1997-10-28. + umask=`umask` + case $stripcmd.$umask in + # Optimize common cases. + *[2367][2367]) mkdir_umask=$umask;; + .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; + + *[0-7]) + mkdir_umask=`expr $umask + 22 \ + - $umask % 100 % 40 + $umask % 20 \ + - $umask % 10 % 4 + $umask % 2 + `;; + *) mkdir_umask=$umask,go-w;; + esac + + # With -d, create the new directory with the user-specified mode. + # Otherwise, rely on $mkdir_umask. + if test -n "$dir_arg"; then + mkdir_mode=-m$mode + else + mkdir_mode= + fi + + posix_mkdir=false + case $umask in + *[123567][0-7][0-7]) + # POSIX mkdir -p sets u+wx bits regardless of umask, which + # is incompatible with FreeBSD 'install' when (umask & 300) != 0. + ;; + *) + tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ + trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 + + if (umask $mkdir_umask && + exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 + then + if test -z "$dir_arg" || { + # Check for POSIX incompatibilities with -m. + # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or + # other-writable bit of parent directory when it shouldn't. + # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. + ls_ld_tmpdir=`ls -ld "$tmpdir"` + case $ls_ld_tmpdir in + d????-?r-*) different_mode=700;; + d????-?--*) different_mode=755;; + *) false;; + esac && + $mkdirprog -m$different_mode -p -- "$tmpdir" && { + ls_ld_tmpdir_1=`ls -ld "$tmpdir"` + test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" + } + } + then posix_mkdir=: + fi + rmdir "$tmpdir/d" "$tmpdir" + else + # Remove any dirs left behind by ancient mkdir implementations. + rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null + fi + trap '' 0;; + esac;; esac if $posix_mkdir && ( - umask $mkdir_umask && - $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" + umask $mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" ) then : else @@ -370,51 +391,53 @@ do # directory the slow way, step by step, checking for races as we go. case $dstdir in - /*) prefix='/';; - [-=\(\)!]*) prefix='./';; - *) prefix='';; + /*) prefix='/';; + [-=\(\)!]*) prefix='./';; + *) prefix='';; esac + eval "$initialize_posix_glob" + oIFS=$IFS IFS=/ - set -f + $posix_glob set -f set fnord $dstdir shift - set +f + $posix_glob set +f IFS=$oIFS prefixes= for d do - test X"$d" = X && continue - - prefix=$prefix$d - if test -d "$prefix"; then - prefixes= - else - if $posix_mkdir; then - (umask=$mkdir_umask && - $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break - # Don't fail if two instances are running concurrently. - test -d "$prefix" || exit 1 - else - case $prefix in - *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; - *) qprefix=$prefix;; - esac - prefixes="$prefixes '$qprefix'" - fi - fi - prefix=$prefix/ + test X"$d" = X && continue + + prefix=$prefix$d + if test -d "$prefix"; then + prefixes= + else + if $posix_mkdir; then + (umask=$mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break + # Don't fail if two instances are running concurrently. + test -d "$prefix" || exit 1 + else + case $prefix in + *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; + *) qprefix=$prefix;; + esac + prefixes="$prefixes '$qprefix'" + fi + fi + prefix=$prefix/ done if test -n "$prefixes"; then - # Don't fail if two instances are running concurrently. - (umask $mkdir_umask && - eval "\$doit_exec \$mkdirprog $prefixes") || - test -d "$dstdir" || exit 1 - obsolete_mkdir_used=true + # Don't fail if two instances are running concurrently. + (umask $mkdir_umask && + eval "\$doit_exec \$mkdirprog $prefixes") || + test -d "$dstdir" || exit 1 + obsolete_mkdir_used=true fi fi fi @@ -449,12 +472,15 @@ do # If -C, don't bother to copy if it wouldn't change the file. if $copy_on_change && - old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && - new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && - set -f && + old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && + new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && + + eval "$initialize_posix_glob" && + $posix_glob set -f && set X $old && old=:$2:$4:$5:$6 && set X $new && new=:$2:$4:$5:$6 && - set +f && + $posix_glob set +f && + test "$old" = "$new" && $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 then @@ -467,24 +493,24 @@ do # to itself, or perhaps because mv is so ancient that it does not # support -f. { - # Now remove or move aside any old file at destination location. - # We try this two ways since rm can't unlink itself on some - # systems and the destination file might be busy for other - # reasons. In this case, the final cleanup might fail but the new - # file should still install successfully. - { - test ! -f "$dst" || - $doit $rmcmd -f "$dst" 2>/dev/null || - { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && - { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } - } || - { echo "$0: cannot unlink or rename $dst" >&2 - (exit 1); exit 1 - } - } && - - # Now rename the file to the real destination. - $doit $mvcmd "$dsttmp" "$dst" + # Now remove or move aside any old file at destination location. + # We try this two ways since rm can't unlink itself on some + # systems and the destination file might be busy for other + # reasons. In this case, the final cleanup might fail but the new + # file should still install successfully. + { + test ! -f "$dst" || + $doit $rmcmd -f "$dst" 2>/dev/null || + { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && + { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } + } || + { echo "$0: cannot unlink or rename $dst" >&2 + (exit 1); exit 1 + } + } && + + # Now rename the file to the real destination. + $doit $mvcmd "$dsttmp" "$dst" } fi || exit 1 diff --git a/missing b/missing index f62bbae..db98974 100755 --- a/missing +++ b/missing @@ -3,7 +3,7 @@ scriptversion=2013-10-28.13; # UTC -# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# Copyright (C) 1996-2013 Free Software Foundation, Inc. # Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996. # This program is free software; you can redistribute it and/or modify diff --git a/src/config.m4 b/src/config.m4 index d255f77..239329f 100644 --- a/src/config.m4 +++ b/src/config.m4 @@ -1,13 +1,15 @@ PHP_ARG_WITH(libvirt, for libvirt support, -[ --with-libvirt Include varnish support]) +[ --with-libvirt Include libvirt support]) if test "$PHP_LIBVIRT" != "no"; then AC_PATH_PROG(PKG_CONFIG, pkg-config, no) - if test -x "$PKG_CONFIG" && $PKG_CONFIG varnishapi --exists ; then + LIBVIRT_REQUIRED=1.2.8 + + if test -x "$PKG_CONFIG" && $PKG_CONFIG libvirt --exists ; then AC_MSG_CHECKING(libvirt version) - if $PKG_CONFIG libvirt --atleast-version=1.2.8 ; then + if $PKG_CONFIG libvirt --atleast-version=$LIBVIRT_REQUIRED ; then LIBVIRT_INCLUDE=`$PKG_CONFIG libvirt --cflags` LIBVIRT_LIBRARY=`$PKG_CONFIG libvirt --libs` LIBVIRT_VERSION=`$PKG_CONFIG libvirt --modversion` @@ -19,7 +21,7 @@ if test "$PHP_LIBVIRT" != "no"; then PHP_EVAL_LIBLINE($LIBVIRT_LIBRARY, LIBVIRT_SHARED_LIBADD) AC_MSG_CHECKING(libvirt-qemu version) - if $PKG_CONFIG libvirt-qemu --atleast-version=1.2.8 ; then + if $PKG_CONFIG libvirt-qemu --atleast-version=$LIBVIRT_REQUIRED ; then QEMU_INCLUDE=`$PKG_CONFIG libvirt-qemu --cflags` QEMU_LIBRARY=`$PKG_CONFIG libvirt-qemu --libs` QEMU_VERSION=`$PKG_CONFIG libvirt-qemu --modversion` @@ -31,7 +33,7 @@ if test "$PHP_LIBVIRT" != "no"; then PHP_EVAL_LIBLINE($QEMU_LIBRARY, LIBVIRT_SHARED_LIBADD) AC_MSG_CHECKING(libxml version) - if $PKG_CONFIG libxml-2.0 --atleast-version=1.2.8 ; then + if $PKG_CONFIG libxml-2.0 --exists ; then LIBXML_INCLUDE=`$PKG_CONFIG libxml-2.0 --cflags` LIBXML_LIBRARY=`$PKG_CONFIG libxml-2.0 --libs` LIBXML_VERSION=`$PKG_CONFIG libxml-2.0 --modversion` -- 2.5.5

On 09.04.2016 00:08, Neal Gompa wrote:
From: Remi Collet <fedora@famillecollet.com>
--- install-sh | 366 +++++++++++++++++++++++++++++++--------------------------- missing | 2 +- src/config.m4 | 12 +- 3 files changed, 204 insertions(+), 176 deletions(-)
This looks very suspicious. Why is install-sh and missing updated then? Moreover, this should have been merged into 01/35. You just don't send a broken patch in a series followed by its fix in the very same patchset. But this should not be directed at you, Neal. Michal

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 287 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 198 insertions(+), 89 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 5f330f8..47893b2 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -80,7 +80,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn, 0, 0, 1) ZEND_ARG_INFO(0, conn) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_connect_get_capabilities, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn_xpath, 0, 0, 1) ZEND_ARG_INFO(0, conn) ZEND_ARG_INFO(0, xpath) ZEND_END_ARG_INFO() @@ -121,11 +121,6 @@ ZEND_ARG_INFO(0, networks) ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_lookup_by_name, 0, 0, 2) -ZEND_ARG_INFO(0, conn) -ZEND_ARG_INFO(0, name) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_change_vcpus, 0, 0, 2) ZEND_ARG_INFO(0, conn) ZEND_ARG_INFO(0, numCpus) @@ -180,12 +175,12 @@ ZEND_ARG_INFO(0, conn) ZEND_ARG_INFO(0, id) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_lookup_by_uuid, 0, 0, 2) +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn_uuid, 0, 0, 2) ZEND_ARG_INFO(0, conn) ZEND_ARG_INFO(0, uuid) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_conn_xml, 0, 0, 2) +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn_xml, 0, 0, 2) ZEND_ARG_INFO(0, conn) ZEND_ARG_INFO(0, xml) ZEND_END_ARG_INFO() @@ -343,6 +338,117 @@ ZEND_ARG_INFO(0, xml) ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn_optflags, 0, 0, 1) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_snapshot_lookup_by_name, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, name) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn_name, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_storagevolume_lookup_by_path, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_storagevolume_get_xml_desc, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, xpath) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_storagevolume_create_xml_from, 0, 0, 3) +ZEND_ARG_INFO(0, pool) +ZEND_ARG_INFO(0, xml) +ZEND_ARG_INFO(0, original_volume) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_storagevolume_download, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, stream) +ZEND_ARG_INFO(0, offset) +ZEND_ARG_INFO(0, length) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_storagevolume_resize, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, capacity) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_storagepool_define_xml, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, xml) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn_optcpunr, 0, 0, 1) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, cpunr) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn_opttime, 0, 0, 1) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, time) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn_optcap, 0, 0, 1) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, cap) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_opttype, 0, 0, 0) +ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_check_version, 0, 0, 3) +ZEND_ARG_INFO(0, major) +ZEND_ARG_INFO(0, minor) +ZEND_ARG_INFO(0, micro) +ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_name, 0, 0, 1) +ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_optpath, 0, 0, 0) +ZEND_ARG_INFO(0, path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_image_create, 0, 0, 4) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, name) +ZEND_ARG_INFO(0, size) +ZEND_ARG_INFO(0, format) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn_image, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, image) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_logfile_set, 0, 0, 1) +ZEND_ARG_INFO(0, filename) +ZEND_ARG_INFO(0, maxsize) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_qemu_agent_command, 0, 0, 2) +ZEND_ARG_INFO(0, conn) +ZEND_ARG_INFO(0, cmd) +ZEND_ARG_INFO(0, timeout) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + static zend_function_entry libvirt_functions[] = { /* Common functions */ PHP_FE(libvirt_get_last_error, arginfo_libvirt_void) @@ -350,7 +456,7 @@ static zend_function_entry libvirt_functions[] = { PHP_FE(libvirt_connect, arginfo_libvirt_connect) PHP_FE(libvirt_connect_get_uri, arginfo_libvirt_conn) PHP_FE(libvirt_connect_get_hostname, arginfo_libvirt_conn) - PHP_FE(libvirt_connect_get_capabilities, arginfo_libvirt_connect_get_capabilities) + PHP_FE(libvirt_connect_get_capabilities, arginfo_libvirt_conn_xpath) PHP_FE(libvirt_connect_get_emulator, arginfo_libvirt_connect_get_emulator) PHP_FE(libvirt_connect_get_nic_models, arginfo_libvirt_connect_get_emulator) PHP_FE(libvirt_connect_get_soundhw_models, arginfo_libvirt_connect_get_soundhw_models) @@ -374,8 +480,8 @@ static zend_function_entry libvirt_functions[] = { PHP_FE(libvirt_domain_new_get_vnc, arginfo_libvirt_void) PHP_FE(libvirt_domain_get_counts, arginfo_libvirt_conn) PHP_FE(libvirt_domain_is_persistent, arginfo_libvirt_conn) - PHP_FE(libvirt_domain_lookup_by_name, arginfo_libvirt_domain_lookup_by_name) - PHP_FE(libvirt_domain_get_xml_desc, arginfo_libvirt_connect_get_capabilities) + PHP_FE(libvirt_domain_lookup_by_name, arginfo_libvirt_conn_name) + PHP_FE(libvirt_domain_get_xml_desc, arginfo_libvirt_conn_xpath) PHP_FE(libvirt_domain_get_disk_devices, arginfo_libvirt_conn) PHP_FE(libvirt_domain_get_interface_devices, arginfo_libvirt_conn) PHP_FE(libvirt_domain_change_vcpus, arginfo_libvirt_domain_change_vcpus) @@ -391,10 +497,10 @@ static zend_function_entry libvirt_functions[] = { PHP_FE(libvirt_domain_get_uuid_string, arginfo_libvirt_conn) PHP_FE(libvirt_domain_get_id, arginfo_libvirt_conn) PHP_FE(libvirt_domain_lookup_by_id, arginfo_libvirt_domain_lookup_by_id) - PHP_FE(libvirt_domain_lookup_by_uuid, arginfo_libvirt_domain_lookup_by_uuid) - PHP_FE(libvirt_domain_lookup_by_uuid_string, arginfo_libvirt_domain_lookup_by_uuid) + PHP_FE(libvirt_domain_lookup_by_uuid, arginfo_libvirt_conn_uuid) + PHP_FE(libvirt_domain_lookup_by_uuid_string, arginfo_libvirt_conn_uuid) PHP_FE(libvirt_domain_destroy, arginfo_libvirt_conn) - PHP_FE(libvirt_domain_create, arginfo_libvirt_domain_conn_xml) + PHP_FE(libvirt_domain_create, arginfo_libvirt_conn_xml) PHP_FE(libvirt_domain_resume, arginfo_libvirt_conn) PHP_FE(libvirt_domain_core_dump, arginfo_libvirt_domain_core_dump) PHP_FE(libvirt_domain_shutdown, arginfo_libvirt_conn) @@ -402,8 +508,8 @@ static zend_function_entry libvirt_functions[] = { PHP_FE(libvirt_domain_managedsave, arginfo_libvirt_conn) PHP_FE(libvirt_domain_undefine, arginfo_libvirt_conn) PHP_FE(libvirt_domain_reboot, arginfo_libvirt_conn_flags) - PHP_FE(libvirt_domain_define_xml, arginfo_libvirt_domain_conn_xml) - PHP_FE(libvirt_domain_create_xml, arginfo_libvirt_domain_conn_xml) + PHP_FE(libvirt_domain_define_xml, arginfo_libvirt_conn_xml) + PHP_FE(libvirt_domain_create_xml, arginfo_libvirt_conn_xml) PHP_FE(libvirt_domain_memory_peek, arginfo_libvirt_domain_memory_peek) PHP_FE(libvirt_domain_memory_stats, arginfo_libvirt_conn_flags) PHP_FE(libvirt_domain_set_memory, arginfo_libvirt_domain_set_memory) @@ -435,87 +541,87 @@ static zend_function_entry libvirt_functions[] = { PHP_FE(libvirt_domain_send_pointer_event, arginfo_libvirt_domain_send_pointer_event) PHP_FE(libvirt_domain_update_device, arginfo_libvirt_domain_update_device) /* Domain snapshot functions */ - PHP_FE(libvirt_domain_has_current_snapshot, NULL) - PHP_FE(libvirt_domain_snapshot_create, NULL) - PHP_FE(libvirt_domain_snapshot_get_xml, NULL) - PHP_FE(libvirt_domain_snapshot_revert, NULL) - PHP_FE(libvirt_domain_snapshot_delete, NULL) - PHP_FE(libvirt_domain_snapshot_lookup_by_name, NULL) + PHP_FE(libvirt_domain_has_current_snapshot, arginfo_libvirt_conn_optflags) + PHP_FE(libvirt_domain_snapshot_create, arginfo_libvirt_conn_optflags) + PHP_FE(libvirt_domain_snapshot_get_xml, arginfo_libvirt_conn_optflags) + PHP_FE(libvirt_domain_snapshot_revert, arginfo_libvirt_conn_optflags) + PHP_FE(libvirt_domain_snapshot_delete, arginfo_libvirt_conn_optflags) + PHP_FE(libvirt_domain_snapshot_lookup_by_name, arginfo_libvirt_domain_snapshot_lookup_by_name) /* Storagepool functions */ - PHP_FE(libvirt_storagepool_lookup_by_name,NULL) - PHP_FE(libvirt_storagepool_lookup_by_volume,NULL) - PHP_FE(libvirt_storagepool_get_info,NULL) - PHP_FE(libvirt_storagevolume_lookup_by_name,NULL) - PHP_FE(libvirt_storagevolume_lookup_by_path,NULL) - PHP_FE(libvirt_storagevolume_get_name,NULL) - PHP_FE(libvirt_storagevolume_get_path,NULL) - PHP_FE(libvirt_storagevolume_get_info,NULL) - PHP_FE(libvirt_storagevolume_get_xml_desc,NULL) - PHP_FE(libvirt_storagevolume_create_xml,NULL) - PHP_FE(libvirt_storagevolume_create_xml_from,NULL) - PHP_FE(libvirt_storagevolume_delete,NULL) - PHP_FE(libvirt_storagevolume_download,NULL) - PHP_FE(libvirt_storagevolume_upload,NULL) - PHP_FE(libvirt_storagevolume_resize,NULL) - PHP_FE(libvirt_storagepool_get_uuid_string, NULL) - PHP_FE(libvirt_storagepool_get_name, NULL) - PHP_FE(libvirt_storagepool_lookup_by_uuid_string, NULL) - PHP_FE(libvirt_storagepool_get_xml_desc, NULL) - PHP_FE(libvirt_storagepool_define_xml, NULL) - PHP_FE(libvirt_storagepool_undefine, NULL) - PHP_FE(libvirt_storagepool_create, NULL) - PHP_FE(libvirt_storagepool_destroy, NULL) - PHP_FE(libvirt_storagepool_is_active, NULL) - PHP_FE(libvirt_storagepool_get_volume_count, NULL) - PHP_FE(libvirt_storagepool_refresh, NULL) - PHP_FE(libvirt_storagepool_set_autostart, NULL) - PHP_FE(libvirt_storagepool_get_autostart, NULL) - PHP_FE(libvirt_storagepool_build, NULL) - PHP_FE(libvirt_storagepool_delete, NULL) + PHP_FE(libvirt_storagepool_lookup_by_name, arginfo_libvirt_conn_name) + PHP_FE(libvirt_storagepool_lookup_by_volume, arginfo_libvirt_conn) + PHP_FE(libvirt_storagepool_get_info, arginfo_libvirt_conn) + PHP_FE(libvirt_storagevolume_lookup_by_name, arginfo_libvirt_conn_name) + PHP_FE(libvirt_storagevolume_lookup_by_path, arginfo_libvirt_storagevolume_lookup_by_path) + PHP_FE(libvirt_storagevolume_get_name, arginfo_libvirt_conn) + PHP_FE(libvirt_storagevolume_get_path, arginfo_libvirt_conn) + PHP_FE(libvirt_storagevolume_get_info, arginfo_libvirt_conn) + PHP_FE(libvirt_storagevolume_get_xml_desc, arginfo_libvirt_storagevolume_get_xml_desc) + PHP_FE(libvirt_storagevolume_create_xml, arginfo_libvirt_conn_xml) + PHP_FE(libvirt_storagevolume_create_xml_from,arginfo_libvirt_storagevolume_create_xml_from) + PHP_FE(libvirt_storagevolume_delete, arginfo_libvirt_conn_optflags) + PHP_FE(libvirt_storagevolume_download, arginfo_libvirt_storagevolume_download) + PHP_FE(libvirt_storagevolume_upload, arginfo_libvirt_storagevolume_download) + PHP_FE(libvirt_storagevolume_resize, arginfo_libvirt_storagevolume_resize) + PHP_FE(libvirt_storagepool_get_uuid_string, arginfo_libvirt_conn) + PHP_FE(libvirt_storagepool_get_name, arginfo_libvirt_conn) + PHP_FE(libvirt_storagepool_lookup_by_uuid_string, arginfo_libvirt_conn_uuid) + PHP_FE(libvirt_storagepool_get_xml_desc, arginfo_libvirt_conn_xpath) + PHP_FE(libvirt_storagepool_define_xml, arginfo_libvirt_storagepool_define_xml) + PHP_FE(libvirt_storagepool_undefine, arginfo_libvirt_conn) + PHP_FE(libvirt_storagepool_create, arginfo_libvirt_conn) + PHP_FE(libvirt_storagepool_destroy, arginfo_libvirt_conn) + PHP_FE(libvirt_storagepool_is_active, arginfo_libvirt_conn) + PHP_FE(libvirt_storagepool_get_volume_count, arginfo_libvirt_conn) + PHP_FE(libvirt_storagepool_refresh, arginfo_libvirt_conn_optflags) + PHP_FE(libvirt_storagepool_set_autostart, arginfo_libvirt_conn_flags) + PHP_FE(libvirt_storagepool_get_autostart, arginfo_libvirt_conn) + PHP_FE(libvirt_storagepool_build, arginfo_libvirt_conn) + PHP_FE(libvirt_storagepool_delete, arginfo_libvirt_conn) /* Network functions */ - PHP_FE(libvirt_network_define_xml, NULL) - PHP_FE(libvirt_network_undefine, NULL) - PHP_FE(libvirt_network_get, NULL) - PHP_FE(libvirt_network_get_xml_desc, NULL) - PHP_FE(libvirt_network_get_bridge, NULL) - PHP_FE(libvirt_network_get_information, NULL) - PHP_FE(libvirt_network_get_active, NULL) - PHP_FE(libvirt_network_set_active, NULL) + PHP_FE(libvirt_network_define_xml, arginfo_libvirt_conn_xml) + PHP_FE(libvirt_network_undefine, arginfo_libvirt_conn) + PHP_FE(libvirt_network_get, arginfo_libvirt_conn_name) + PHP_FE(libvirt_network_get_xml_desc, arginfo_libvirt_conn_xpath) + PHP_FE(libvirt_network_get_bridge, arginfo_libvirt_conn) + PHP_FE(libvirt_network_get_information, arginfo_libvirt_conn) + PHP_FE(libvirt_network_get_active, arginfo_libvirt_conn) + PHP_FE(libvirt_network_set_active, arginfo_libvirt_conn_flags) /* Node functions */ - PHP_FE(libvirt_node_get_info, NULL) - PHP_FE(libvirt_node_get_cpu_stats, NULL) - PHP_FE(libvirt_node_get_cpu_stats_for_each_cpu, NULL) - PHP_FE(libvirt_node_get_mem_stats, NULL) + PHP_FE(libvirt_node_get_info, arginfo_libvirt_conn) + PHP_FE(libvirt_node_get_cpu_stats, arginfo_libvirt_conn_optcpunr) + PHP_FE(libvirt_node_get_cpu_stats_for_each_cpu, arginfo_libvirt_conn_opttime) + PHP_FE(libvirt_node_get_mem_stats, arginfo_libvirt_conn) /* Nodedev functions */ - PHP_FE(libvirt_nodedev_get, NULL) - PHP_FE(libvirt_nodedev_capabilities, NULL) - PHP_FE(libvirt_nodedev_get_xml_desc, NULL) - PHP_FE(libvirt_nodedev_get_information, NULL) + PHP_FE(libvirt_nodedev_get, arginfo_libvirt_conn) + PHP_FE(libvirt_nodedev_capabilities, arginfo_libvirt_conn) + PHP_FE(libvirt_nodedev_get_xml_desc, arginfo_libvirt_conn_xpath) + PHP_FE(libvirt_nodedev_get_information, arginfo_libvirt_conn) /* List functions */ - PHP_FE(libvirt_list_domains, NULL) - PHP_FE(libvirt_list_domain_snapshots, NULL) - PHP_FE(libvirt_list_domain_resources, NULL) - PHP_FE(libvirt_list_nodedevs, NULL) - PHP_FE(libvirt_list_networks,NULL) - PHP_FE(libvirt_list_storagepools,NULL) - PHP_FE(libvirt_list_active_storagepools,NULL) - PHP_FE(libvirt_list_inactive_storagepools,NULL) - PHP_FE(libvirt_storagepool_list_volumes,NULL) - PHP_FE(libvirt_list_active_domains, NULL) - PHP_FE(libvirt_list_active_domain_ids, NULL) - PHP_FE(libvirt_list_inactive_domains, NULL) + PHP_FE(libvirt_list_domains, arginfo_libvirt_conn) + PHP_FE(libvirt_list_domain_snapshots, arginfo_libvirt_conn_optflags) + PHP_FE(libvirt_list_domain_resources, arginfo_libvirt_conn) + PHP_FE(libvirt_list_nodedevs, arginfo_libvirt_conn_optcap) + PHP_FE(libvirt_list_networks, arginfo_libvirt_conn_optflags) + PHP_FE(libvirt_list_storagepools, arginfo_libvirt_conn) + PHP_FE(libvirt_list_active_storagepools, arginfo_libvirt_conn) + PHP_FE(libvirt_list_inactive_storagepools, arginfo_libvirt_conn) + PHP_FE(libvirt_storagepool_list_volumes, arginfo_libvirt_conn) + PHP_FE(libvirt_list_active_domains, arginfo_libvirt_conn) + PHP_FE(libvirt_list_active_domain_ids, arginfo_libvirt_conn) + PHP_FE(libvirt_list_inactive_domains, arginfo_libvirt_conn) /* Version information and common function */ - PHP_FE(libvirt_version, NULL) - PHP_FE(libvirt_check_version, NULL) - PHP_FE(libvirt_has_feature, NULL) - PHP_FE(libvirt_get_iso_images, NULL) - PHP_FE(libvirt_image_create, NULL) - PHP_FE(libvirt_image_remove, NULL) + PHP_FE(libvirt_version, arginfo_libvirt_opttype) + PHP_FE(libvirt_check_version, arginfo_libvirt_check_version) + PHP_FE(libvirt_has_feature, arginfo_libvirt_name) + PHP_FE(libvirt_get_iso_images, arginfo_libvirt_optpath) + PHP_FE(libvirt_image_create, arginfo_libvirt_image_create) + PHP_FE(libvirt_image_remove, arginfo_libvirt_conn_image) /* Debugging functions */ - PHP_FE(libvirt_logfile_set, NULL) - PHP_FE(libvirt_print_binding_resources, NULL) + PHP_FE(libvirt_logfile_set, arginfo_libvirt_logfile_set) + PHP_FE(libvirt_print_binding_resources, arginfo_libvirt_void) /* Agent functions */ - PHP_FE(libvirt_domain_qemu_agent_command, NULL) + PHP_FE(libvirt_domain_qemu_agent_command, arginfo_libvirt_domain_qemu_agent_command) #ifdef PHP_FE_END PHP_FE_END #else @@ -3934,6 +4040,7 @@ PHP_FUNCTION(libvirt_domain_lookup_by_uuid) * Since version: 0.5.2(-1) * Description: Function is used to send qemu-ga command * Arguments: @res [resource]: libvirt domain resource, e.g. from libvirt_domain_lookup_by_*() + * @cmd [string]: command * @timeout [int] timeout for waiting (-2 block, -1 default, 0 no wait, >0 wait specific time * @flags [int]: unknown * Returns: String on success and FALSE on error @@ -7355,6 +7462,7 @@ PHP_FUNCTION(libvirt_storagevolume_get_info) * Description: Function is used to get the storage volume XML description * Arguments: @res [resource]: libvirt storagevolume resource * @xpath [string]: optional xPath expression string to get just this entry, can be NULL + * @flags [int]: optional flags * Returns: storagevolume XML description or result of xPath expression */ PHP_FUNCTION(libvirt_storagevolume_get_xml_desc) @@ -9025,6 +9133,7 @@ PHP_FUNCTION(libvirt_network_get_information) * Since version: 0.4.1(-1) * Description: Function is used to set the activity state of the network * Arguments: @res [resource]: libvirt network resource + * @flags [int]: active * Returns: TRUE if success, FALSE on error */ PHP_FUNCTION(libvirt_network_set_active) -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 258 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 200 insertions(+), 58 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 47893b2..0f8d19e 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -1343,7 +1343,13 @@ int is_local_connection(virConnectPtr conn) } /* Destructor for connection resource */ -static void php_libvirt_connection_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void php_libvirt_connection_dtor( +#if PHP_MAJOR_VERSION >= 7 + zend_resource *rsrc +#else + zend_rsrc_list_entry *rsrc +#endif + TSRMLS_DC) { php_libvirt_connection *conn = (php_libvirt_connection*)rsrc->ptr; int rv = 0; @@ -1370,7 +1376,13 @@ static void php_libvirt_connection_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) } /* Destructor for domain resource */ -static void php_libvirt_domain_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void php_libvirt_domain_dtor( +#if PHP_MAJOR_VERSION >= 7 + zend_resource *rsrc +#else + zend_rsrc_list_entry *rsrc +#endif + TSRMLS_DC) { php_libvirt_domain *domain = (php_libvirt_domain*)rsrc->ptr; int rv = 0; @@ -1401,7 +1413,13 @@ static void php_libvirt_domain_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) } /* Destructor for stream resource */ -static void php_libvirt_stream_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void php_libvirt_stream_dtor( +#if PHP_MAJOR_VERSION >= 7 + zend_resource *rsrc +#else + zend_rsrc_list_entry *rsrc +#endif + TSRMLS_DC) { php_libvirt_stream *stream = (php_libvirt_stream*)rsrc->ptr; int rv = 0; @@ -1431,7 +1449,13 @@ static void php_libvirt_stream_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) } /* Destructor for storagepool resource */ -static void php_libvirt_storagepool_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void php_libvirt_storagepool_dtor( +#if PHP_MAJOR_VERSION >= 7 + zend_resource *rsrc +#else + zend_rsrc_list_entry *rsrc +#endif + TSRMLS_DC) { php_libvirt_storagepool *pool = (php_libvirt_storagepool*)rsrc->ptr; int rv = 0; @@ -1461,7 +1485,13 @@ static void php_libvirt_storagepool_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) } /* Destructor for volume resource */ -static void php_libvirt_volume_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void php_libvirt_volume_dtor( +#if PHP_MAJOR_VERSION >= 7 + zend_resource *rsrc +#else + zend_rsrc_list_entry *rsrc +#endif + TSRMLS_DC) { php_libvirt_volume *volume = (php_libvirt_volume*)rsrc->ptr; int rv = 0; @@ -1491,7 +1521,13 @@ static void php_libvirt_volume_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) } /* Destructor for network resource */ -static void php_libvirt_network_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void php_libvirt_network_dtor( +#if PHP_MAJOR_VERSION >= 7 + zend_resource *rsrc +#else + zend_rsrc_list_entry *rsrc +#endif + TSRMLS_DC) { php_libvirt_network *network = (php_libvirt_network*)rsrc->ptr; int rv = 0; @@ -1521,7 +1557,13 @@ static void php_libvirt_network_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) } /* Destructor for nodedev resource */ -static void php_libvirt_nodedev_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void php_libvirt_nodedev_dtor( +#if PHP_MAJOR_VERSION >= 7 + zend_resource *rsrc +#else + zend_rsrc_list_entry *rsrc +#endif + TSRMLS_DC) { php_libvirt_nodedev *nodedev = (php_libvirt_nodedev*)rsrc->ptr; int rv = 0; @@ -1551,7 +1593,13 @@ static void php_libvirt_nodedev_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) } /* Destructor for snapshot resource */ -static void php_libvirt_snapshot_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void php_libvirt_snapshot_dtor( +#if PHP_MAJOR_VERSION >= 7 + zend_resource *rsrc +#else + zend_rsrc_list_entry *rsrc +#endif + TSRMLS_DC) { php_libvirt_snapshot *snapshot = (php_libvirt_snapshot*)rsrc->ptr; int rv = 0; @@ -1924,10 +1972,6 @@ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, args, __VA_ARGS__) == FAILU ZEND_FETCH_RESOURCE(snapshot, php_libvirt_snapshot*, &zsnapshot, -1, PHP_LIBVIRT_SNAPSHOT_RES_NAME, le_libvirt_snapshot);\ if ((snapshot==NULL) || (snapshot->snapshot==NULL)) RETURN_FALSE;\ -/* Macro to "recreate" string with emalloc */ -#define RECREATE_STRING_WITH_E(str_out, str_in) \ - str_out = estrdup(str_in); - #define LONGLONG_INIT \ char tmpnumber[64] @@ -1998,7 +2042,11 @@ static int libvirt_virConnectCredType[] = { PHP_FUNCTION(libvirt_get_last_error) { if (LIBVIRT_G (last_error) == NULL) RETURN_NULL(); +#if PHP_MAJOR_VERSION >= 7 + RETURN_STRING(LIBVIRT_G (last_error)); +#else RETURN_STRING(LIBVIRT_G (last_error),1); +#endif } /* @@ -2611,7 +2659,6 @@ PHP_FUNCTION(libvirt_connect_get_uri) { zval *zconn; char *uri; - char *uri_out; php_libvirt_connection *conn = NULL; GET_CONNECTION_FROM_ARGS("r",&zconn); @@ -2619,9 +2666,12 @@ PHP_FUNCTION(libvirt_connect_get_uri) DPRINTF("%s: virConnectGetURI returned %s\n", PHPFUNC, uri); if (uri == NULL) RETURN_FALSE; - RECREATE_STRING_WITH_E(uri_out, uri); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(uri); +#else + RETVAL_STRING(uri, 1); +#endif free(uri); - RETURN_STRING(uri_out, 0); } /* @@ -2636,7 +2686,6 @@ PHP_FUNCTION(libvirt_connect_get_hostname) php_libvirt_connection *conn=NULL; zval *zconn; char *hostname; - char *hostname_out; GET_CONNECTION_FROM_ARGS("r",&zconn); @@ -2644,9 +2693,12 @@ PHP_FUNCTION(libvirt_connect_get_hostname) DPRINTF("%s: virConnectGetHostname returned %s\n", PHPFUNC, hostname); if (hostname==NULL) RETURN_FALSE; - RECREATE_STRING_WITH_E(hostname_out,hostname); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(hostname); +#else + RETVAL_STRING(hostname, 1); +#endif free(hostname); - RETURN_STRING(hostname_out,0); } /* @@ -2947,16 +2999,18 @@ PHP_FUNCTION(libvirt_connect_get_sysinfo) php_libvirt_connection *conn=NULL; zval *zconn; char *sysinfo; - char *sysinfo_out; GET_CONNECTION_FROM_ARGS("r",&zconn); sysinfo=virConnectGetSysinfo(conn->conn, 0); if (sysinfo==NULL) RETURN_FALSE; - RECREATE_STRING_WITH_E(sysinfo_out, sysinfo); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(sysinfo); +#else + RETVAL_STRING(sysinfo, 1); +#endif free(sysinfo); - RETURN_STRING(sysinfo_out,0); } /* @@ -3916,7 +3970,12 @@ PHP_FUNCTION(libvirt_domain_get_metadata) } } else { - RETURN_STRING(ret, 0); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(ret); +#else + RETVAL_STRING(ret, 1); +#endif + free(ret); } } @@ -4060,7 +4119,11 @@ PHP_FUNCTION(libvirt_domain_qemu_agent_command) ret = virDomainQemuAgentCommand(domain->domain, cmd, timeout, flags); if (ret == NULL) RETURN_FALSE; +#if PHP_MAJOR_VERSION >= 7 + RETURN_STRING(ret); +#else RETURN_STRING(ret, 1); +#endif } /* @@ -4348,7 +4411,11 @@ PHP_FUNCTION(libvirt_domain_get_name) DPRINTF("%s: virDomainGetName(%p) returned %s\n", PHPFUNC, domain->domain, name); if (name==NULL) RETURN_FALSE; +#if PHP_MAJOR_VERSION >= 7 + RETURN_STRING(name); +#else RETURN_STRING(name, 1); //we can use the copy mechanism as we need not to free name (we even can not!) +#endif } /* @@ -4372,7 +4439,12 @@ PHP_FUNCTION(libvirt_domain_get_uuid_string) DPRINTF("%s: virDomainGetUUIDString(%p) returned %d (%s)\n", PHPFUNC, domain->domain, retval, uuid); if (retval!=0) RETURN_FALSE; +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(uuid); + efree(uuid); +#else RETURN_STRING(uuid,0); +#endif } /* @@ -4847,7 +4919,12 @@ PHP_FUNCTION(libvirt_domain_get_uuid) DPRINTF("%s: virDomainGetUUID(%p, %p) returned %d\n", PHPFUNC, domain->domain, uuid, retval); if (retval!=0) RETURN_FALSE; +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(uuid); + efree(uuid); +#else RETURN_STRING(uuid,0); +#endif } /* @@ -4914,7 +4991,6 @@ PHP_FUNCTION(libvirt_connect_get_capabilities) php_libvirt_connection *conn=NULL; zval *zconn; char *caps; - char *caps_out; char *xpath = NULL; int xpath_len; char *tmp = NULL; @@ -4928,15 +5004,21 @@ PHP_FUNCTION(libvirt_connect_get_capabilities) tmp = get_string_from_xpath(caps, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { - RECREATE_STRING_WITH_E (caps_out, caps); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(caps); +#else + RETVAL_STRING(caps, 1); +#endif } else { - RECREATE_STRING_WITH_E (caps_out, tmp); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(tmp); +#else + RETVAL_STRING(tmp, 1); +#endif } free(caps); free(tmp); - - RETURN_STRING(caps_out,0); } /* @@ -4967,9 +5049,12 @@ PHP_FUNCTION(libvirt_connect_get_emulator) RETURN_FALSE; } - RECREATE_STRING_WITH_E(emulator, tmp); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(tmp); +#else + RETVAL_STRING(tmp, 1); +#endif free(tmp); - RETURN_STRING(emulator, 0); } /* @@ -5396,7 +5481,11 @@ PHP_FUNCTION(libvirt_domain_new) PHP_FUNCTION(libvirt_domain_new_get_vnc) { if (LIBVIRT_G(vnc_location)) +#if PHP_MAJOR_VERSION >= 7 + RETURN_STRING(LIBVIRT_G(vnc_location)); +#else RETURN_STRING(LIBVIRT_G(vnc_location),1); +#endif RETURN_NULL(); } @@ -5415,7 +5504,6 @@ PHP_FUNCTION(libvirt_domain_get_xml_desc) zval *zdomain; char *tmp = NULL; char *xml; - char *xml_out; char *xpath = NULL; int xpath_len; long flags=0; @@ -5435,15 +5523,21 @@ PHP_FUNCTION(libvirt_domain_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { - RECREATE_STRING_WITH_E (xml_out, xml); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(xml); +#else + RETVAL_STRING(xml, 1); +#endif } else { - RECREATE_STRING_WITH_E (xml_out, tmp); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(tmp); +#else + RETVAL_STRING(tmp, 1); +#endif } free(tmp); free(xml); - - RETURN_STRING(xml_out,0); } /* @@ -6348,7 +6442,12 @@ PHP_FUNCTION(libvirt_domain_memory_peek) buff=(char *)emalloc(size); retval=virDomainMemoryPeek(domain->domain,start,size,buff,flags); if (retval != 0) RETURN_FALSE; +#if PHP_MAJOR_VERSION >= 7 + RETURN_STRINGL(buff, size); + efree(buff); +#else RETURN_STRINGL(buff,size,0); +#endif } /* @@ -7080,7 +7179,6 @@ PHP_FUNCTION(libvirt_domain_snapshot_create) PHP_FUNCTION(libvirt_domain_snapshot_get_xml) { char *xml; - char *xml_out; zval *zsnapshot; php_libvirt_snapshot *snapshot; long flags = 0; @@ -7090,9 +7188,12 @@ PHP_FUNCTION(libvirt_domain_snapshot_get_xml) xml = virDomainSnapshotGetXMLDesc(snapshot->snapshot, flags); if (xml==NULL) RETURN_FALSE; - RECREATE_STRING_WITH_E(xml_out,xml); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(xml); +#else + RETVAL_STRING(xml, 1); +#endif free(xml); - RETURN_STRING(xml_out,0); } /* @@ -7404,7 +7505,11 @@ PHP_FUNCTION(libvirt_storagevolume_get_name) DPRINTF("%s: virStorageVolGetName(%p) returned %s\n", PHPFUNC, volume->volume, retval); if (retval == NULL) RETURN_FALSE; +#if PHP_MAJOR_VERSION >= 7 + RETURN_STRING(retval); +#else RETURN_STRING (retval, 1); +#endif } /* @@ -7426,7 +7531,11 @@ PHP_FUNCTION(libvirt_storagevolume_get_path) DPRINTF("%s: virStorageVolGetPath(%p) returned %s\n", PHPFUNC, volume->volume, retval); if (retval == NULL) RETURN_FALSE; +#if PHP_MAJOR_VERSION >= 7 + RETURN_STRING(retval); +#else RETURN_STRING (retval, 1); +#endif } /* @@ -7471,7 +7580,6 @@ PHP_FUNCTION(libvirt_storagevolume_get_xml_desc) zval *zvolume; char *tmp = NULL; char *xml; - char *xml_out; char *xpath = NULL; int xpath_len; long flags=0; @@ -7491,15 +7599,21 @@ PHP_FUNCTION(libvirt_storagevolume_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { - RECREATE_STRING_WITH_E (xml_out, xml); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(xml); +#else + RETVAL_STRING(xml, 1); +#endif } else { - RECREATE_STRING_WITH_E(xml_out, tmp); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(tmp); +#else + RETVAL_STRING(tmp, 1); +#endif } free(xml); free(tmp); - - RETURN_STRING(xml_out,0); } /* @@ -7743,7 +7857,12 @@ PHP_FUNCTION(libvirt_storagepool_get_uuid_string) if (retval != 0) RETURN_FALSE; - RETURN_STRING(uuid, 0); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(uuid); + efree(uuid); +#else + RETURN_STRING(uuid,0); +#endif } /* @@ -7766,7 +7885,11 @@ PHP_FUNCTION(libvirt_storagepool_get_name) if (name == NULL) RETURN_FALSE; +#if PHP_MAJOR_VERSION >= 7 + RETURN_STRING(name); +#else RETURN_STRING(name, 1); +#endif } /* @@ -7818,7 +7941,6 @@ PHP_FUNCTION(libvirt_storagepool_get_xml_desc) php_libvirt_storagepool *pool = NULL; zval *zpool; char *xml; - char *xml_out; char *xpath = NULL; char *tmp = NULL; long flags = 0; @@ -7840,15 +7962,21 @@ PHP_FUNCTION(libvirt_storagepool_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { - RECREATE_STRING_WITH_E (xml_out, xml); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(xml); +#else + RETVAL_STRING(xml, 1); +#endif } else { - RECREATE_STRING_WITH_E (xml_out, tmp); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(tmp); +#else + RETVAL_STRING(tmp, 1); +#endif } free(xml); free(tmp); - - RETURN_STRING (xml_out, 0); } /* @@ -8711,7 +8839,6 @@ PHP_FUNCTION(libvirt_nodedev_get_xml_desc) zval *znodedev; char *tmp = NULL; char *xml = NULL; - char *xml_out = NULL; char *xpath = NULL; int xpath_len; int retval = -1; @@ -8730,15 +8857,21 @@ PHP_FUNCTION(libvirt_nodedev_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { - RECREATE_STRING_WITH_E (xml_out, xml); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(xml); +#else + RETVAL_STRING(xml, 1); +#endif } else { - RECREATE_STRING_WITH_E (xml_out, tmp); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(tmp); +#else + RETVAL_STRING(tmp, 1); +#endif } free(xml); free(tmp); - - RETURN_STRING(xml_out, 0); } /* @@ -9007,7 +9140,11 @@ PHP_FUNCTION(libvirt_network_get_bridge) RETURN_FALSE; } +#if PHP_MAJOR_VERSION >= 7 + RETURN_STRING(name); +#else RETURN_STRING(name, 1); +#endif } /* @@ -9187,7 +9324,6 @@ PHP_FUNCTION(libvirt_network_get_xml_desc) php_libvirt_network *network; zval *znetwork; char *xml = NULL; - char *xml_out = NULL; char *xpath = NULL; char *tmp; int xpath_len; @@ -9208,15 +9344,21 @@ PHP_FUNCTION(libvirt_network_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { - RECREATE_STRING_WITH_E (xml_out, xml); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(xml); +#else + RETVAL_STRING(xml, 1); +#endif } else { - RECREATE_STRING_WITH_E (xml_out, tmp); +#if PHP_MAJOR_VERSION >= 7 + RETVAL_STRING(tmp); +#else + RETVAL_STRING(tmp, 1); +#endif } free(xml); free(tmp); - - RETURN_STRING(xml_out, 0); } /* -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 0f8d19e..5f3857c 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -55,6 +55,12 @@ const char *features[] = { NULL }; const char *features_binaries[] = { NULL }; #endif +#if PHP_MAJOR_VERSION >= 7 +typedef size_t strsize_t; +#else +typedef int strsize_t; +typedef long zend_long; +#endif /* ZEND thread safe per request globals definition */ int le_libvirt_connection; int le_libvirt_domain; @@ -2071,7 +2077,7 @@ PHP_FUNCTION(libvirt_connect) virConnectAuth libvirt_virConnectAuth= { libvirt_virConnectCredType, sizeof(libvirt_virConnectCredType)/sizeof(int), libvirt_virConnectAuthCallback, NULL}; char *url=NULL; - int url_len=0; + strsize_t url_len=0; int readonly=1; HashTable *arr_hash; @@ -4290,7 +4296,7 @@ PHP_FUNCTION(libvirt_stream_recv) char *recv_buf; php_libvirt_stream *stream=NULL; int retval = -1; - long length = 0; + zend_long length = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|l", &zstream, &zbuf, &length) == FAILURE) { RETURN_LONG(retval); @@ -4337,7 +4343,7 @@ PHP_FUNCTION(libvirt_stream_send) zval *zstream, *zbuf; php_libvirt_stream *stream=NULL; int retval = -1; - long length = 0; + zend_long length = 0; char *cstr; //int cstrlen; @@ -7770,9 +7776,9 @@ PHP_FUNCTION(libvirt_storagevolume_download) php_libvirt_stream *stream=NULL; zval *zvolume; zval *zstream; - long flags = 0; - long offset = 0; - long length = 0; + zend_long flags = 0; + zend_long offset = 0; + zend_long length = 0; int retval = -1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l|l|l", &zvolume, &zstream, &offset, &length, &flags) == FAILURE) { @@ -7811,9 +7817,9 @@ PHP_FUNCTION(libvirt_storagevolume_upload) php_libvirt_stream *stream=NULL; zval *zvolume; zval *zstream; - long flags = 0; - long offset = 0; - long length = 0; + zend_long flags = 0; + zend_long offset = 0; + zend_long length = 0; int retval = -1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l|l|l", &zvolume, &zstream, &offset, &length, &flags) == FAILURE) { @@ -9372,7 +9378,7 @@ PHP_FUNCTION(libvirt_version) { unsigned long libVer; unsigned long typeVer; - int type_len; + strsize_t type_len; char *type=NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &type,&type_len) == FAILURE) { set_error("Invalid arguments" TSRMLS_CC); @@ -9419,7 +9425,7 @@ PHP_FUNCTION(libvirt_version) PHP_FUNCTION(libvirt_check_version) { unsigned long libVer; - unsigned long major = 0, minor = 0, micro = 0, type = VIR_VERSION_BINDING; + zend_long major = 0, minor = 0, micro = 0, type = VIR_VERSION_BINDING; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll|l", &major, &minor, µ, &type) == FAILURE) { set_error("Invalid arguments" TSRMLS_CC); @@ -9464,7 +9470,7 @@ PHP_FUNCTION(libvirt_check_version) PHP_FUNCTION(libvirt_has_feature) { char *name = NULL; - int name_len = 0; + strsize_t name_len = 0; const char *binary = NULL; int ret = 0; @@ -9492,7 +9498,7 @@ PHP_FUNCTION(libvirt_has_feature) PHP_FUNCTION(libvirt_get_iso_images) { char *path = NULL; - int path_len = 0; + strsize_t path_len = 0; #ifndef EXTWIN struct dirent *entry; DIR *d = NULL; @@ -9579,8 +9585,8 @@ PHP_FUNCTION(libvirt_print_binding_resources) PHP_FUNCTION(libvirt_logfile_set) { char *filename = NULL; - long maxsize = DEFAULT_LOG_MAXSIZE; - int filename_len = 0; + zend_long maxsize = DEFAULT_LOG_MAXSIZE; + strsize_t filename_len = 0; int err; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &maxsize) == FAILURE) { -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 174 insertions(+), 27 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 5f3857c..d37fd6f 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -57,9 +57,20 @@ const char *features_binaries[] = { NULL }; #if PHP_MAJOR_VERSION >= 7 typedef size_t strsize_t; + +#define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \ + if ((_state = (_type)zend_fetch_resource(Z_RES_P(*_zval), _name, _le)) == NULL) { \ + RETURN_FALSE; \ + } + #else typedef int strsize_t; typedef long zend_long; +typedef unsigned long zend_ulong; + +#define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \ + ZEND_FETCH_RESOURCE(_state, _type, _zval, -1, _name, _le); + #endif /* ZEND thread safe per request globals definition */ int le_libvirt_connection; @@ -1915,7 +1926,7 @@ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, args, __VA_ARGS__) == FAILU RETURN_FALSE;\ }\ \ -ZEND_FETCH_RESOURCE(conn, php_libvirt_connection*, &zconn, -1, PHP_LIBVIRT_CONNECTION_RES_NAME, le_libvirt_connection);\ +VIRT_FETCH_RESOURCE(conn, php_libvirt_connection*, &zconn, PHP_LIBVIRT_CONNECTION_RES_NAME, le_libvirt_connection);\ if ((conn==NULL) || (conn->conn==NULL)) RETURN_FALSE;\ #define GET_DOMAIN_FROM_ARGS(args, ...) \ @@ -1925,7 +1936,7 @@ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, args, __VA_ARGS__) == FAILU RETURN_FALSE;\ }\ \ -ZEND_FETCH_RESOURCE(domain, php_libvirt_domain*, &zdomain, -1, PHP_LIBVIRT_DOMAIN_RES_NAME, le_libvirt_domain);\ +VIRT_FETCH_RESOURCE(domain, php_libvirt_domain*, &zdomain, PHP_LIBVIRT_DOMAIN_RES_NAME, le_libvirt_domain);\ if ((domain==NULL) || (domain->domain==NULL)) RETURN_FALSE;\ #define GET_NETWORK_FROM_ARGS(args, ...) \ @@ -1935,7 +1946,7 @@ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, args, __VA_ARGS__) == FAILU RETURN_FALSE;\ }\ \ -ZEND_FETCH_RESOURCE(network, php_libvirt_network*, &znetwork, -1, PHP_LIBVIRT_NETWORK_RES_NAME, le_libvirt_network);\ +VIRT_FETCH_RESOURCE(network, php_libvirt_network*, &znetwork, PHP_LIBVIRT_NETWORK_RES_NAME, le_libvirt_network);\ if ((network==NULL) || (network->network==NULL)) RETURN_FALSE;\ #define GET_NODEDEV_FROM_ARGS(args, ...) \ @@ -1945,7 +1956,7 @@ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, args, __VA_ARGS__) == FAILU RETURN_FALSE;\ }\ \ -ZEND_FETCH_RESOURCE(nodedev, php_libvirt_nodedev*, &znodedev, -1, PHP_LIBVIRT_NODEDEV_RES_NAME, le_libvirt_nodedev);\ +VIRT_FETCH_RESOURCE(nodedev, php_libvirt_nodedev*, &znodedev, PHP_LIBVIRT_NODEDEV_RES_NAME, le_libvirt_nodedev);\ if ((nodedev==NULL) || (nodedev->device==NULL)) RETURN_FALSE;\ #define GET_STORAGEPOOL_FROM_ARGS(args, ...) \ @@ -1955,7 +1966,7 @@ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, args, __VA_ARGS__) == FAILU RETURN_FALSE;\ }\ \ -ZEND_FETCH_RESOURCE(pool, php_libvirt_storagepool*, &zpool, -1, PHP_LIBVIRT_STORAGEPOOL_RES_NAME, le_libvirt_storagepool);\ +VIRT_FETCH_RESOURCE(pool, php_libvirt_storagepool*, &zpool, PHP_LIBVIRT_STORAGEPOOL_RES_NAME, le_libvirt_storagepool);\ if ((pool==NULL) || (pool->pool==NULL)) RETURN_FALSE;\ #define GET_VOLUME_FROM_ARGS(args, ...) \ @@ -1965,7 +1976,7 @@ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, args, __VA_ARGS__) == FAILU RETURN_FALSE;\ }\ \ -ZEND_FETCH_RESOURCE(volume, php_libvirt_volume*, &zvolume, -1, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume);\ +VIRT_FETCH_RESOURCE(volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume);\ if ((volume==NULL) || (volume->volume==NULL)) RETURN_FALSE;\ #define GET_SNAPSHOT_FROM_ARGS(args, ...) \ @@ -1975,7 +1986,7 @@ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, args, __VA_ARGS__) == FAILU RETURN_FALSE;\ }\ \ -ZEND_FETCH_RESOURCE(snapshot, php_libvirt_snapshot*, &zsnapshot, -1, PHP_LIBVIRT_SNAPSHOT_RES_NAME, le_libvirt_snapshot);\ +VIRT_FETCH_RESOURCE(snapshot, php_libvirt_snapshot*, &zsnapshot, PHP_LIBVIRT_SNAPSHOT_RES_NAME, le_libvirt_snapshot);\ if ((snapshot==NULL) || (snapshot->snapshot==NULL)) RETURN_FALSE;\ #define LONGLONG_INIT \ @@ -2069,7 +2080,7 @@ PHP_FUNCTION(libvirt_connect) php_libvirt_connection *conn; php_libvirt_cred_value *creds=NULL; zval* zcreds=NULL; - zval **data; + zval *data; int i; int j; int credscount=0; @@ -2084,9 +2095,7 @@ PHP_FUNCTION(libvirt_connect) HashPosition pointer; int array_count; - char *key; - unsigned int key_len; - unsigned long index; + zend_ulong index; unsigned long libVer; @@ -2131,9 +2140,27 @@ PHP_FUNCTION(libvirt_connect) j=0; /* parse the input Array and create list of credentials. The list (array) is passed to callback function. */ for (zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); +#if PHP_MAJOR_VERSION >= 7 + (data = zend_hash_get_current_data_ex(arr_hash, &pointer)) != NULL; + zend_hash_move_forward_ex(arr_hash, &pointer)) { + if (Z_TYPE_P(data) == IS_STRING) { + zend_string *key; + if (zend_hash_get_current_key_ex(arr_hash, &key, &index, &pointer) == HASH_KEY_IS_STRING) { + PHPWRITE(ZSTR_VAL(key), ZSTR_LEN(key)); + } else { + DPRINTF("%s: credentials index %d\n", PHPFUNC, (int)index); + creds[j].type=index; + creds[j].result=(char *)emalloc( Z_STRLEN_P(data) + 1 ); + memset(creds[j].result, 0, Z_STRLEN_P(data) + 1); + creds[j].resultlen=Z_STRLEN_P(data); + strncpy(creds[j].result,Z_STRVAL_P(data),Z_STRLEN_P(data)); + j++; +#else zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) { if (Z_TYPE_PP(data) == IS_STRING) { + char *key; + unsigned int key_len; if (zend_hash_get_current_key_ex(arr_hash, &key, &key_len, &index, 0, &pointer) == HASH_KEY_IS_STRING) { PHPWRITE(key, key_len); } else { @@ -2144,6 +2171,7 @@ PHP_FUNCTION(libvirt_connect) creds[j].resultlen=Z_STRLEN_PP(data); strncpy(creds[j].result,Z_STRVAL_PP(data),Z_STRLEN_PP(data)); j++; +#endif } } } @@ -2166,7 +2194,11 @@ PHP_FUNCTION(libvirt_connect) resource_change_counter(INT_RESOURCE_CONNECTION, NULL, conn->conn, 1 TSRMLS_CC); DPRINTF("%s: Connection to %s established, returning %p\n", PHPFUNC, url, conn->conn); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(conn, le_libvirt_connection)); +#else ZEND_REGISTER_RESOURCE(return_value, conn, le_libvirt_connection); +#endif conn->resource_id=Z_LVAL_P(return_value); } @@ -3299,9 +3331,7 @@ long get_next_free_numeric_value(virDomainPtr domain, char *xpath) HashTable *arr_hash; HashPosition pointer; // int array_count; - zval **data; - char *key; - unsigned int key_len; + zval *data; unsigned long index; long max_slot = -1; @@ -3313,13 +3343,26 @@ long get_next_free_numeric_value(virDomainPtr domain, char *xpath) arr_hash = Z_ARRVAL_P(output); // array_count = zend_hash_num_elements(arr_hash); for (zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); +#if PHP_MAJOR_VERSION >= 7 + (data = zend_hash_get_current_data_ex(arr_hash, &pointer)) != NULL; + zend_hash_move_forward_ex(arr_hash, &pointer)) { + if (Z_TYPE_P(data) == IS_STRING) { + zend_string *key; + if (zend_hash_get_current_key_ex(arr_hash, &key, &index, &pointer) != HASH_KEY_IS_STRING) { + long num = -1; + + sscanf(Z_STRVAL_P(data), "%lx", &num); +#else zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) { if (Z_TYPE_PP(data) == IS_STRING) { + char *key; + unsigned int key_len; if (zend_hash_get_current_key_ex(arr_hash, &key, &key_len, &index, 0, &pointer) != HASH_KEY_IS_STRING) { long num = -1; sscanf(Z_STRVAL_PP(data), "%lx", &num); +#endif if (num > max_slot) max_slot = num; } @@ -4065,7 +4108,11 @@ PHP_FUNCTION(libvirt_domain_lookup_by_name) DPRINTF("%s: domain name = '%s', returning %p\n", PHPFUNC, name, res_domain->domain); resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, res_domain->domain, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_domain, le_libvirt_domain)); +#else ZEND_REGISTER_RESOURCE(return_value, res_domain, le_libvirt_domain); +#endif } /* @@ -4097,7 +4144,11 @@ PHP_FUNCTION(libvirt_domain_lookup_by_uuid) DPRINTF("%s: domain UUID = '%s', returning %p\n", PHPFUNC, uuid, res_domain->domain); resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, res_domain->domain, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_domain, le_libvirt_domain)); +#else ZEND_REGISTER_RESOURCE(return_value, res_domain, le_libvirt_domain); +#endif } /* @@ -4161,7 +4212,11 @@ PHP_FUNCTION(libvirt_domain_lookup_by_uuid_string) DPRINTF("%s: domain UUID string = '%s', returning %p\n", PHPFUNC, uuid, res_domain->domain); resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, res_domain->domain, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_domain, le_libvirt_domain)); +#else ZEND_REGISTER_RESOURCE(return_value, res_domain, le_libvirt_domain); +#endif } /* @@ -4181,7 +4236,7 @@ PHP_FUNCTION(libvirt_stream_create) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zconn) == FAILURE) { RETURN_FALSE; } - ZEND_FETCH_RESOURCE (conn, php_libvirt_connection*, &zconn, -1, PHP_LIBVIRT_CONNECTION_RES_NAME, le_libvirt_connection); + VIRT_FETCH_RESOURCE (conn, php_libvirt_connection*, &zconn, PHP_LIBVIRT_CONNECTION_RES_NAME, le_libvirt_connection); if ((conn==NULL)||(conn->conn==NULL))RETURN_FALSE; stream = virStreamNew(conn->conn, 0); @@ -4195,7 +4250,11 @@ PHP_FUNCTION(libvirt_stream_create) res_stream->conn = conn; resource_change_counter(INT_RESOURCE_STREAM, conn->conn, res_stream->stream, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_stream, le_libvirt_stream)); +#else ZEND_REGISTER_RESOURCE(return_value, res_stream, le_libvirt_stream); +#endif } /* @@ -4214,7 +4273,7 @@ PHP_FUNCTION(libvirt_stream_close) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) == FAILURE) { RETURN_LONG(retval); } - ZEND_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, -1, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream); + VIRT_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream); if ((stream==NULL)||(stream->stream==NULL))RETURN_LONG(retval); retval = virStreamFree(stream->stream); @@ -4243,7 +4302,7 @@ PHP_FUNCTION(libvirt_stream_abort) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) == FAILURE) { RETURN_LONG(retval); } - ZEND_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, -1, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream); + VIRT_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream); if ((stream==NULL)||(stream->stream==NULL))RETURN_LONG(retval); retval = virStreamAbort(stream->stream); @@ -4270,7 +4329,7 @@ PHP_FUNCTION(libvirt_stream_finish) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) == FAILURE) { RETURN_LONG(retval); } - ZEND_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, -1, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream); + VIRT_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream); if ((stream==NULL)||(stream->stream==NULL))RETURN_LONG(retval); retval = virStreamFinish(stream->stream); @@ -4301,7 +4360,7 @@ PHP_FUNCTION(libvirt_stream_recv) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|l", &zstream, &zbuf, &length) == FAILURE) { RETURN_LONG(retval); } - ZEND_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, -1, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream); + VIRT_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream); if ((stream==NULL)||(stream->stream==NULL))RETURN_LONG(retval); recv_buf = emalloc(length + 1); @@ -4350,7 +4409,7 @@ PHP_FUNCTION(libvirt_stream_send) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|l", &zstream, &zbuf, &length) == FAILURE) { RETURN_LONG(retval); } - ZEND_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, -1, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream); + VIRT_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream); if ((stream==NULL)||(stream->stream==NULL))RETURN_LONG(retval); cstr = Z_STRVAL_P(zbuf); @@ -4392,7 +4451,11 @@ PHP_FUNCTION(libvirt_domain_lookup_by_id) DPRINTF("%s: domain id = '%d', returning %p\n", PHPFUNC, (int)id, res_domain->domain); resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, res_domain->domain, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_domain, le_libvirt_domain)); +#else ZEND_REGISTER_RESOURCE(return_value, res_domain, le_libvirt_domain); +#endif } /* @@ -5474,7 +5537,11 @@ PHP_FUNCTION(libvirt_domain_new) DPRINTF("%s: returning %p\n", PHPFUNC, res_domain->domain); resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, res_domain->domain, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_domain, le_libvirt_domain)); +#else ZEND_REGISTER_RESOURCE(return_value, res_domain, le_libvirt_domain); +#endif } /* @@ -5719,7 +5786,11 @@ PHP_FUNCTION(libvirt_domain_change_memory) DPRINTF("%s: returning %p\n", PHPFUNC, res_domain->domain); resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, res_domain->domain, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_domain, le_libvirt_domain)); +#else ZEND_REGISTER_RESOURCE(return_value, res_domain, le_libvirt_domain); +#endif } /* @@ -5800,7 +5871,11 @@ PHP_FUNCTION(libvirt_domain_change_boot_devices) DPRINTF("%s: returning %p\n", PHPFUNC, res_domain->domain); resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, res_domain->domain, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_domain, le_libvirt_domain)); +#else ZEND_REGISTER_RESOURCE(return_value, res_domain, le_libvirt_domain); +#endif } /* @@ -6388,7 +6463,11 @@ PHP_FUNCTION(libvirt_domain_define_xml) DPRINTF("%s: returning %p\n", PHPFUNC, res_domain->domain); resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, res_domain->domain, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_domain, le_libvirt_domain)); +#else ZEND_REGISTER_RESOURCE(return_value, res_domain, le_libvirt_domain); +#endif } /* @@ -6421,7 +6500,11 @@ PHP_FUNCTION(libvirt_domain_create_xml) DPRINTF("%s: returning %p\n", PHPFUNC, res_domain->domain); resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, res_domain->domain, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_domain, le_libvirt_domain)); +#else ZEND_REGISTER_RESOURCE(return_value, res_domain, le_libvirt_domain); +#endif } /* @@ -7033,7 +7116,7 @@ PHP_FUNCTION(libvirt_domain_migrate) RETURN_FALSE; } - ZEND_FETCH_RESOURCE(dconn, php_libvirt_connection*, &zdconn, -1, PHP_LIBVIRT_CONNECTION_RES_NAME, le_libvirt_connection); + VIRT_FETCH_RESOURCE(dconn, php_libvirt_connection*, &zdconn, PHP_LIBVIRT_CONNECTION_RES_NAME, le_libvirt_connection); if ((dconn==NULL) || (dconn->conn==NULL)) { set_error("Destination connection object is not valid" TSRMLS_CC); RETURN_FALSE; @@ -7048,7 +7131,11 @@ PHP_FUNCTION(libvirt_domain_migrate) DPRINTF("%s: returning %p\n", PHPFUNC, res_domain->domain); resource_change_counter(INT_RESOURCE_DOMAIN, dconn->conn, res_domain->domain, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_domain, le_libvirt_domain)); +#else ZEND_REGISTER_RESOURCE(return_value, res_domain, le_libvirt_domain); +#endif } /* @@ -7140,7 +7227,11 @@ PHP_FUNCTION(libvirt_domain_snapshot_lookup_by_name) DPRINTF("%s: returning %p\n", PHPFUNC, res_snapshot->snapshot); resource_change_counter(INT_RESOURCE_SNAPSHOT, domain->conn->conn, res_snapshot->snapshot, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_snapshot, le_libvirt_snapshot)); +#else ZEND_REGISTER_RESOURCE(return_value, res_snapshot, le_libvirt_snapshot); +#endif } /* @@ -7171,7 +7262,11 @@ PHP_FUNCTION(libvirt_domain_snapshot_create) DPRINTF("%s: returning %p\n", PHPFUNC, res_snapshot->snapshot); resource_change_counter(INT_RESOURCE_SNAPSHOT, domain->conn->conn, res_snapshot->snapshot, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_snapshot, le_libvirt_snapshot)); +#else ZEND_REGISTER_RESOURCE(return_value, res_snapshot, le_libvirt_snapshot); +#endif } /* @@ -7321,7 +7416,11 @@ PHP_FUNCTION(libvirt_storagepool_lookup_by_name) DPRINTF("%s: returning %p\n", PHPFUNC, res_pool->pool); resource_change_counter(INT_RESOURCE_STORAGEPOOL, conn->conn, res_pool->pool, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_pool, le_libvirt_storagepool)); +#else ZEND_REGISTER_RESOURCE(return_value, res_pool, le_libvirt_storagepool); +#endif } /* Storagepool functions */ @@ -7353,7 +7452,11 @@ PHP_FUNCTION(libvirt_storagepool_lookup_by_volume) DPRINTF("%s: returning %p\n", PHPFUNC, res_pool->pool); resource_change_counter(INT_RESOURCE_STORAGEPOOL, res_pool->conn->conn, res_pool->pool, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_pool, le_libvirt_storagepool)); +#else ZEND_REGISTER_RESOURCE(return_value, res_pool, le_libvirt_storagepool); +#endif } /* @@ -7452,7 +7555,11 @@ PHP_FUNCTION(libvirt_storagevolume_lookup_by_name) DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume); resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_volume->volume, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_volume, le_libvirt_volume)); +#else ZEND_REGISTER_RESOURCE(return_value, res_volume, le_libvirt_volume); +#endif } /* @@ -7489,7 +7596,11 @@ PHP_FUNCTION(libvirt_storagevolume_lookup_by_path) DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume); resource_change_counter(INT_RESOURCE_VOLUME, conn->conn, res_volume->volume, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_volume, le_libvirt_volume)); +#else ZEND_REGISTER_RESOURCE(return_value, res_volume, le_libvirt_volume); +#endif } /* @@ -7653,7 +7764,11 @@ PHP_FUNCTION(libvirt_storagevolume_create_xml) DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume); resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_volume->volume, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_volume, le_libvirt_volume)); +#else ZEND_REGISTER_RESOURCE(return_value, res_volume, le_libvirt_volume); +#endif } /* @@ -7684,9 +7799,9 @@ PHP_FUNCTION(libvirt_storagevolume_create_xml_from) RETURN_FALSE; } - ZEND_FETCH_RESOURCE (pool, php_libvirt_storagepool*, &zpool, -1, PHP_LIBVIRT_STORAGEPOOL_RES_NAME, le_libvirt_storagepool); + VIRT_FETCH_RESOURCE (pool, php_libvirt_storagepool*, &zpool, PHP_LIBVIRT_STORAGEPOOL_RES_NAME, le_libvirt_storagepool); if ((pool==NULL)||(pool->pool==NULL))RETURN_FALSE; - ZEND_FETCH_RESOURCE (pl_volume, php_libvirt_volume*, &zvolume, -1, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume); + VIRT_FETCH_RESOURCE (pl_volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume); if ((pl_volume==NULL)||(pl_volume->volume==NULL))RETURN_FALSE; resource_change_counter(INT_RESOURCE_VOLUME, NULL, pl_volume->volume, 1 TSRMLS_CC); @@ -7700,7 +7815,11 @@ PHP_FUNCTION(libvirt_storagevolume_create_xml_from) DPRINTF("%s: returning %p\n", PHPFUNC, res_volume->volume); resource_change_counter(INT_RESOURCE_VOLUME, pool->conn->conn, res_volume->volume, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_volume, le_libvirt_volume)); +#else ZEND_REGISTER_RESOURCE(return_value, res_volume, le_libvirt_volume); +#endif } /* @@ -7784,9 +7903,9 @@ PHP_FUNCTION(libvirt_storagevolume_download) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l|l|l", &zvolume, &zstream, &offset, &length, &flags) == FAILURE) { RETURN_LONG(retval); } - ZEND_FETCH_RESOURCE (volume, php_libvirt_volume*, &zvolume, -1, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume); + VIRT_FETCH_RESOURCE (volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume); if ((volume==NULL)||(volume->volume==NULL))RETURN_LONG(retval); - ZEND_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, -1, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream); + VIRT_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream); if ((stream==NULL)||(stream->stream==NULL))RETURN_LONG(retval); retval = virStorageVolDownload(volume->volume, stream->stream, offset, length, flags); @@ -7825,9 +7944,9 @@ PHP_FUNCTION(libvirt_storagevolume_upload) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l|l|l", &zvolume, &zstream, &offset, &length, &flags) == FAILURE) { RETURN_LONG(retval); } - ZEND_FETCH_RESOURCE (volume, php_libvirt_volume*, &zvolume, -1, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume); + VIRT_FETCH_RESOURCE (volume, php_libvirt_volume*, &zvolume, PHP_LIBVIRT_VOLUME_RES_NAME, le_libvirt_volume); if ((volume==NULL)||(volume->volume==NULL))RETURN_LONG(retval); - ZEND_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, -1, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream); + VIRT_FETCH_RESOURCE (stream, php_libvirt_stream*, &zstream, PHP_LIBVIRT_STREAM_RES_NAME, le_libvirt_stream); if ((stream==NULL)||(stream->stream==NULL))RETURN_LONG(retval); retval = virStorageVolUpload(volume->volume, stream->stream, offset, length, flags); @@ -7931,7 +8050,11 @@ PHP_FUNCTION(libvirt_storagepool_lookup_by_uuid_string) DPRINTF("%s: returning %p\n", PHPFUNC, res_pool->pool); resource_change_counter(INT_RESOURCE_STORAGEPOOL, conn->conn, res_pool->pool, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_pool, le_libvirt_storagepool)); +#else ZEND_REGISTER_RESOURCE (return_value, res_pool, le_libvirt_storagepool); +#endif } /* @@ -8018,7 +8141,11 @@ PHP_FUNCTION(libvirt_storagepool_define_xml) DPRINTF("%s: returning %p\n", PHPFUNC, res_pool->pool); resource_change_counter(INT_RESOURCE_STORAGEPOOL, conn->conn, res_pool->pool, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_pool, le_libvirt_storagepool)); +#else ZEND_REGISTER_RESOURCE (return_value, res_pool, le_libvirt_storagepool); +#endif } /* @@ -8501,7 +8628,11 @@ PHP_FUNCTION(libvirt_list_domain_resources) res_domain->conn=conn; resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, res_domain->domain, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_domain, le_libvirt_domain)); +#else ZEND_REGISTER_RESOURCE(zdomain, res_domain, le_libvirt_domain); +#endif add_next_index_zval(return_value, zdomain); } } @@ -8526,7 +8657,11 @@ PHP_FUNCTION(libvirt_list_domain_resources) ALLOC_INIT_ZVAL(zdomain); res_domain->conn=conn; +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_domain, le_libvirt_domain)); +#else ZEND_REGISTER_RESOURCE(zdomain, res_domain, le_libvirt_domain); +#endif resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, res_domain->domain, 1 TSRMLS_CC); add_next_index_zval(return_value, zdomain); } @@ -8795,7 +8930,11 @@ PHP_FUNCTION(libvirt_nodedev_get) DPRINTF("%s: returning %p\n", PHPFUNC, res_dev->device); resource_change_counter(INT_RESOURCE_NODEDEV, conn->conn, res_dev->device, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_dev, le_libvirt_nodedev)); +#else ZEND_REGISTER_RESOURCE(return_value, res_dev, le_libvirt_nodedev); +#endif } /* @@ -9068,7 +9207,11 @@ PHP_FUNCTION(libvirt_network_define_xml) DPRINTF("%s: returning %p\n", PHPFUNC, res_net->network); resource_change_counter(INT_RESOURCE_NETWORK, conn->conn, res_net->network, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_net, le_libvirt_network)); +#else ZEND_REGISTER_RESOURCE(return_value, res_net, le_libvirt_network); +#endif } /* @@ -9121,7 +9264,11 @@ PHP_FUNCTION(libvirt_network_get) DPRINTF("%s: returning %p\n", PHPFUNC, res_net->network); resource_change_counter(INT_RESOURCE_NETWORK, conn->conn, res_net->network, 1 TSRMLS_CC); +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, zend_register_resource(res_net, le_libvirt_network)); +#else ZEND_REGISTER_RESOURCE(return_value, res_net, le_libvirt_network); +#endif } /* -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 299 ++++++++++++++++++------------------------------------ 1 file changed, 99 insertions(+), 200 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index d37fd6f..0459bb9 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -58,6 +58,7 @@ const char *features_binaries[] = { NULL }; #if PHP_MAJOR_VERSION >= 7 typedef size_t strsize_t; +#define VIRT_COPY_OPT #define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \ if ((_state = (_type)zend_fetch_resource(Z_RES_P(*_zval), _name, _le)) == NULL) { \ RETURN_FALSE; \ @@ -68,6 +69,8 @@ typedef int strsize_t; typedef long zend_long; typedef unsigned long zend_ulong; +#define VIRT_COPY_OPT ,1 + #define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \ ZEND_FETCH_RESOURCE(_state, _type, _zval, -1, _name, _le); @@ -1995,7 +1998,7 @@ if ((snapshot==NULL) || (snapshot->snapshot==NULL)) RETURN_FALSE;\ #define LONGLONG_ASSOC(out,key,in) \ if (LIBVIRT_G(longlong_to_string_ini)) { \ snprintf(tmpnumber,63,"%llu",in); \ - add_assoc_string_ex(out,key,strlen(key)+1,tmpnumber,1); \ + add_assoc_string_ex(out,key,strlen(key)+1,tmpnumber VIRT_COPY_OPT); \ } \ else \ { \ @@ -2059,11 +2062,7 @@ static int libvirt_virConnectCredType[] = { PHP_FUNCTION(libvirt_get_last_error) { if (LIBVIRT_G (last_error) == NULL) RETURN_NULL(); -#if PHP_MAJOR_VERSION >= 7 - RETURN_STRING(LIBVIRT_G (last_error)); -#else - RETURN_STRING(LIBVIRT_G (last_error),1); -#endif + RETURN_STRING(LIBVIRT_G (last_error) VIRT_COPY_OPT); } /* @@ -2223,7 +2222,7 @@ PHP_FUNCTION(libvirt_node_get_info) if (retval==-1) RETURN_FALSE; array_init(return_value); - add_assoc_string_ex(return_value, "model", 6, info.model, 1); + add_assoc_string_ex(return_value, "model", 6, info.model VIRT_COPY_OPT); add_assoc_long(return_value, "memory", (long)info.memory); add_assoc_long(return_value, "cpus", (long)info.cpus); add_assoc_long(return_value, "nodes", (long)info.nodes); @@ -2318,9 +2317,9 @@ PHP_FUNCTION(libvirt_node_get_cpu_stats) add_assoc_long(return_value, "cpu", cpunr); else if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS) - add_assoc_string_ex(return_value, "cpu", 4, "all", 1); + add_assoc_string_ex(return_value, "cpu", 4, "all" VIRT_COPY_OPT); else - add_assoc_string_ex(return_value, "cpu", 4, "unknown", 1); + add_assoc_string_ex(return_value, "cpu", 4, "unknown" VIRT_COPY_OPT); free(params); params = NULL; @@ -2532,21 +2531,21 @@ PHP_FUNCTION(libvirt_connect_get_machine_types) char tmp3[2048] = { 0 }; snprintf(key, sizeof(key), "%d", k); - //add_assoc_string_ex(arr2, key, strlen(key) + 1, ret3[k], 1); + //add_assoc_string_ex(arr2, key, strlen(key) + 1, ret3[k] VIRT_COPY_OPT); snprintf(tmp3, sizeof(tmp3), "//capabilities/guest/arch[@name=\"%s\"]/machine[text()=\"%s\"]/@maxCpus", ret[i], ret3[k]); numTmp = get_string_from_xpath(caps, tmp3, NULL, NULL); if (numTmp == NULL) - add_assoc_string_ex(arr2, key, strlen(key) + 1, ret3[k], 1); + add_assoc_string_ex(arr2, key, strlen(key) + 1, ret3[k] VIRT_COPY_OPT); else { zval *arr4; ALLOC_INIT_ZVAL(arr4); array_init(arr4); - add_assoc_string_ex(arr4, "name", 5, ret3[k], 1); - add_assoc_string_ex(arr4, "maxCpus", 9, numTmp, 1); + add_assoc_string_ex(arr4, "name", 5, ret3[k] VIRT_COPY_OPT); + add_assoc_string_ex(arr4, "maxCpus", 9, numTmp VIRT_COPY_OPT); add_assoc_zval_ex(arr2, key, strlen(key) + 1, arr4); free(numTmp); @@ -2574,14 +2573,14 @@ PHP_FUNCTION(libvirt_connect_get_machine_types) numTmp = get_string_from_xpath(caps, tmp3, NULL, NULL); if (numTmp == NULL) - add_assoc_string_ex(arr3, key, strlen(key) + 1, ret3[k], 1); + add_assoc_string_ex(arr3, key, strlen(key) + 1, ret3[k] VIRT_COPY_OPT); else { zval *arr4; ALLOC_INIT_ZVAL(arr4); array_init(arr4); - add_assoc_string_ex(arr4, "name", 5, ret3[k], 1); - add_assoc_string_ex(arr4, "maxCpus", 9, numTmp, 1); + add_assoc_string_ex(arr4, "name", 5, ret3[k] VIRT_COPY_OPT); + add_assoc_string_ex(arr4, "maxCpus", 9, numTmp VIRT_COPY_OPT); add_assoc_zval_ex(arr3, key, strlen(key) + 1, arr4); free(numTmp); @@ -2624,21 +2623,21 @@ PHP_FUNCTION(libvirt_connect_get_information) tmp = virConnectGetURI(conn->conn); DPRINTF("%s: Got connection URI of %s...\n", PHPFUNC, tmp); array_init(return_value); - add_assoc_string_ex(return_value, "uri", 4, tmp ? tmp : "unknown", 1); + add_assoc_string_ex(return_value, "uri", 4, tmp ? tmp : "unknown" VIRT_COPY_OPT); free(tmp); tmp = virConnectGetHostname(conn->conn); - add_assoc_string_ex(return_value, "hostname", 9, tmp ? tmp : "unknown", 1); + add_assoc_string_ex(return_value, "hostname", 9, tmp ? tmp : "unknown" VIRT_COPY_OPT); free(tmp); if ((virConnectGetVersion(conn->conn, &hvVer) == 0) && (type = virConnectGetType(conn->conn))) { - add_assoc_string_ex(return_value, "hypervisor", 11, (char *)type, 1); + add_assoc_string_ex(return_value, "hypervisor", 11, (char *)type VIRT_COPY_OPT); add_assoc_long(return_value, "hypervisor_major",(long)((hvVer/1000000) % 1000)); add_assoc_long(return_value, "hypervisor_minor",(long)((hvVer/1000) % 1000)); add_assoc_long(return_value, "hypervisor_release",(long)(hvVer %1000)); snprintf(hvStr, sizeof(hvStr), "%s %d.%d.%d", type, (long)((hvVer/1000000) % 1000), (long)((hvVer/1000) % 1000), (long)(hvVer %1000)); - add_assoc_string_ex(return_value, "hypervisor_string", 18, hvStr, 1); + add_assoc_string_ex(return_value, "hypervisor_string", 18, hvStr VIRT_COPY_OPT); } if (strcmp(type, "QEMU") == 0) { @@ -2651,21 +2650,21 @@ PHP_FUNCTION(libvirt_connect_get_information) add_assoc_long(return_value, "hypervisor_maxvcpus", maxvcpus); iTmp = virConnectIsEncrypted(conn->conn); if (iTmp == 1) - add_assoc_string_ex(return_value, "encrypted", 10, "Yes", 1); + add_assoc_string_ex(return_value, "encrypted", 10, "Yes" VIRT_COPY_OPT); else if (iTmp == 0) - add_assoc_string_ex(return_value, "encrypted", 10, "No", 1); + add_assoc_string_ex(return_value, "encrypted", 10, "No" VIRT_COPY_OPT); else - add_assoc_string_ex(return_value, "encrypted", 10, "unknown", 1); + add_assoc_string_ex(return_value, "encrypted", 10, "unknown" VIRT_COPY_OPT); iTmp = virConnectIsSecure(conn->conn); if (iTmp == 1) - add_assoc_string_ex(return_value, "secure", 7, "Yes", 1); + add_assoc_string_ex(return_value, "secure", 7, "Yes" VIRT_COPY_OPT); else if (iTmp == 0) - add_assoc_string_ex(return_value, "secure", 7, "No", 1); + add_assoc_string_ex(return_value, "secure", 7, "No" VIRT_COPY_OPT); else - add_assoc_string_ex(return_value, "secure", 7, "unknown", 1); + add_assoc_string_ex(return_value, "secure", 7, "unknown" VIRT_COPY_OPT); add_assoc_long(return_value, "num_inactive_domains", virConnectNumOfDefinedDomains(conn->conn)); add_assoc_long(return_value, "num_inactive_interfaces", virConnectNumOfDefinedInterfaces(conn->conn)); @@ -2704,11 +2703,7 @@ PHP_FUNCTION(libvirt_connect_get_uri) DPRINTF("%s: virConnectGetURI returned %s\n", PHPFUNC, uri); if (uri == NULL) RETURN_FALSE; -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(uri); -#else - RETVAL_STRING(uri, 1); -#endif + RETVAL_STRING(uri VIRT_COPY_OPT); free(uri); } @@ -2731,11 +2726,7 @@ PHP_FUNCTION(libvirt_connect_get_hostname) DPRINTF("%s: virConnectGetHostname returned %s\n", PHPFUNC, hostname); if (hostname==NULL) RETURN_FALSE; -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(hostname); -#else - RETVAL_STRING(hostname, 1); -#endif + RETVAL_STRING(hostname VIRT_COPY_OPT); free(hostname); } @@ -2888,14 +2879,14 @@ PHP_FUNCTION(libvirt_connect_get_hypervisor) DPRINTF("%s: virConnectGetType returned %s\n", PHPFUNC, type); array_init(return_value); - add_assoc_string_ex(return_value, "hypervisor", 11, (char *)type, 1); + add_assoc_string_ex(return_value, "hypervisor", 11, (char *)type VIRT_COPY_OPT); add_assoc_long(return_value, "major",(long)((hvVer/1000000) % 1000)); add_assoc_long(return_value, "minor",(long)((hvVer/1000) % 1000)); add_assoc_long(return_value, "release",(long)(hvVer %1000)); snprintf(hvStr, sizeof(hvStr), "%s %d.%d.%d", type, (long)((hvVer/1000000) % 1000), (long)((hvVer/1000) % 1000), (long)(hvVer %1000)); - add_assoc_string_ex(return_value, "hypervisor_string", 18, hvStr, 1); + add_assoc_string_ex(return_value, "hypervisor_string", 18, hvStr VIRT_COPY_OPT); } /* @@ -2990,7 +2981,7 @@ PHP_FUNCTION(libvirt_connect_get_all_domain_stats) add_assoc_bool(arr2, params.field, params.value.b); break; case VIR_TYPED_PARAM_STRING: - add_assoc_string_ex(arr2, params.field, strlen(params.field)+1, params.value.s, strlen(params.value.s)+1); + add_assoc_string_ex(arr2, params.field, strlen(params.field)+1, params.value.s VIRT_COPY_OPT); break; } } @@ -3043,11 +3034,7 @@ PHP_FUNCTION(libvirt_connect_get_sysinfo) sysinfo=virConnectGetSysinfo(conn->conn, 0); if (sysinfo==NULL) RETURN_FALSE; -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(sysinfo); -#else - RETVAL_STRING(sysinfo, 1); -#endif + RETVAL_STRING(sysinfo VIRT_COPY_OPT); free(sysinfo); } @@ -3115,7 +3102,7 @@ char *get_string_from_xpath(char *xml, char *xpath, zval **val, int *retVal) value = (char *)xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1); snprintf(key, sizeof(key), "%d", i); - add_assoc_string_ex(*val, key, strlen(key)+1, value, 1); + add_assoc_string_ex(*val, key, strlen(key)+1, value VIRT_COPY_OPT); ret++; } } @@ -4019,11 +4006,7 @@ PHP_FUNCTION(libvirt_domain_get_metadata) } } else { -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(ret); -#else - RETVAL_STRING(ret, 1); -#endif + RETVAL_STRING(ret VIRT_COPY_OPT); free(ret); } } @@ -4176,11 +4159,7 @@ PHP_FUNCTION(libvirt_domain_qemu_agent_command) ret = virDomainQemuAgentCommand(domain->domain, cmd, timeout, flags); if (ret == NULL) RETURN_FALSE; -#if PHP_MAJOR_VERSION >= 7 - RETURN_STRING(ret); -#else - RETURN_STRING(ret, 1); -#endif + RETURN_STRING(ret VIRT_COPY_OPT); } /* @@ -4480,11 +4459,7 @@ PHP_FUNCTION(libvirt_domain_get_name) DPRINTF("%s: virDomainGetName(%p) returned %s\n", PHPFUNC, domain->domain, name); if (name==NULL) RETURN_FALSE; -#if PHP_MAJOR_VERSION >= 7 - RETURN_STRING(name); -#else - RETURN_STRING(name, 1); //we can use the copy mechanism as we need not to free name (we even can not!) -#endif + RETURN_STRING(name VIRT_COPY_OPT); //we can use the copy mechanism as we need not to free name (we even can not!) } /* @@ -4509,7 +4484,7 @@ PHP_FUNCTION(libvirt_domain_get_uuid_string) if (retval!=0) RETURN_FALSE; #if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(uuid); + RETVAL_STRING(uuid VIRT_COPY_OPT); efree(uuid); #else RETURN_STRING(uuid,0); @@ -4610,12 +4585,12 @@ PHP_FUNCTION(libvirt_domain_get_screenshot_api) if (WEXITSTATUS(exitStatus) != 0) RETURN_FALSE; - add_assoc_string_ex(return_value, "file", 5, fileNew, 1); - add_assoc_string_ex(return_value, "mime", 5, "image/png", 1); + add_assoc_string_ex(return_value, "file", 5, fileNew VIRT_COPY_OPT); + add_assoc_string_ex(return_value, "mime", 5, "image/png" VIRT_COPY_OPT); } else { - add_assoc_string_ex(return_value, "file", 5, file, 1); - add_assoc_string_ex(return_value, "mime", 5, mime, 1); + add_assoc_string_ex(return_value, "file", 5, file VIRT_COPY_OPT); + add_assoc_string_ex(return_value, "mime", 5, mime VIRT_COPY_OPT); } } @@ -5073,17 +5048,9 @@ PHP_FUNCTION(libvirt_connect_get_capabilities) tmp = get_string_from_xpath(caps, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(caps); -#else - RETVAL_STRING(caps, 1); -#endif + RETVAL_STRING(caps VIRT_COPY_OPT); } else { -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(tmp); -#else - RETVAL_STRING(tmp, 1); -#endif + RETVAL_STRING(tmp VIRT_COPY_OPT); } free(caps); @@ -5118,11 +5085,7 @@ PHP_FUNCTION(libvirt_connect_get_emulator) RETURN_FALSE; } -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(tmp); -#else - RETVAL_STRING(tmp, 1); -#endif + RETVAL_STRING(tmp VIRT_COPY_OPT); free(tmp); } @@ -5187,7 +5150,7 @@ PHP_FUNCTION(libvirt_connect_get_nic_models) tTokenizer t = tokenize(tmp, ","); for (i = 0; i < t.numTokens; i++) { snprintf(tmp2, sizeof(tmp2), "%d", i); - add_assoc_string_ex(return_value, tmp2, strlen(tmp2) + 1, t.tokens[i], 1); + add_assoc_string_ex(return_value, tmp2, strlen(tmp2) + 1, t.tokens[i] VIRT_COPY_OPT); } free_tokens(t); } @@ -5280,14 +5243,14 @@ PHP_FUNCTION(libvirt_connect_get_soundhw_models) zval *arr; ALLOC_INIT_ZVAL(arr); array_init(arr); - add_assoc_string_ex(arr, "name", 5, t.tokens[0], 1); - add_assoc_string_ex(arr, "description", 12, desc, 1); + add_assoc_string_ex(arr, "name", 5, t.tokens[0] VIRT_COPY_OPT); + add_assoc_string_ex(arr, "description", 12, desc VIRT_COPY_OPT); add_next_index_zval(return_value, arr); } else { char tmp2[16] = { 0 }; snprintf(tmp2, sizeof(tmp2), "%d", n++); - add_assoc_string_ex(return_value, tmp2, strlen(tmp2) + 1, t.tokens[0], 1); + add_assoc_string_ex(return_value, tmp2, strlen(tmp2) + 1, t.tokens[0] VIRT_COPY_OPT); } free_tokens(t); @@ -5554,11 +5517,7 @@ PHP_FUNCTION(libvirt_domain_new) PHP_FUNCTION(libvirt_domain_new_get_vnc) { if (LIBVIRT_G(vnc_location)) -#if PHP_MAJOR_VERSION >= 7 - RETURN_STRING(LIBVIRT_G(vnc_location)); -#else - RETURN_STRING(LIBVIRT_G(vnc_location),1); -#endif + RETURN_STRING(LIBVIRT_G(vnc_location) VIRT_COPY_OPT); RETURN_NULL(); } @@ -5596,17 +5555,9 @@ PHP_FUNCTION(libvirt_domain_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(xml); -#else - RETVAL_STRING(xml, 1); -#endif + RETVAL_STRING(xml VIRT_COPY_OPT); } else { -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(tmp); -#else - RETVAL_STRING(tmp, 1); -#endif + RETVAL_STRING(tmp VIRT_COPY_OPT); } free(tmp); @@ -6760,8 +6711,8 @@ PHP_FUNCTION(libvirt_domain_get_network_info) } array_init(return_value); - add_assoc_string_ex(return_value, "mac", 4, mac, 1); - add_assoc_string_ex(return_value, "network", 8, tmp, 1); + add_assoc_string_ex(return_value, "mac", 4, mac VIRT_COPY_OPT); + add_assoc_string_ex(return_value, "network", 8, tmp VIRT_COPY_OPT); free(tmp); free(xpath); @@ -6772,9 +6723,9 @@ PHP_FUNCTION(libvirt_domain_get_network_info) } tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "nic_type", 9, tmp, 1); + add_assoc_string_ex(return_value, "nic_type", 9, tmp VIRT_COPY_OPT); else - add_assoc_string_ex(return_value, "nic_type", 9, "default", 1); + add_assoc_string_ex(return_value, "nic_type", 9, "default" VIRT_COPY_OPT); free(xml); free(xpath); @@ -6858,12 +6809,12 @@ PHP_FUNCTION(libvirt_domain_get_block_info) array_init(return_value); LONGLONG_INIT; - add_assoc_string_ex(return_value, "device", 7, dev, 1); + add_assoc_string_ex(return_value, "device", 7, dev VIRT_COPY_OPT); if (isFile) - add_assoc_string_ex(return_value, "file", 5, tmp, 1); + add_assoc_string_ex(return_value, "file", 5, tmp VIRT_COPY_OPT); else - add_assoc_string_ex(return_value, "partition", 10, tmp, 1); + add_assoc_string_ex(return_value, "partition", 10, tmp VIRT_COPY_OPT); free(xpath); if (asprintf(&xpath, "//domain/devices/disk/target[@dev='%s']/../driver/@type", dev) < 0) { @@ -6873,7 +6824,7 @@ PHP_FUNCTION(libvirt_domain_get_block_info) free(tmp); tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if (tmp != NULL) - add_assoc_string_ex(return_value, "type", 5, tmp, 1); + add_assoc_string_ex(return_value, "type", 5, tmp VIRT_COPY_OPT); LONGLONG_ASSOC(return_value, "capacity", info.capacity); LONGLONG_ASSOC(return_value, "allocation", info.allocation); @@ -6929,7 +6880,7 @@ PHP_FUNCTION(libvirt_domain_xml_xpath) if (rc == 0) RETURN_FALSE; - add_assoc_string_ex(return_value, "xpath", 6, (char *)zpath, 1); + add_assoc_string_ex(return_value, "xpath", 6, (char *)zpath VIRT_COPY_OPT); if (rc < 0) add_assoc_long(return_value, "error_code", (long)rc); } @@ -7289,11 +7240,7 @@ PHP_FUNCTION(libvirt_domain_snapshot_get_xml) xml = virDomainSnapshotGetXMLDesc(snapshot->snapshot, flags); if (xml==NULL) RETURN_FALSE; -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(xml); -#else - RETVAL_STRING(xml, 1); -#endif + RETVAL_STRING(xml VIRT_COPY_OPT); free(xml); } @@ -7622,11 +7569,7 @@ PHP_FUNCTION(libvirt_storagevolume_get_name) DPRINTF("%s: virStorageVolGetName(%p) returned %s\n", PHPFUNC, volume->volume, retval); if (retval == NULL) RETURN_FALSE; -#if PHP_MAJOR_VERSION >= 7 - RETURN_STRING(retval); -#else - RETURN_STRING (retval, 1); -#endif + RETURN_STRING(retval VIRT_COPY_OPT); } /* @@ -7648,11 +7591,7 @@ PHP_FUNCTION(libvirt_storagevolume_get_path) DPRINTF("%s: virStorageVolGetPath(%p) returned %s\n", PHPFUNC, volume->volume, retval); if (retval == NULL) RETURN_FALSE; -#if PHP_MAJOR_VERSION >= 7 - RETURN_STRING(retval); -#else - RETURN_STRING (retval, 1); -#endif + RETURN_STRING(retval VIRT_COPY_OPT); } /* @@ -7716,17 +7655,9 @@ PHP_FUNCTION(libvirt_storagevolume_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(xml); -#else - RETVAL_STRING(xml, 1); -#endif + RETVAL_STRING(xml VIRT_COPY_OPT); } else { -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(tmp); -#else - RETVAL_STRING(tmp, 1); -#endif + RETVAL_STRING(tmp VIRT_COPY_OPT); } free(xml); @@ -8010,11 +7941,7 @@ PHP_FUNCTION(libvirt_storagepool_get_name) if (name == NULL) RETURN_FALSE; -#if PHP_MAJOR_VERSION >= 7 - RETURN_STRING(name); -#else - RETURN_STRING(name, 1); -#endif + RETURN_STRING(name VIRT_COPY_OPT); } /* @@ -8091,17 +8018,9 @@ PHP_FUNCTION(libvirt_storagepool_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(xml); -#else - RETVAL_STRING(xml, 1); -#endif + RETVAL_STRING(xml VIRT_COPY_OPT); } else { -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(tmp); -#else - RETVAL_STRING(tmp, 1); -#endif + RETVAL_STRING(tmp VIRT_COPY_OPT); } free(xml); @@ -9002,17 +8921,9 @@ PHP_FUNCTION(libvirt_nodedev_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(xml); -#else - RETVAL_STRING(xml, 1); -#endif + RETVAL_STRING(xml VIRT_COPY_OPT); } else { -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(tmp); -#else - RETVAL_STRING(tmp, 1); -#endif + RETVAL_STRING(tmp VIRT_COPY_OPT); } free(xml); @@ -9057,18 +8968,18 @@ PHP_FUNCTION(libvirt_nodedev_get_information) goto error; } - add_assoc_string_ex(return_value, "name", 5, tmp, 1); + add_assoc_string_ex(return_value, "name", 5, tmp VIRT_COPY_OPT); /* Get parent name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/parent", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "parent", 7, tmp, 1); + add_assoc_string_ex(return_value, "parent", 7, tmp VIRT_COPY_OPT); /* Get capability */ cap = get_string_from_xpath(xml, "//device/capability/@type", NULL, &retval); if ((cap != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "capability", 11, cap, 1); + add_assoc_string_ex(return_value, "capability", 11, cap VIRT_COPY_OPT); /* System capability is having hardware and firmware sub-blocks */ if (strcmp(cap, "system") == 0) { @@ -9076,92 +8987,92 @@ PHP_FUNCTION(libvirt_nodedev_get_information) free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/hardware/vendor", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "hardware_vendor", 16, tmp, 1); + add_assoc_string_ex(return_value, "hardware_vendor", 16, tmp VIRT_COPY_OPT); /* Get hardware version */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/hardware/version", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "hardware_version", 17, tmp, 1); + add_assoc_string_ex(return_value, "hardware_version", 17, tmp VIRT_COPY_OPT); /* Get hardware serial */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/hardware/serial", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "hardware_serial", 16, tmp, 1); + add_assoc_string_ex(return_value, "hardware_serial", 16, tmp VIRT_COPY_OPT); /* Get hardware UUID */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/hardware/uuid", NULL, &retval); if (tmp != NULL) - add_assoc_string_ex(return_value, "hardware_uuid", 15, tmp, 1); + add_assoc_string_ex(return_value, "hardware_uuid", 15, tmp VIRT_COPY_OPT); /* Get firmware vendor */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/firmware/vendor", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "firmware_vendor", 16, tmp, 1); + add_assoc_string_ex(return_value, "firmware_vendor", 16, tmp VIRT_COPY_OPT); /* Get firmware version */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/firmware/version", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "firmware_version", 17, tmp, 1); + add_assoc_string_ex(return_value, "firmware_version", 17, tmp VIRT_COPY_OPT); /* Get firmware release date */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/firmware/release_date", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "firmware_release_date", 22, tmp, 1); + add_assoc_string_ex(return_value, "firmware_release_date", 22, tmp VIRT_COPY_OPT); } /* Get product_id */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/product/@id", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "product_id", 11, tmp, 1); + add_assoc_string_ex(return_value, "product_id", 11, tmp VIRT_COPY_OPT); /* Get product_name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/product", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "product_name", 13, tmp, 1); + add_assoc_string_ex(return_value, "product_name", 13, tmp VIRT_COPY_OPT); /* Get vendor_id */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/vendor/@id", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "vendor_id", 10, tmp, 1); + add_assoc_string_ex(return_value, "vendor_id", 10, tmp VIRT_COPY_OPT); /* Get vendor_name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/vendor", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "vendor_name", 12, tmp, 1); + add_assoc_string_ex(return_value, "vendor_name", 12, tmp VIRT_COPY_OPT); /* Get driver name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/driver/name", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "driver_name", 12, tmp, 1); + add_assoc_string_ex(return_value, "driver_name", 12, tmp VIRT_COPY_OPT); /* Get driver name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/interface", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "interface_name", 15, tmp, 1); + add_assoc_string_ex(return_value, "interface_name", 15, tmp VIRT_COPY_OPT); /* Get driver name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/address", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "address", 8, tmp, 1); + add_assoc_string_ex(return_value, "address", 8, tmp VIRT_COPY_OPT); /* Get driver name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/capability/@type", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "capabilities", 11, tmp, 1); + add_assoc_string_ex(return_value, "capabilities", 11, tmp VIRT_COPY_OPT); free(cap); free(tmp); @@ -9293,11 +9204,7 @@ PHP_FUNCTION(libvirt_network_get_bridge) RETURN_FALSE; } -#if PHP_MAJOR_VERSION >= 7 - RETURN_STRING(name); -#else - RETURN_STRING(name, 1); -#endif + RETURN_STRING(name VIRT_COPY_OPT); } /* @@ -9370,42 +9277,42 @@ PHP_FUNCTION(libvirt_network_get_information) RETURN_FALSE; } - add_assoc_string_ex(return_value, "name", 5, name, 1); + add_assoc_string_ex(return_value, "name", 5, name VIRT_COPY_OPT); /* Get gateway IP address */ ipaddr = get_string_from_xpath(xml, "//network/ip/@address", NULL, &retval); if (ipaddr && retval > 0) - add_assoc_string_ex(return_value, "ip", 3, ipaddr, 1); + add_assoc_string_ex(return_value, "ip", 3, ipaddr VIRT_COPY_OPT); /* Get netmask */ netmask = get_string_from_xpath(xml, "//network/ip/@netmask", NULL, &retval); if (netmask && retval > 0) { int subnet_bits = get_subnet_bits(netmask); - add_assoc_string_ex(return_value, "netmask", 8, netmask, 1); + add_assoc_string_ex(return_value, "netmask", 8, netmask VIRT_COPY_OPT); add_assoc_long(return_value, "netmask_bits", (long) subnet_bits); /* Format CIDR address representation */ ipaddr[strlen(ipaddr) - 1] = ipaddr[strlen(ipaddr) - 1] - 1; snprintf(fixedtemp, sizeof(fixedtemp), "%s/%d", ipaddr, subnet_bits); - add_assoc_string_ex(return_value, "ip_range", 9, fixedtemp, 1); + add_assoc_string_ex(return_value, "ip_range", 9, fixedtemp VIRT_COPY_OPT); } /* Get forwarding settings */ mode = get_string_from_xpath(xml, "//network/forward/@mode", NULL, &retval); if (mode && retval > 0) - add_assoc_string_ex(return_value, "forwarding", 11, mode, 1); + add_assoc_string_ex(return_value, "forwarding", 11, mode VIRT_COPY_OPT); /* Get forwarding settings */ dev = get_string_from_xpath(xml, "//network/forward/@dev", NULL, &retval); if (dev && retval > 0) - add_assoc_string_ex(return_value, "forward_dev", 12, dev, 1); + add_assoc_string_ex(return_value, "forward_dev", 12, dev VIRT_COPY_OPT); /* Get DHCP values */ dhcp_start = get_string_from_xpath(xml, "//network/ip/dhcp/range/@start", NULL, &retval); dhcp_end = get_string_from_xpath(xml, "//network/ip/dhcp/range/@end", NULL, &retval); if (dhcp_start && dhcp_end && retval > 0) { - add_assoc_string_ex(return_value, "dhcp_start", 11, dhcp_start, 1); - add_assoc_string_ex(return_value, "dhcp_end", 9, dhcp_end, 1); + add_assoc_string_ex(return_value, "dhcp_start", 11, dhcp_start VIRT_COPY_OPT); + add_assoc_string_ex(return_value, "dhcp_end", 9, dhcp_end VIRT_COPY_OPT); } free(dhcp_end); @@ -9497,17 +9404,9 @@ PHP_FUNCTION(libvirt_network_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(xml); -#else - RETVAL_STRING(xml, 1); -#endif + RETVAL_STRING(xml VIRT_COPY_OPT); } else { -#if PHP_MAJOR_VERSION >= 7 - RETVAL_STRING(tmp); -#else - RETVAL_STRING(tmp, 1); -#endif + RETVAL_STRING(tmp VIRT_COPY_OPT); } free(xml); @@ -9547,7 +9446,7 @@ PHP_FUNCTION(libvirt_version) add_assoc_long(return_value, "libvirt.minor",(long)((libVer/1000) % 1000)); add_assoc_long(return_value, "libvirt.major",(long)((libVer/1000000) % 1000)); - add_assoc_string_ex(return_value, "connector.version", 18, PHP_LIBVIRT_WORLD_VERSION, 1); + add_assoc_string_ex(return_value, "connector.version", 18, PHP_LIBVIRT_WORLD_VERSION VIRT_COPY_OPT); add_assoc_long(return_value, "connector.major", VERSION_MAJOR); add_assoc_long(return_value, "connector.minor", VERSION_MINOR); add_assoc_long(return_value, "connector.release", VERSION_MICRO); -- 2.5.5

On 09.04.2016 00:08, Neal Gompa wrote:
From: Remi Collet <fedora@famillecollet.com>
--- src/libvirt-php.c | 299 ++++++++++++++++++------------------------------------ 1 file changed, 99 insertions(+), 200 deletions(-)
diff --git a/src/libvirt-php.c b/src/libvirt-php.c index d37fd6f..0459bb9 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -58,6 +58,7 @@ const char *features_binaries[] = { NULL }; #if PHP_MAJOR_VERSION >= 7 typedef size_t strsize_t;
+#define VIRT_COPY_OPT #define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \ if ((_state = (_type)zend_fetch_resource(Z_RES_P(*_zval), _name, _le)) == NULL) { \ RETURN_FALSE; \ @@ -68,6 +69,8 @@ typedef int strsize_t; typedef long zend_long; typedef unsigned long zend_ulong;
+#define VIRT_COPY_OPT ,1 + #define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \ ZEND_FETCH_RESOURCE(_state, _type, _zval, -1, _name, _le);
@@ -1995,7 +1998,7 @@ if ((snapshot==NULL) || (snapshot->snapshot==NULL)) RETURN_FALSE;\ #define LONGLONG_ASSOC(out,key,in) \ if (LIBVIRT_G(longlong_to_string_ini)) { \ snprintf(tmpnumber,63,"%llu",in); \ - add_assoc_string_ex(out,key,strlen(key)+1,tmpnumber,1); \ + add_assoc_string_ex(out,key,strlen(key)+1,tmpnumber VIRT_COPY_OPT); \ } \ else \ { \ @@ -2059,11 +2062,7 @@ static int libvirt_virConnectCredType[] = { PHP_FUNCTION(libvirt_get_last_error) { if (LIBVIRT_G (last_error) == NULL) RETURN_NULL(); -#if PHP_MAJOR_VERSION >= 7 - RETURN_STRING(LIBVIRT_G (last_error)); -#else - RETURN_STRING(LIBVIRT_G (last_error),1); -#endif + RETURN_STRING(LIBVIRT_G (last_error) VIRT_COPY_OPT);
I'm afraid, this will not fly. While preprocessing this code, my compiler tries to expand RETURN_STRING() macro first (with VIRT_COPY_OPT still not expanded). Therefore it finds an argument missing and produces an compilation error. What we can do here is create a wrapper over RETURN_STRING, e.g. VIR_RETURN_STRING() that will behave differently for PHP7 and the rest. Unfortunately, this is where I have to stop the review as it's getting hairy and I gotta run. Sorry. Michal

On Tue, Apr 12, 2016 at 11:13 AM, Michal Privoznik <mprivozn@redhat.com> wrote:
I'm afraid, this will not fly. While preprocessing this code, my compiler tries to expand RETURN_STRING() macro first (with VIRT_COPY_OPT still not expanded). Therefore it finds an argument missing and produces an compilation error. What we can do here is create a wrapper over RETURN_STRING, e.g. VIR_RETURN_STRING() that will behave differently for PHP7 and the rest.
Unfortunately, this is where I have to stop the review as it's getting hairy and I gotta run. Sorry.
Michal
Unfortunately, I cannot reproduce your problem. On my CentOS 7.2 system, I built, installed, and tested using gcc-4.8.5-4.el7 with libvirt-1.2.17-13.el7_2.4 and its associated devel package. I've compiled it as a PHP 5.4 module (using the default PHP), as a PHP 5.6 module (using Remi's SCL for PHP 5.6), and as a PHP 7.0 module (using Remi's SCL for PHP 7.0). It worked properly with both build systems, and all 17 tests passed with the `make test` run on the newer build system. For reference on my CentOS 7.2 system, I'm using the following: * gcc-4.8.5-4.el7 * libvirt-daemon-1.2.17-13.el7_2.4 * libvirt-devel-1.2.17-13.el7_2.4 * xz-devel-5.1.2-12alpha.el7 * libxml2-devel-2.9.1-6.el7_2.2 * libxslt-1.1.28-5.el7 * xhtml1-dtds-1.0-20020801.11.el7 Here are the PHP packages I have installed: * php-cli-5.4.16-36.el7_1 * php-common-5.4.16-36.el7_1 * php-devel-5.4.16-36.el7_1 * php56-runtime-2.1-5.el7.remi * php56-php-cli-5.6.20-1.el7.remi * php56-php-pecl-jsonc-1.3.9-1.el7.remi * php56-php-pecl-zip-1.13.2-1.el7.remi * php56-php-pecl-jsonc-devel-1.3.9-1.el7.remi * php56-php-common-5.6.20-1.el7.remi * php56-php-devel-5.6.20-1.el7.remi * php70-runtime-1.0-4.el7.remi * php70-php-json-7.0.5-1.el7.remi * php70-php-cli-7.0.5-1.el7.remi * php70-php-common-7.0.5-1.el7.remi * php70-php-devel-7.0.5-1.el7.remi For kicks, I tested on Fedora 23 with the latest system libvirt and php 5.6 packages available, and everything seems to work as expected. Here are the packages on my Fedora system: * gcc-5.3.1-2.fc23 * libvirt-daemon-1.2.18.2-3.fc23 * libvirt-devel-1.2.18.2-3.fc23 * xz-devel-5.2.1-3.fc23 * libxml2-devel-2.9.3-2.fc23 * libxslt-1.1.28-11.fc23 * xhtml1-dtds-1.0-20020801.13.fc23 Here are the PHP packages on my Fedora system: * php-cli-5.6.20-1.fc23 * php-common-5.6.20-1.fc23 * php-pecl-jsonc-1.3.9-1.fc23 * php-pecl-jsonc-devel-1.3.9-1.fc23 * php-devel-5.6.20-1.fc23 Obviously there's some kind of mismatch in my environment and yours that is causing problems. Could you please tell me what your environment is and what you're using so that I can see if I can reproduce the issue? -- 真実はいつも一つ!/ Always, there's only one truth!

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 9 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 0459bb9..3ce8370 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -2285,7 +2285,11 @@ PHP_FUNCTION(libvirt_node_get_cpu_stats) array_init(return_value); for (i = 0; i < 2; i++) { +#if PHP_MAJOR_VERSION >= 7 + zval *arr, zarr; +#else zval *arr; +#endif if (i > 0) #ifdef EXTWIN Sleep(1000); @@ -2298,7 +2302,11 @@ PHP_FUNCTION(libvirt_node_get_cpu_stats) RETURN_FALSE; } +#if PHP_MAJOR_VERSION >= 7 + arr = &zarr; +#else ALLOC_INIT_ZVAL(arr); +#endif array_init(arr); for (j = 0; j < nparams; j++) { @@ -2344,7 +2352,11 @@ PHP_FUNCTION(libvirt_node_get_cpu_stats_for_each_cpu) int done = 0; int i, j, numCpus; time_t startTime = 0; +#if PHP_MAJOR_VERSION >= 7 + zval *time_array, ztime_array; +#else zval *time_array; +#endif GET_CONNECTION_FROM_ARGS("r|l", &zconn, &avg); @@ -2374,19 +2386,32 @@ PHP_FUNCTION(libvirt_node_get_cpu_stats_for_each_cpu) iter = 0; done = 0; while ( !done ) { +#if PHP_MAJOR_VERSION >= 7 + zval *arr, zarr; + arr = &zarr; +#else zval *arr; - ALLOC_INIT_ZVAL(arr); +#endif + array_init(arr); for (i = 0; i < numCpus; i++) { +#if PHP_MAJOR_VERSION >= 7 + zval *arr2, zarr2; +#else zval *arr2; +#endif if (virNodeGetCPUStats(conn->conn, i, params, &nparams, 0) != 0) { set_error("Unable to get node cpu stats" TSRMLS_CC); RETURN_FALSE; } +#if PHP_MAJOR_VERSION >= 7 + arr2 = &zarr2; +#else ALLOC_INIT_ZVAL(arr2); +#endif array_init(arr2); for (j = 0; j < nparams; j++) @@ -2411,7 +2436,11 @@ PHP_FUNCTION(libvirt_node_get_cpu_stats_for_each_cpu) iter++; } +#if PHP_MAJOR_VERSION >= 7 + time_array = &ztime_array; +#else ALLOC_INIT_ZVAL(time_array); +#endif array_init(time_array); add_assoc_long(time_array, "start", startTime); @@ -2507,8 +2536,13 @@ PHP_FUNCTION(libvirt_connect_get_machine_types) snprintf(tmp, sizeof(tmp), "//capabilities/guest/arch[@name=\"%s\"]/domain/@type", ret[i]); char **ret2 = get_array_from_xpath(caps, tmp, &num2); if (ret2 != NULL) { +#if PHP_MAJOR_VERSION >= 7 + zval *arr2, zarr2; + arr2 = &zarr2; +#else zval *arr2; ALLOC_INIT_ZVAL(arr2); +#endif array_init(arr2); for (j = 0; j < num2; j++) { @@ -2516,8 +2550,13 @@ PHP_FUNCTION(libvirt_connect_get_machine_types) char tmp2[1024] = { 0 }; /* Common */ +#if PHP_MAJOR_VERSION >= 7 + zval *arr3, zarr3; + arr3 = &zarr3; +#else zval *arr3; ALLOC_INIT_ZVAL(arr3); +#endif array_init(arr3); snprintf(tmp2, sizeof(tmp2), "//capabilities/guest/arch[@name=\"%s\"]/machine", @@ -2540,8 +2579,13 @@ PHP_FUNCTION(libvirt_connect_get_machine_types) if (numTmp == NULL) add_assoc_string_ex(arr2, key, strlen(key) + 1, ret3[k] VIRT_COPY_OPT); else { +#if PHP_MAJOR_VERSION >= 7 + zval *arr4, zarr4; + arr4 = &zarr4; +#else zval *arr4; ALLOC_INIT_ZVAL(arr4); +#endif array_init(arr4); add_assoc_string_ex(arr4, "name", 5, ret3[k] VIRT_COPY_OPT); @@ -2575,8 +2619,13 @@ PHP_FUNCTION(libvirt_connect_get_machine_types) if (numTmp == NULL) add_assoc_string_ex(arr3, key, strlen(key) + 1, ret3[k] VIRT_COPY_OPT); else { +#if PHP_MAJOR_VERSION >= 7 + zval *arr4, zarr4; + arr4 = &zarr4; +#else zval *arr4; ALLOC_INIT_ZVAL(arr4); +#endif array_init(arr4); add_assoc_string_ex(arr4, "name", 5, ret3[k] VIRT_COPY_OPT); @@ -2956,8 +3005,13 @@ PHP_FUNCTION(libvirt_connect_get_all_domain_stats) RETURN_FALSE; for (i=0; i < retval; i++) { +#if PHP_MAJOR_VERSION >= 7 + zval *arr2, zarr2; + arr2 = &zarr2; +#else zval *arr2; ALLOC_INIT_ZVAL(arr2); +#endif array_init(arr2); for (j = 0; j < retstats[i]->nparams; j++) { params = retstats[i]->params[j]; @@ -5233,6 +5287,13 @@ PHP_FUNCTION(libvirt_connect_get_soundhw_models) continue; if ((i > 0) && (flags & CONNECT_FLAG_SOUNDHW_GET_NAMES)) { +#if PHP_MAJOR_VERSION >= 7 + zval *arr, zarr; + arr = &zarr; +#else + zval *arr; + ALLOC_INIT_ZVAL(arr); +#endif memset(desc, 0, sizeof(desc)); for (i = 1; i < t.numTokens; i++) { strcat(desc, t.tokens[i]); @@ -5240,8 +5301,6 @@ PHP_FUNCTION(libvirt_connect_get_soundhw_models) strcat(desc, " "); } - zval *arr; - ALLOC_INIT_ZVAL(arr); array_init(arr); add_assoc_string_ex(arr, "name", 5, t.tokens[0] VIRT_COPY_OPT); add_assoc_string_ex(arr, "description", 12, desc VIRT_COPY_OPT); @@ -8513,7 +8572,11 @@ PHP_FUNCTION(libvirt_list_domain_resources) { php_libvirt_connection *conn=NULL; zval *zconn; +#if PHP_MAJOR_VERSION >= 7 + zval zdomain; +#else zval *zdomain; +#endif int count=-1; int expectedcount=-1; int *ids; @@ -8543,16 +8606,17 @@ PHP_FUNCTION(libvirt_list_domain_resources) res_domain= (php_libvirt_domain *)emalloc(sizeof(php_libvirt_domain)); res_domain->domain = domain; - ALLOC_INIT_ZVAL(zdomain); res_domain->conn=conn; resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, res_domain->domain, 1 TSRMLS_CC); #if PHP_MAJOR_VERSION >= 7 - ZVAL_RES(return_value, zend_register_resource(res_domain, le_libvirt_domain)); + ZVAL_RES(&zdomain, zend_register_resource(res_domain, le_libvirt_domain)); + add_next_index_zval(return_value, &zdomain); #else + ALLOC_INIT_ZVAL(zdomain); ZEND_REGISTER_RESOURCE(zdomain, res_domain, le_libvirt_domain); -#endif add_next_index_zval(return_value, zdomain); +#endif } } efree(ids); @@ -8573,16 +8637,17 @@ PHP_FUNCTION(libvirt_list_domain_resources) res_domain = (php_libvirt_domain *)emalloc(sizeof(php_libvirt_domain)); res_domain->domain = domain; - ALLOC_INIT_ZVAL(zdomain); res_domain->conn=conn; #if PHP_MAJOR_VERSION >= 7 - ZVAL_RES(return_value, zend_register_resource(res_domain, le_libvirt_domain)); + ZVAL_RES(&zdomain, zend_register_resource(res_domain, le_libvirt_domain)); + add_next_index_zval(return_value, &zdomain); #else + ALLOC_INIT_ZVAL(zdomain); ZEND_REGISTER_RESOURCE(zdomain, res_domain, le_libvirt_domain); + add_next_index_zval(return_value, zdomain); #endif resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, res_domain->domain, 1 TSRMLS_CC); - add_next_index_zval(return_value, zdomain); } free(names[i]); } -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 3ce8370..3dba7a0 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -3040,7 +3040,11 @@ PHP_FUNCTION(libvirt_connect_get_all_domain_stats) } } name = virDomainGetName(retstats[i]->dom); +#if PHP_MAJOR_VERSION >= 7 + zend_hash_update(Z_ARRVAL_P(return_value), zend_string_init(name, strlen(name), 0), arr2); +#else zend_hash_update(Z_ARRVAL_P(return_value), name, strlen(name)+1, &arr2, sizeof(arr2), NULL); +#endif } virDomainStatsRecordListFree(retstats); -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 3dba7a0..c1587f9 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -7387,7 +7387,7 @@ PHP_FUNCTION(libvirt_list_domain_snapshots) array_init(return_value); for (i=0;i<count;i++) { - add_next_index_string(return_value, names[i], 1); + add_next_index_string(return_value, names[i] VIRT_COPY_OPT); free(names[i]); } } @@ -7498,7 +7498,7 @@ PHP_FUNCTION(libvirt_storagepool_list_volumes) if ((count != expectedcount) || (count<0)) RETURN_FALSE; for (i=0;i<count;i++) { - add_next_index_string(return_value, names[i],1); + add_next_index_string(return_value, names[i] VIRT_COPY_OPT); free(names[i]); } @@ -8390,7 +8390,7 @@ PHP_FUNCTION(libvirt_list_storagepools) array_init(return_value); for (i=0;i<count;i++) { - add_next_index_string(return_value, names[i],1); + add_next_index_string(return_value, names[i] VIRT_COPY_OPT); free(names[i]); } efree(names); @@ -8407,7 +8407,7 @@ PHP_FUNCTION(libvirt_list_storagepools) for (i = 0; i < count; i++) { - add_next_index_string (return_value, names[i], 1); + add_next_index_string (return_value, names[i] VIRT_COPY_OPT); free (names[i]); } efree (names); @@ -8444,7 +8444,7 @@ PHP_FUNCTION(libvirt_list_active_storagepools) array_init(return_value); for (i=0;i<count;i++) { - add_next_index_string(return_value, names[i],1); + add_next_index_string(return_value, names[i] VIRT_COPY_OPT); free(names[i]); } efree(names); @@ -8480,7 +8480,7 @@ PHP_FUNCTION(libvirt_list_inactive_storagepools) array_init(return_value); for (i = 0; i < count; i++) { - add_next_index_string (return_value, names[i], 1); + add_next_index_string (return_value, names[i] VIRT_COPY_OPT); free (names[i]); } efree (names); @@ -8524,7 +8524,7 @@ PHP_FUNCTION(libvirt_list_domains) name=virDomainGetName(domain); if (name != NULL) { DPRINTF("%s: Found running domain %s with ID = %d\n", PHPFUNC, name, ids[i]); - add_next_index_string(return_value, name, 1); + add_next_index_string(return_value, name VIRT_COPY_OPT); } else DPRINTF("%s: Cannot get ID for running domain %d\n", PHPFUNC, ids[i]); @@ -8558,7 +8558,7 @@ PHP_FUNCTION(libvirt_list_domains) for (i=0;i<count;i++) { - add_next_index_string(return_value, names[i], 1); + add_next_index_string(return_value, names[i] VIRT_COPY_OPT); DPRINTF("%s: Found inactive domain %s\n", PHPFUNC, names[i]); free(names[i]); } @@ -8740,7 +8740,7 @@ PHP_FUNCTION(libvirt_list_active_domains) RETURN_FALSE; } - add_next_index_string(return_value, name, 1); + add_next_index_string(return_value, name VIRT_COPY_OPT); } } efree(ids); @@ -8777,7 +8777,7 @@ PHP_FUNCTION(libvirt_list_inactive_domains) array_init(return_value); for (i=0;i<count;i++) { - add_next_index_string(return_value, names[i],1); + add_next_index_string(return_value, names[i] VIRT_COPY_OPT); free(names[i]); } efree(names); @@ -8816,7 +8816,7 @@ PHP_FUNCTION(libvirt_list_networks) for (i=0;i<count;i++) { - add_next_index_string(return_value, names[i], 1); + add_next_index_string(return_value, names[i]); free(names[i]); } @@ -8880,7 +8880,7 @@ PHP_FUNCTION(libvirt_list_nodedevs) array_init(return_value); for (i=0;i<count;i++) { - add_next_index_string(return_value, names[i], 1); + add_next_index_string(return_value, names[i] VIRT_COPY_OPT); free(names[i]); } @@ -8951,7 +8951,7 @@ PHP_FUNCTION(libvirt_nodedev_capabilities) array_init(return_value); for (i=0;i<count;i++) { - add_next_index_string(return_value, names[i], 1); + add_next_index_string(return_value, names[i] VIRT_COPY_OPT); free(names[i]); } @@ -9640,7 +9640,7 @@ PHP_FUNCTION(libvirt_get_iso_images) array_init(return_value); while ((entry = readdir(d)) != NULL) { if (strcasecmp(entry->d_name + strlen(entry->d_name) - 4, ".iso") == 0) { - add_next_index_string(return_value, entry->d_name, 1); + add_next_index_string(return_value, entry->d_name VIRT_COPY_OPT); num++; } } @@ -9680,7 +9680,7 @@ PHP_FUNCTION(libvirt_print_binding_resources) else snprintf(tmp, sizeof(tmp), "Libvirt %s resource at 0x%"UINTx, translate_counter_type(binding_resources[i].type), binding_resources[i].mem); - add_next_index_string(return_value, tmp, 1); + add_next_index_string(return_value, tmp VIRT_COPY_OPT); } } -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 98 +++++++++++++++++++++++++++++++++++++++++++++---------- src/libvirt-php.h | 4 +++ 2 files changed, 85 insertions(+), 17 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index c1587f9..1959074 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -2008,7 +2008,7 @@ else \ #define LONGLONG_INDEX(out,key,in) \ if (LIBVIRT_G(longlong_to_string_ini)) { \ snprintf(tmpnumber,63,"%llu",in); \ - add_index_string(out,key,tmpnumber,1); \ + add_index_string(out,key,tmpnumber VIRT_COPY_OPT); \ } \ else \ { \ @@ -2194,11 +2194,12 @@ PHP_FUNCTION(libvirt_connect) DPRINTF("%s: Connection to %s established, returning %p\n", PHPFUNC, url, conn->conn); #if PHP_MAJOR_VERSION >= 7 - ZVAL_RES(return_value, zend_register_resource(conn, le_libvirt_connection)); + conn->resource_id = zend_register_resource(conn, le_libvirt_connection); + ZVAL_RES(return_value, conn->resource_id); #else ZEND_REGISTER_RESOURCE(return_value, conn, le_libvirt_connection); + conn->resource_id = Z_LVAL_P(return_value); #endif - conn->resource_id=Z_LVAL_P(return_value); } /* @@ -4407,14 +4408,15 @@ PHP_FUNCTION(libvirt_stream_recv) if (retval < 0) { efree(recv_buf); zval_dtor(zbuf); - Z_TYPE_P(zbuf) = IS_NULL; + ZVAL_NULL(zbuf); } else { recv_buf[retval] = '\0'; - /* Rebuild buffer zval */ - zval_dtor(zbuf); - Z_STRVAL_P(zbuf) = recv_buf; - Z_STRLEN_P(zbuf) = retval; - Z_TYPE_P(zbuf) = IS_STRING; +#if PHP_MAJOR_VERSION >= 7 + ZVAL_STRINGL(zbuf, recv_buf, retval); + efree(recv_buf); +#else + ZVAL_STRINGL(zbuf, recv_buf, retval, 0) +#endif } if (retval == -1) { @@ -4775,9 +4777,7 @@ PHP_FUNCTION(libvirt_domain_get_screenshot) } /* This is necessary to make the output binary safe */ - Z_STRLEN_P(return_value) = fsize; - Z_STRVAL_P(return_value) = buf; - Z_TYPE_P(return_value) = IS_STRING; + ZVAL_STRINGL(return_value, buf, fsize VIRT_COPY_OPT); efree(buf); free(tmp); @@ -5130,7 +5130,6 @@ PHP_FUNCTION(libvirt_connect_get_emulator) char *arch = NULL; int arch_len; char *tmp; - char *emulator; GET_CONNECTION_FROM_ARGS("r|s",&zconn,&arch,&arch_len); @@ -5327,10 +5326,15 @@ void parse_array(zval *arr, tVMDisk *disk, tVMNetwork *network) { HashTable *arr_hash; // int array_count; +#if PHP_MAJOR_VERSION >= 7 + zval *data; + zend_string *key; +#else zval **data; // removed **zvalue - HashPosition pointer; char *key; unsigned int key_len; +#endif + HashPosition pointer; unsigned long index; arr_hash = Z_ARRVAL_P(arr); @@ -5341,6 +5345,43 @@ void parse_array(zval *arr, tVMDisk *disk, tVMNetwork *network) if (network != NULL) memset(network, 0, sizeof(tVMNetwork)); +#if PHP_MAJOR_VERSION >= 7 + for (zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); + (data = zend_hash_get_current_data_ex(arr_hash, &pointer)) != NULL; + zend_hash_move_forward_ex(arr_hash, &pointer)) { + if ((Z_TYPE_P(data) == IS_STRING) || (Z_TYPE_P(data) == IS_LONG)) { + if (zend_hash_get_current_key_ex(arr_hash, &key, &index, &pointer) == HASH_KEY_IS_STRING) { + if (disk != NULL) { + if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "path") == 0) + disk->path = strdup( Z_STRVAL_P(data) ); + else if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "driver") == 0) + disk->driver = strdup( Z_STRVAL_P(data) ); + else if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "bus") == 0) + disk->bus = strdup( Z_STRVAL_P(data) ); + else if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "dev") == 0) + disk->dev = strdup( Z_STRVAL_P(data) ); + else if (strcmp(ZSTR_VAL(key), "size") == 0) { + if (Z_TYPE_P(data) == IS_LONG) + disk->size = Z_LVAL_P(data); + else + disk->size = size_def_to_mbytes(Z_STRVAL_P(data)); + } + else if ((Z_TYPE_P(data) == IS_LONG) && strcmp(ZSTR_VAL(key), "dev") == 0) + disk->flags = Z_LVAL_P(data); + } else { + if (network != NULL) { + if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "mac") == 0) + network->mac = strdup( Z_STRVAL_P(data) ); + else if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "network") == 0) + network->network = strdup( Z_STRVAL_P(data) ); + else if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "model") == 0) + network->model = strdup( Z_STRVAL_P(data) ); + } + } + } + } + } +#else for (zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) { @@ -5379,6 +5420,7 @@ void parse_array(zval *arr, tVMDisk *disk, tVMNetwork *network) } } } +#endif } /* @@ -5420,7 +5462,11 @@ PHP_FUNCTION(libvirt_domain_new) long maxmemMB = -1; HashTable *arr_hash; int numDisks, numNets, i; +#if PHP_MAJOR_VERSION >= 7 + zval *data; +#else zval **data; // removed **zvalue +#endif HashPosition pointer; char vncl[2048] = { 0 }; char tmpname[1024] = { 0 }; @@ -5451,12 +5497,19 @@ PHP_FUNCTION(libvirt_domain_new) memset(vmDisks, 0, numDisks * sizeof(tVMDisk)); i = 0; for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); +#if PHP_MAJOR_VERSION >= 7 + (data = zend_hash_get_current_data_ex(arr_hash, &pointer)) != NULL; + zend_hash_move_forward_ex(arr_hash, &pointer)) { + if (Z_TYPE_P(data) == IS_ARRAY) { + tVMDisk disk; + parse_array(data, &disk, NULL); +#else zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) { if (Z_TYPE_PP(data) == IS_ARRAY) { tVMDisk disk; parse_array(*data, &disk, NULL); - +#endif if (disk.path != NULL) { //DPRINTF("Disk => path = '%s', driver = '%s', bus = '%s', dev = '%s', size = %ld MB, flags = %d\n", // disk.path, disk.driver, disk.bus, disk.dev, disk.size, disk.flags); @@ -5473,12 +5526,19 @@ PHP_FUNCTION(libvirt_domain_new) memset(vmNetworks, 0, numNets * sizeof(tVMNetwork)); i = 0; for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); +#if PHP_MAJOR_VERSION >= 7 + (data = zend_hash_get_current_data_ex(arr_hash, &pointer)) != NULL; + zend_hash_move_forward_ex(arr_hash, &pointer)) { + if (Z_TYPE_P(data) == IS_ARRAY) { + tVMNetwork network; + parse_array(data, NULL, &network); +#else zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) { if (Z_TYPE_PP(data) == IS_ARRAY) { tVMNetwork network; parse_array(*data, NULL, &network); - +#endif if (network.mac != NULL) { //DPRINTF("Network => mac = '%s', network = '%s', model = '%s'\n", network.mac, network.network, network.model); vmNetworks[i++] = network; @@ -7003,7 +7063,11 @@ PHP_FUNCTION(libvirt_domain_get_connect) conn= domain->conn; if (conn->conn == NULL) RETURN_FALSE; +#if PHP_MAJOR_VERSION >= 7 + ZVAL_RES(return_value, conn->resource_id); +#else RETURN_RESOURCE(conn->resource_id); +#endif } /* @@ -8836,7 +8900,7 @@ PHP_FUNCTION(libvirt_list_networks) for (i=0;i<count;i++) { - add_next_index_string(return_value, names[i], 1); + add_next_index_string(return_value, names[i] VIRT_COPY_OPT); free(names[i]); } diff --git a/src/libvirt-php.h b/src/libvirt-php.h index 6b56547..2ffe9f3 100644 --- a/src/libvirt-php.h +++ b/src/libvirt-php.h @@ -258,7 +258,11 @@ typedef struct tBMPFile { /* Libvirt-php types */ typedef struct _php_libvirt_connection { virConnectPtr conn; +#if PHP_MAJOR_VERSION >= 7 + zend_resource *resource_id; +#else long resource_id; +#endif } php_libvirt_connection; typedef struct _php_libvirt_stream { -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libvirt-php.h b/src/libvirt-php.h index 2ffe9f3..d1f034e 100644 --- a/src/libvirt-php.h +++ b/src/libvirt-php.h @@ -74,10 +74,10 @@ #endif #ifndef VERSION -#define VERSION "0.5.1" +#define VERSION "0.5.2-dev" #define VERSION_MAJOR 0 #define VERSION_MINOR 5 -#define VERSION_MICRO 1 +#define VERSION_MICRO 2 #endif #include <libvirt/libvirt.h> -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 1959074..f4f9c5f 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -2088,7 +2088,7 @@ PHP_FUNCTION(libvirt_connect) char *url=NULL; strsize_t url_len=0; - int readonly=1; + zend_bool readonly=1; HashTable *arr_hash; HashPosition pointer; @@ -7849,7 +7849,7 @@ PHP_FUNCTION(libvirt_storagevolume_create_xml_from) virStorageVolPtr volume=NULL; char *xml; - int xml_len; + strsize_t xml_len; if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "rsr", &zpool, &xml, &xml_len, &zvolume) == FAILURE) { -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 279 +++++++++++++++++++++++++++--------------------------- 1 file changed, 141 insertions(+), 138 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index f4f9c5f..2700c77 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -2248,7 +2248,7 @@ PHP_FUNCTION(libvirt_node_get_cpu_stats) int cpuNum = VIR_NODE_CPU_STATS_ALL_CPUS; virNodeCPUStatsPtr params; virNodeInfo info; - long cpunr = -1; + zend_long cpunr = -1; int nparams = 0; int i, j, numCpus; @@ -2349,7 +2349,7 @@ PHP_FUNCTION(libvirt_node_get_cpu_stats_for_each_cpu) virNodeCPUStatsPtr params; virNodeInfo info; int nparams = 0; - long avg = 0, iter = 0; + zend_long avg = 0, iter = 0; int done = 0; int i, j, numCpus; time_t startTime = 0; @@ -2799,12 +2799,12 @@ PHP_FUNCTION(libvirt_image_create) char *path = NULL; char fpath[4096] = { 0 }; char *image = NULL; - int image_len; + strsize_t image_len; char *format; - int format_len; + strsize_t format_len; long long size; char *size_str; - int size_str_len; + strsize_t size_str_len; int cmdRet; if (LIBVIRT_G(image_path_ini)) @@ -2867,7 +2867,7 @@ PHP_FUNCTION(libvirt_image_remove) char name[1024]; char msg[4096] = { 0 }; char *image = NULL; - int image_len; + strsize_t image_len; GET_CONNECTION_FROM_ARGS("rs",&zconn,&image,&image_len); @@ -2989,8 +2989,8 @@ PHP_FUNCTION(libvirt_connect_get_all_domain_stats) php_libvirt_connection *conn = NULL; zval *zconn; int retval = -1; - long flags = 0; - long stats = 0; + zend_long flags = 0; + zend_long stats = 0; const char *name = NULL; int i; int j; @@ -3929,7 +3929,7 @@ PHP_FUNCTION(libvirt_domain_set_max_memory) { php_libvirt_domain *domain = NULL; zval *zdomain; - long memory = 0; + zend_long memory = 0; GET_DOMAIN_FROM_ARGS ("rl", &zdomain, &memory); @@ -3951,7 +3951,7 @@ PHP_FUNCTION(libvirt_domain_set_memory) { php_libvirt_domain *domain = NULL; zval *zdomain; - long memory = 0; + zend_long memory = 0; GET_DOMAIN_FROM_ARGS ("rl", &zdomain, &memory); @@ -3974,8 +3974,8 @@ PHP_FUNCTION(libvirt_domain_set_memory_flags) { php_libvirt_domain *domain = NULL; zval *zdomain; - long memory = 0; - long flags = 0; + zend_long memory = 0; + zend_long flags = 0; GET_DOMAIN_FROM_ARGS ("rl|l", &zdomain, &memory, &flags); @@ -4044,10 +4044,10 @@ PHP_FUNCTION(libvirt_domain_get_metadata) { php_libvirt_domain *domain = NULL; zval *zdomain; - long type = 0; - long flags = 0; + zend_long type = 0; + zend_long flags = 0; char *uri = NULL; - int uri_len; + strsize_t uri_len; char *ret = NULL; GET_DOMAIN_FROM_ARGS ("rlsl", &zdomain, &type, &uri, &uri_len, &flags); @@ -4086,12 +4086,12 @@ PHP_FUNCTION(libvirt_domain_set_metadata) { php_libvirt_domain *domain = NULL; zval *zdomain; - int metadata_len, key_len, uri_len; + strsize_t metadata_len, key_len, uri_len; char *metadata = NULL; char *key = NULL; char *uri = NULL; - long type = 0; - long flags = 0; + zend_long type = 0; + zend_long flags = 0; int rc; GET_DOMAIN_FROM_ARGS ("rlsssl", &zdomain, &type, &metadata, &metadata_len, &key, &key_len, &uri, &uri_len, &flags); @@ -4134,7 +4134,7 @@ PHP_FUNCTION(libvirt_domain_lookup_by_name) { php_libvirt_connection *conn=NULL; zval *zconn; - int name_len; + strsize_t name_len; char *name=NULL; virDomainPtr domain=NULL; php_libvirt_domain *res_domain; @@ -4169,7 +4169,7 @@ PHP_FUNCTION(libvirt_domain_lookup_by_uuid) { php_libvirt_connection *conn=NULL; zval *zconn; - int uuid_len; + strsize_t uuid_len; unsigned char *uuid=NULL; virDomainPtr domain=NULL; php_libvirt_domain *res_domain; @@ -4208,10 +4208,10 @@ PHP_FUNCTION(libvirt_domain_qemu_agent_command) php_libvirt_domain *domain=NULL; zval *zdomain; const char *cmd; - int cmd_len; + strsize_t cmd_len; char *ret; - long timeout = -1; - long flags = 0; + zend_long timeout = -1; + zend_long flags = 0; GET_DOMAIN_FROM_ARGS("rs|ll", &zdomain, &cmd, &cmd_len, &timeout, &flags); @@ -4233,7 +4233,7 @@ PHP_FUNCTION(libvirt_domain_lookup_by_uuid_string) { php_libvirt_connection *conn=NULL; zval *zconn; - int uuid_len; + strsize_t uuid_len; char *uuid=NULL; virDomainPtr domain=NULL; php_libvirt_domain *res_domain; @@ -4475,7 +4475,7 @@ PHP_FUNCTION(libvirt_domain_lookup_by_id) { php_libvirt_connection *conn=NULL; zval *zconn; - long id; + zend_long id; virDomainPtr domain=NULL; php_libvirt_domain *res_domain; @@ -4581,7 +4581,7 @@ PHP_FUNCTION(libvirt_domain_get_screenshot_api) { php_libvirt_domain *domain=NULL; zval *zdomain; - long screen = 0; + zend_long screen = 0; int fd = -1; char file[] = "/tmp/libvirt-php-tmp-XXXXXX"; virStreamPtr st = NULL; @@ -4678,8 +4678,8 @@ PHP_FUNCTION(libvirt_domain_get_screenshot) char *xml = NULL; int port = -1; char *hostname = NULL; - int hostname_len; - long scancode = 10; + strsize_t hostname_len; + zend_long scancode = 10; const char *path; char *pathDup = NULL; char name[1024] = { 0 }; @@ -4814,7 +4814,7 @@ PHP_FUNCTION(libvirt_domain_get_screen_dimensions) char *tmp = NULL; char *xml = NULL; char *hostname = NULL; - int hostname_len; + strsize_t hostname_len; int ret; int width; int height; @@ -4883,9 +4883,9 @@ PHP_FUNCTION(libvirt_domain_send_keys) char *tmp = NULL; char *xml = NULL; char *hostname = NULL; - int hostname_len; + strsize_t hostname_len; char *keys = NULL; - int keys_len; + strsize_t keys_len; int ret = 0; GET_DOMAIN_FROM_ARGS("rss",&zdomain, &hostname, &hostname_len, &keys, &keys_len); @@ -4951,11 +4951,11 @@ PHP_FUNCTION(libvirt_domain_send_pointer_event) char *tmp = NULL; char *xml = NULL; char *hostname = NULL; - int hostname_len; - long pos_x = 0; - long pos_y = 0; - long clicked = 0; - int release = 1; + strsize_t hostname_len; + zend_long pos_x = 0; + zend_long pos_y = 0; + zend_long clicked = 0; + zend_bool release = 1; int ret; GET_DOMAIN_FROM_ARGS("rslll|b",&zdomain, &hostname, &hostname_len, &pos_x, &pos_y, &clicked, &release); @@ -5094,7 +5094,7 @@ PHP_FUNCTION(libvirt_connect_get_capabilities) zval *zconn; char *caps; char *xpath = NULL; - int xpath_len; + strsize_t xpath_len; char *tmp = NULL; int retval = -1; @@ -5128,7 +5128,7 @@ PHP_FUNCTION(libvirt_connect_get_emulator) php_libvirt_connection *conn=NULL; zval *zconn; char *arch = NULL; - int arch_len; + strsize_t arch_len; char *tmp; GET_CONNECTION_FROM_ARGS("r|s",&zconn,&arch,&arch_len); @@ -5159,7 +5159,7 @@ PHP_FUNCTION(libvirt_connect_get_nic_models) php_libvirt_connection *conn=NULL; zval *zconn; char *arch = NULL; - int arch_len; + strsize_t arch_len; char *tmp; GET_CONNECTION_FROM_ARGS("r|s",&zconn,&arch,&arch_len); @@ -5230,9 +5230,9 @@ PHP_FUNCTION(libvirt_connect_get_soundhw_models) php_libvirt_connection *conn=NULL; zval *zconn; char *arch = NULL; - int arch_len; + strsize_t arch_len; char *tmp; - long flags = 0; + zend_long flags = 0; GET_CONNECTION_FROM_ARGS("r|sl",&zconn,&arch,&arch_len,&flags); @@ -5447,19 +5447,19 @@ PHP_FUNCTION(libvirt_domain_new) virDomainPtr domain=NULL; zval *zconn; char *arch = NULL; - int arch_len; + strsize_t arch_len; char *tmp; char *name; - int name_len=0; + strsize_t name_len=0; // char *emulator; char *iso_image = NULL; - int iso_image_len; - long vcpus = -1; - long memMB = -1; + strsize_t iso_image_len; + zend_long vcpus = -1; + zend_long memMB = -1; zval *disks, *networks; tVMDisk *vmDisks = NULL; tVMNetwork *vmNetworks = NULL; - long maxmemMB = -1; + zend_long maxmemMB = -1; HashTable *arr_hash; int numDisks, numNets, i; #if PHP_MAJOR_VERSION >= 7 @@ -5473,7 +5473,7 @@ PHP_FUNCTION(libvirt_domain_new) char *xml = NULL; int retval = 0; char *uuid = NULL; - long flags = 0; + zend_long flags = 0; int fd = -1; GET_CONNECTION_FROM_ARGS("rsslllsaa|l",&zconn,&name,&name_len,&arch,&arch_len,&memMB,&maxmemMB,&vcpus,&iso_image,&iso_image_len,&disks,&networks,&flags); @@ -5660,8 +5660,8 @@ PHP_FUNCTION(libvirt_domain_get_xml_desc) char *tmp = NULL; char *xml; char *xpath = NULL; - int xpath_len; - long flags=0; + strsize_t xpath_len; + zend_long flags=0; int retval = -1; GET_DOMAIN_FROM_ARGS("rs|l",&zdomain,&xpath,&xpath_len,&flags); @@ -5768,7 +5768,7 @@ PHP_FUNCTION(libvirt_domain_get_interface_devices) */ PHP_FUNCTION(libvirt_domain_change_vcpus) { - long numCpus, flags = 0; + zend_long numCpus, flags = 0; php_libvirt_domain *domain=NULL; zval *zdomain; @@ -5803,9 +5803,9 @@ PHP_FUNCTION(libvirt_domain_change_memory) char *new_xml = NULL; int new_len; char *newXml = NULL; - long xflags = 0; - long allocMem = 0; - long allocMax = 0; + zend_long xflags = 0; + zend_long allocMem = 0; + zend_long allocMax = 0; // int pos = -1; int len = 0; php_libvirt_domain *res_domain = NULL; @@ -5888,11 +5888,11 @@ PHP_FUNCTION(libvirt_domain_change_boot_devices) char *new_xml = NULL; int new_len; char newXml[4096] = { 0 }; - long xflags = 0; + zend_long xflags = 0; char *first = NULL; - int first_len; + strsize_t first_len; char *second = NULL; - int second_len; + strsize_t second_len; // int pos = -1; int len = 0; php_libvirt_domain *res_domain = NULL; @@ -5970,15 +5970,15 @@ PHP_FUNCTION(libvirt_domain_disk_add) zval *zdomain; char *xml; char *img = NULL; - int img_len; + strsize_t img_len; char *dev = NULL; - int dev_len; + strsize_t dev_len; char *driver = NULL; - int driver_len; + strsize_t driver_len; char *typ = NULL; - int typ_len; + strsize_t typ_len; char *newXml = NULL; - long xflags = 0; + zend_long xflags = 0; int retval = -1; char *xpath = NULL; char *tmp = NULL; @@ -6066,9 +6066,9 @@ PHP_FUNCTION(libvirt_domain_disk_remove) zval *zdomain; char *xml; char *dev = NULL; - int dev_len; + strsize_t dev_len; char *newXml = NULL; - long xflags = 0; + zend_long xflags = 0; int retval = -1; char *xpath = NULL; char *tmp = NULL; @@ -6139,13 +6139,13 @@ PHP_FUNCTION(libvirt_domain_nic_add) zval *zdomain; char *xml; char *mac = NULL; - int mac_len; + strsize_t mac_len; char *net = NULL; - int net_len; + strsize_t net_len; char *model = NULL; - int model_len; + strsize_t model_len; char *newXml = NULL; - long xflags = 0; + zend_long xflags = 0; int retval = -1; char *xpath = NULL; char *tmp = NULL; @@ -6232,9 +6232,9 @@ PHP_FUNCTION(libvirt_domain_nic_remove) zval *zdomain; char *xml; char *mac = NULL; - int mac_len; + strsize_t mac_len; char *newXml = NULL; - long xflags = 0; + zend_long xflags = 0; int retval = -1; char *xpath = NULL; char *tmp = NULL; @@ -6392,7 +6392,7 @@ PHP_FUNCTION(libvirt_domain_core_dump) php_libvirt_domain *domain=NULL; zval *zdomain; int retval; - int to_len; + strsize_t to_len; char *to; GET_DOMAIN_FROM_ARGS("rs",&zdomain,&to,&to_len); @@ -6499,7 +6499,7 @@ PHP_FUNCTION(libvirt_domain_reboot) php_libvirt_domain *domain=NULL; zval *zdomain; int retval; - long flags=0; + zend_long flags=0; GET_DOMAIN_FROM_ARGS("r|l",&zdomain,&flags); @@ -6524,7 +6524,7 @@ PHP_FUNCTION(libvirt_domain_define_xml) zval *zconn; virDomainPtr domain=NULL; char *xml; - int xml_len; + strsize_t xml_len; GET_CONNECTION_FROM_ARGS("rs",&zconn,&xml,&xml_len); @@ -6559,8 +6559,8 @@ PHP_FUNCTION(libvirt_domain_create_xml) zval *zconn; virDomainPtr domain=NULL; char *xml; - int xml_len; - long flags=0; + strsize_t xml_len; + zend_long flags=0; GET_CONNECTION_FROM_ARGS("rs|l", &zconn, &xml, &xml_len, &flags); @@ -6596,9 +6596,9 @@ PHP_FUNCTION(libvirt_domain_memory_peek) php_libvirt_domain *domain=NULL; zval *zdomain; int retval; - long flags=0; - long start; - long size; + zend_long flags=0; + zend_long start; + zend_long size; char *buff; GET_DOMAIN_FROM_ARGS("rlll",&zdomain,&start,&size,&flags); @@ -6626,7 +6626,7 @@ PHP_FUNCTION(libvirt_domain_memory_stats) php_libvirt_domain *domain=NULL; zval *zdomain; int retval; - long flags=0; + zend_long flags=0; int i; struct _virDomainMemoryStat stats[VIR_DOMAIN_MEMORY_STAT_NR]; @@ -6658,8 +6658,8 @@ PHP_FUNCTION(libvirt_domain_update_device) php_libvirt_domain *domain=NULL; zval *zdomain; char *xml; - int xml_len; - long flags; + strsize_t xml_len; + zend_long flags; int res; GET_DOMAIN_FROM_ARGS("rsl",&zdomain,&xml,&xml_len,&flags); @@ -6686,7 +6686,7 @@ PHP_FUNCTION(libvirt_domain_block_stats) zval *zdomain; int retval; char *path; - int path_len; + strsize_t path_len; struct _virDomainBlockStats stats; @@ -6721,9 +6721,9 @@ PHP_FUNCTION(libvirt_domain_block_resize) zval *zdomain; int retval; char *path; - int path_len; - long size = 0; - long flags = 0; + strsize_t path_len; + zend_long size = 0; + zend_long flags = 0; GET_DOMAIN_FROM_ARGS("rsl|l",&zdomain, &path, &path_len, &size, &flags); @@ -6748,8 +6748,8 @@ PHP_FUNCTION(libvirt_domain_block_job_abort) zval *zdomain; int retval; char *path; - int path_len; - long flags = 0; + strsize_t path_len; + zend_long flags = 0; GET_DOMAIN_FROM_ARGS("rs|l",&zdomain, &path, &path_len, &flags); @@ -6775,9 +6775,9 @@ PHP_FUNCTION(libvirt_domain_block_job_set_speed) zval *zdomain; int retval; char *path; - int path_len; - long bandwidth = 0; - long flags = 0; + strsize_t path_len; + zend_long bandwidth = 0; + zend_long flags = 0; GET_DOMAIN_FROM_ARGS("rsl|l",&zdomain, &path, &path_len, &bandwidth, &flags); @@ -6805,7 +6805,7 @@ PHP_FUNCTION(libvirt_domain_get_network_info) char *mac; char *xml; char *tmp = NULL; - int mac_len; + strsize_t mac_len; char *xpath = NULL; GET_DOMAIN_FROM_ARGS("rs",&zdomain,&mac,&mac_len); @@ -6878,7 +6878,8 @@ PHP_FUNCTION(libvirt_domain_get_block_info) char *dev; char *xml; char *tmp = NULL; - int dev_len, isFile; + strsize_t dev_len; + int isFile; char *xpath = NULL; struct _virDomainBlockInfo info; @@ -6981,7 +6982,8 @@ PHP_FUNCTION(libvirt_domain_xml_xpath) zval *zpath; char *xml; char *tmp = NULL; - long path_len=-1, flags = 0; + strsize_t path_len = -1; + zend_long flags = 0; int rc = 0; GET_DOMAIN_FROM_ARGS("rs|l",&zdomain, &zpath, &path_len, &flags); @@ -7022,7 +7024,7 @@ PHP_FUNCTION(libvirt_domain_interface_stats) zval *zdomain; int retval; char *path; - int path_len; + strsize_t path_len; struct _virDomainInterfaceStats stats; @@ -7088,10 +7090,10 @@ PHP_FUNCTION(libvirt_domain_migrate_to_uri) int retval; long flags=0; char *duri; - int duri_len; + strsize_t duri_len; char *dname; - int dname_len; - long bandwidth; + strsize_t dname_len; + zend_long bandwidth; dname=NULL; dname_len=0; @@ -7124,15 +7126,15 @@ PHP_FUNCTION(libvirt_domain_migrate_to_uri2) zval *zdomain; int retval; char *dconnuri; - int dconnuri_len; + strsize_t dconnuri_len; char *miguri; - int miguri_len; + strsize_t miguri_len; char *dxml; - int dxml_len; - long flags=0; + strsize_t dxml_len; + zend_long flags=0; char *dname; - int dname_len; - long bandwidth; + strsize_t dname_len; + zend_long bandwidth; dconnuri=NULL; dconnuri_len=0; @@ -7178,10 +7180,10 @@ PHP_FUNCTION(libvirt_domain_migrate) virDomainPtr destdomain=NULL; php_libvirt_domain *res_domain; - long flags=0; + zend_long flags=0; char *dname; - int dname_len; - long bandwidth; + strsize_t dname_len; + zend_long bandwidth; dname=NULL; dname_len=0; @@ -7265,7 +7267,7 @@ PHP_FUNCTION(libvirt_domain_has_current_snapshot) php_libvirt_domain *domain=NULL; zval *zdomain; int retval; - long flags = 0; + zend_long flags = 0; GET_DOMAIN_FROM_ARGS("r|l",&zdomain, &flags); @@ -7287,9 +7289,9 @@ PHP_FUNCTION(libvirt_domain_snapshot_lookup_by_name) { php_libvirt_domain *domain=NULL; zval *zdomain; - int name_len; + strsize_t name_len; char *name=NULL; - long flags = 0; + zend_long flags = 0; php_libvirt_snapshot *res_snapshot; virDomainSnapshotPtr snapshot = NULL; @@ -7326,7 +7328,7 @@ PHP_FUNCTION(libvirt_domain_snapshot_create) php_libvirt_snapshot *res_snapshot; zval *zdomain; virDomainSnapshotPtr snapshot = NULL; - long flags = 0; + zend_long flags = 0; GET_DOMAIN_FROM_ARGS("r|l",&zdomain, &flags); @@ -7360,7 +7362,7 @@ PHP_FUNCTION(libvirt_domain_snapshot_get_xml) char *xml; zval *zsnapshot; php_libvirt_snapshot *snapshot; - long flags = 0; + zend_long flags = 0; GET_SNAPSHOT_FROM_ARGS("r|l",&zsnapshot, &flags); @@ -7384,7 +7386,7 @@ PHP_FUNCTION(libvirt_domain_snapshot_revert) zval *zsnapshot; php_libvirt_snapshot *snapshot; int ret; - long flags = 0; + zend_long flags = 0; GET_SNAPSHOT_FROM_ARGS("r|l",&zsnapshot, &flags); @@ -7406,7 +7408,7 @@ PHP_FUNCTION(libvirt_domain_snapshot_delete) { zval *zsnapshot; php_libvirt_snapshot *snapshot; - long flags = 0; + zend_long flags = 0; int retval; GET_SNAPSHOT_FROM_ARGS("r|l",&zsnapshot, &flags); @@ -7432,7 +7434,7 @@ PHP_FUNCTION(libvirt_list_domain_snapshots) int count=-1; int expectedcount=-1; char **names; - long flags = 0; + zend_long flags = 0; int i; GET_DOMAIN_FROM_ARGS("r|l",&zdomain, &flags); @@ -7472,7 +7474,7 @@ PHP_FUNCTION(libvirt_storagepool_lookup_by_name) { php_libvirt_connection *conn=NULL; zval *zconn; - int name_len; + strsize_t name_len; char *name=NULL; virStoragePoolPtr pool=NULL; php_libvirt_storagepool *res_pool; @@ -7612,7 +7614,7 @@ PHP_FUNCTION(libvirt_storagevolume_lookup_by_name) php_libvirt_storagepool *pool=NULL; php_libvirt_volume *res_volume; zval *zpool; - int name_len; + strsize_t name_len; char *name=NULL; virStorageVolPtr volume=NULL; @@ -7649,7 +7651,7 @@ PHP_FUNCTION(libvirt_storagevolume_lookup_by_path) php_libvirt_connection *conn=NULL; php_libvirt_volume *res_volume; zval *zconn; - int name_len; + strsize_t name_len; char *name=NULL; virStorageVolPtr volume=NULL; @@ -7764,8 +7766,8 @@ PHP_FUNCTION(libvirt_storagevolume_get_xml_desc) char *tmp = NULL; char *xml; char *xpath = NULL; - int xpath_len; - long flags=0; + strsize_t xpath_len; + zend_long flags=0; int retval = -1; GET_VOLUME_FROM_ARGS("rs|l",&zvolume,&xpath,&xpath_len,&flags); @@ -7807,8 +7809,8 @@ PHP_FUNCTION(libvirt_storagevolume_create_xml) zval *zpool; virStorageVolPtr volume=NULL; char *xml; - long flags = 0; - int xml_len; + zend_long flags = 0; + strsize_t xml_len; GET_STORAGEPOOL_FROM_ARGS("rs|l",&zpool,&xml,&xml_len, &flags); @@ -7892,7 +7894,7 @@ PHP_FUNCTION(libvirt_storagevolume_delete) { php_libvirt_volume *volume=NULL; zval *zvolume; - long flags = 0; + zend_long flags = 0; int retval = 0; GET_VOLUME_FROM_ARGS("r|l",&zvolume,&flags); @@ -7920,8 +7922,8 @@ PHP_FUNCTION(libvirt_storagevolume_resize) { php_libvirt_volume *volume=NULL; zval *zvolume; - long flags = 0; - long capacity = 0; + zend_long flags = 0; + zend_long capacity = 0; int retval = -1; GET_VOLUME_FROM_ARGS("rl|l", &zvolume, &capacity, &flags); @@ -8084,7 +8086,7 @@ PHP_FUNCTION(libvirt_storagepool_lookup_by_uuid_string) php_libvirt_connection *conn = NULL; zval *zconn; char *uuid = NULL; - int uuid_len; + strsize_t uuid_len; virStoragePoolPtr storage=NULL; php_libvirt_storagepool *res_pool; @@ -8126,8 +8128,8 @@ PHP_FUNCTION(libvirt_storagepool_get_xml_desc) char *xml; char *xpath = NULL; char *tmp = NULL; - long flags = 0; - int xpath_len; + zend_long flags = 0; + strsize_t xpath_len; int retval = -1; GET_STORAGEPOOL_FROM_ARGS("r|s", &zpool, &xpath, &xpath_len, &flags); @@ -8170,8 +8172,8 @@ PHP_FUNCTION(libvirt_storagepool_define_xml) zval *zconn; virStoragePoolPtr pool = NULL; char *xml; - int xml_len; - long flags = 0; + strsize_t xml_len; + zend_long flags = 0; GET_CONNECTION_FROM_ARGS ("rs|l", &zconn, &xml, &xml_len, &flags); @@ -8307,7 +8309,7 @@ PHP_FUNCTION(libvirt_storagepool_refresh) { php_libvirt_storagepool *pool = NULL; zval *zpool; - long flags = 0; + zend_long flags = 0; int retval; GET_STORAGEPOOL_FROM_ARGS ("r|l", &zpool, &flags); @@ -8859,7 +8861,7 @@ PHP_FUNCTION(libvirt_list_networks) { php_libvirt_connection *conn=NULL; zval *zconn; - long flags = VIR_NETWORKS_ACTIVE | VIR_NETWORKS_INACTIVE; + zend_long flags = VIR_NETWORKS_ACTIVE | VIR_NETWORKS_INACTIVE; int count=-1; int expectedcount=-1; char **names; @@ -8928,7 +8930,8 @@ PHP_FUNCTION(libvirt_list_nodedevs) int expectedcount=-1; char *cap = NULL; char **names; - int i, cap_len; + int i; + strsize_t cap_len; GET_CONNECTION_FROM_ARGS("r|s",&zconn,&cap,&cap_len); @@ -8967,7 +8970,7 @@ PHP_FUNCTION(libvirt_nodedev_get) virNodeDevice *dev; zval *zconn; char *name; - int name_len; + strsize_t name_len; GET_CONNECTION_FROM_ARGS("rs",&zconn,&name,&name_len); @@ -9037,7 +9040,7 @@ PHP_FUNCTION(libvirt_nodedev_get_xml_desc) char *tmp = NULL; char *xml = NULL; char *xpath = NULL; - int xpath_len; + strsize_t xpath_len; int retval = -1; GET_NODEDEV_FROM_ARGS("r|s",&znodedev,&xpath,&xpath_len); @@ -9236,7 +9239,7 @@ PHP_FUNCTION(libvirt_network_define_xml) virNetwork *net; zval *zconn; char *xml = NULL; - int xml_len; + strsize_t xml_len; GET_CONNECTION_FROM_ARGS("rs",&zconn,&xml,&xml_len); @@ -9293,7 +9296,7 @@ PHP_FUNCTION(libvirt_network_get) virNetwork *net; zval *zconn; char *name; - int name_len; + strsize_t name_len; GET_CONNECTION_FROM_ARGS("rs",&zconn,&name,&name_len); @@ -9470,7 +9473,7 @@ PHP_FUNCTION(libvirt_network_set_active) { php_libvirt_network *network; zval *znetwork; - long act = 0; + zend_long act = 0; DPRINTF("%s: Setting network activity...\n", PHPFUNC); @@ -9519,7 +9522,7 @@ PHP_FUNCTION(libvirt_network_get_xml_desc) char *xml = NULL; char *xpath = NULL; char *tmp; - int xpath_len; + strsize_t xpath_len; int retval = -1; GET_NETWORK_FROM_ARGS("r|s",&znetwork,&xpath,&xpath_len); -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 75 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 2700c77..3977302 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -59,6 +59,9 @@ const char *features_binaries[] = { NULL }; typedef size_t strsize_t; #define VIRT_COPY_OPT +#define VIRT_RETVAL_STRING(str) RETVAL_STRING(str) +#define VIRT_ZVAL_STRINGL(zv,str,len) ZVAL_STRINGL(zv,str,len) + #define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \ if ((_state = (_type)zend_fetch_resource(Z_RES_P(*_zval), _name, _le)) == NULL) { \ RETURN_FALSE; \ @@ -70,6 +73,8 @@ typedef long zend_long; typedef unsigned long zend_ulong; #define VIRT_COPY_OPT ,1 +#define VIRT_RETVAL_STRING(str) RETVAL_STRING(str, 1) +#define VIRT_ZVAL_STRINGL(zv,str,len) ZVAL_STRINGL(zv,str,len,1) #define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \ ZEND_FETCH_RESOURCE(_state, _type, _zval, -1, _name, _le); @@ -2062,7 +2067,7 @@ static int libvirt_virConnectCredType[] = { PHP_FUNCTION(libvirt_get_last_error) { if (LIBVIRT_G (last_error) == NULL) RETURN_NULL(); - RETURN_STRING(LIBVIRT_G (last_error) VIRT_COPY_OPT); + VIRT_RETVAL_STRING(LIBVIRT_G(last_error)); } /* @@ -2079,7 +2084,11 @@ PHP_FUNCTION(libvirt_connect) php_libvirt_connection *conn; php_libvirt_cred_value *creds=NULL; zval* zcreds=NULL; +#if PHP_MAJOR_VERSION >= 7 zval *data; +#else + zval **data; +#endif int i; int j; int credscount=0; @@ -2753,7 +2762,7 @@ PHP_FUNCTION(libvirt_connect_get_uri) DPRINTF("%s: virConnectGetURI returned %s\n", PHPFUNC, uri); if (uri == NULL) RETURN_FALSE; - RETVAL_STRING(uri VIRT_COPY_OPT); + VIRT_RETVAL_STRING(uri); free(uri); } @@ -2776,7 +2785,7 @@ PHP_FUNCTION(libvirt_connect_get_hostname) DPRINTF("%s: virConnectGetHostname returned %s\n", PHPFUNC, hostname); if (hostname==NULL) RETURN_FALSE; - RETVAL_STRING(hostname VIRT_COPY_OPT); + VIRT_RETVAL_STRING(hostname); free(hostname); } @@ -3093,7 +3102,7 @@ PHP_FUNCTION(libvirt_connect_get_sysinfo) sysinfo=virConnectGetSysinfo(conn->conn, 0); if (sysinfo==NULL) RETURN_FALSE; - RETVAL_STRING(sysinfo VIRT_COPY_OPT); + VIRT_RETVAL_STRING(sysinfo); free(sysinfo); } @@ -3377,7 +3386,11 @@ long get_next_free_numeric_value(virDomainPtr domain, char *xpath) HashTable *arr_hash; HashPosition pointer; // int array_count; +#if PHP_MAJOR_VERSION >= 7 zval *data; +#else + zval **data; +#endif unsigned long index; long max_slot = -1; @@ -4065,7 +4078,7 @@ PHP_FUNCTION(libvirt_domain_get_metadata) } } else { - RETVAL_STRING(ret VIRT_COPY_OPT); + VIRT_RETVAL_STRING(ret); free(ret); } } @@ -4218,7 +4231,7 @@ PHP_FUNCTION(libvirt_domain_qemu_agent_command) ret = virDomainQemuAgentCommand(domain->domain, cmd, timeout, flags); if (ret == NULL) RETURN_FALSE; - RETURN_STRING(ret VIRT_COPY_OPT); + VIRT_RETVAL_STRING(ret); } /* @@ -4415,7 +4428,7 @@ PHP_FUNCTION(libvirt_stream_recv) ZVAL_STRINGL(zbuf, recv_buf, retval); efree(recv_buf); #else - ZVAL_STRINGL(zbuf, recv_buf, retval, 0) + ZVAL_STRINGL(zbuf, recv_buf, retval, 0); #endif } @@ -4519,7 +4532,7 @@ PHP_FUNCTION(libvirt_domain_get_name) DPRINTF("%s: virDomainGetName(%p) returned %s\n", PHPFUNC, domain->domain, name); if (name==NULL) RETURN_FALSE; - RETURN_STRING(name VIRT_COPY_OPT); //we can use the copy mechanism as we need not to free name (we even can not!) + VIRT_RETVAL_STRING(name); //we can use the copy mechanism as we need not to free name (we even can not!) } /* @@ -4777,7 +4790,7 @@ PHP_FUNCTION(libvirt_domain_get_screenshot) } /* This is necessary to make the output binary safe */ - ZVAL_STRINGL(return_value, buf, fsize VIRT_COPY_OPT); + VIRT_ZVAL_STRINGL(return_value, buf, fsize); efree(buf); free(tmp); @@ -5106,9 +5119,9 @@ PHP_FUNCTION(libvirt_connect_get_capabilities) tmp = get_string_from_xpath(caps, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { - RETVAL_STRING(caps VIRT_COPY_OPT); + VIRT_RETVAL_STRING(caps); } else { - RETVAL_STRING(tmp VIRT_COPY_OPT); + VIRT_RETVAL_STRING(tmp); } free(caps); @@ -5142,7 +5155,7 @@ PHP_FUNCTION(libvirt_connect_get_emulator) RETURN_FALSE; } - RETVAL_STRING(tmp VIRT_COPY_OPT); + VIRT_RETVAL_STRING(tmp); free(tmp); } @@ -5640,9 +5653,9 @@ PHP_FUNCTION(libvirt_domain_new) PHP_FUNCTION(libvirt_domain_new_get_vnc) { if (LIBVIRT_G(vnc_location)) - RETURN_STRING(LIBVIRT_G(vnc_location) VIRT_COPY_OPT); - - RETURN_NULL(); + VIRT_RETVAL_STRING(LIBVIRT_G(vnc_location)); + else + RETVAL_NULL(); } /* @@ -5678,9 +5691,9 @@ PHP_FUNCTION(libvirt_domain_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { - RETVAL_STRING(xml VIRT_COPY_OPT); + VIRT_RETVAL_STRING(xml); } else { - RETVAL_STRING(tmp VIRT_COPY_OPT); + VIRT_RETVAL_STRING(tmp); } free(tmp); @@ -7369,7 +7382,7 @@ PHP_FUNCTION(libvirt_domain_snapshot_get_xml) xml = virDomainSnapshotGetXMLDesc(snapshot->snapshot, flags); if (xml==NULL) RETURN_FALSE; - RETVAL_STRING(xml VIRT_COPY_OPT); + VIRT_RETVAL_STRING(xml); free(xml); } @@ -7698,7 +7711,7 @@ PHP_FUNCTION(libvirt_storagevolume_get_name) DPRINTF("%s: virStorageVolGetName(%p) returned %s\n", PHPFUNC, volume->volume, retval); if (retval == NULL) RETURN_FALSE; - RETURN_STRING(retval VIRT_COPY_OPT); + VIRT_RETVAL_STRING(retval); } /* @@ -7720,7 +7733,7 @@ PHP_FUNCTION(libvirt_storagevolume_get_path) DPRINTF("%s: virStorageVolGetPath(%p) returned %s\n", PHPFUNC, volume->volume, retval); if (retval == NULL) RETURN_FALSE; - RETURN_STRING(retval VIRT_COPY_OPT); + VIRT_RETVAL_STRING(retval); } /* @@ -7784,9 +7797,9 @@ PHP_FUNCTION(libvirt_storagevolume_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { - RETVAL_STRING(xml VIRT_COPY_OPT); + VIRT_RETVAL_STRING(xml); } else { - RETVAL_STRING(tmp VIRT_COPY_OPT); + VIRT_RETVAL_STRING(tmp); } free(xml); @@ -8070,7 +8083,7 @@ PHP_FUNCTION(libvirt_storagepool_get_name) if (name == NULL) RETURN_FALSE; - RETURN_STRING(name VIRT_COPY_OPT); + VIRT_RETVAL_STRING(name); } /* @@ -8147,9 +8160,9 @@ PHP_FUNCTION(libvirt_storagepool_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { - RETVAL_STRING(xml VIRT_COPY_OPT); + VIRT_RETVAL_STRING(xml); } else { - RETVAL_STRING(tmp VIRT_COPY_OPT); + VIRT_RETVAL_STRING(tmp); } free(xml); @@ -8882,7 +8895,7 @@ PHP_FUNCTION(libvirt_list_networks) for (i=0;i<count;i++) { - add_next_index_string(return_value, names[i]); + add_next_index_string(return_value, names[i] VIRT_COPY_OPT); free(names[i]); } @@ -9057,9 +9070,9 @@ PHP_FUNCTION(libvirt_nodedev_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { - RETVAL_STRING(xml VIRT_COPY_OPT); + VIRT_RETVAL_STRING(xml); } else { - RETVAL_STRING(tmp VIRT_COPY_OPT); + VIRT_RETVAL_STRING(tmp); } free(xml); @@ -9340,7 +9353,7 @@ PHP_FUNCTION(libvirt_network_get_bridge) RETURN_FALSE; } - RETURN_STRING(name VIRT_COPY_OPT); + VIRT_RETVAL_STRING(name); } /* @@ -9540,9 +9553,9 @@ PHP_FUNCTION(libvirt_network_get_xml_desc) tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp == NULL) || (retval < 0)) { - RETVAL_STRING(xml VIRT_COPY_OPT); + VIRT_RETVAL_STRING(xml); } else { - RETVAL_STRING(tmp VIRT_COPY_OPT); + VIRT_RETVAL_STRING(tmp); } free(xml); -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 2 +- src/tests/skipif.inc | 3 +++ src/tests/test-version-get.phpt | 27 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/tests/skipif.inc create mode 100644 src/tests/test-version-get.phpt diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 3977302..1977039 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -9595,7 +9595,7 @@ PHP_FUNCTION(libvirt_version) add_assoc_long(return_value, "libvirt.minor",(long)((libVer/1000) % 1000)); add_assoc_long(return_value, "libvirt.major",(long)((libVer/1000000) % 1000)); - add_assoc_string_ex(return_value, "connector.version", 18, PHP_LIBVIRT_WORLD_VERSION VIRT_COPY_OPT); + add_assoc_string(return_value, "connector.version", PHP_LIBVIRT_WORLD_VERSION VIRT_COPY_OPT); add_assoc_long(return_value, "connector.major", VERSION_MAJOR); add_assoc_long(return_value, "connector.minor", VERSION_MINOR); add_assoc_long(return_value, "connector.release", VERSION_MICRO); diff --git a/src/tests/skipif.inc b/src/tests/skipif.inc new file mode 100644 index 0000000..9f3159b --- /dev/null +++ b/src/tests/skipif.inc @@ -0,0 +1,3 @@ +<?php + if (!extension_loaded('libvirt')) die('skip libvirt extension not available'); +?> diff --git a/src/tests/test-version-get.phpt b/src/tests/test-version-get.phpt new file mode 100644 index 0000000..b0ab5a3 --- /dev/null +++ b/src/tests/test-version-get.phpt @@ -0,0 +1,27 @@ +--TEST-- +libvirt_version +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +var_dump(libvirt_version()); +?> +Done +--EXPECTF-- +array(7) { + ["libvirt.release"]=> + int(%d) + ["libvirt.minor"]=> + int(%d) + ["libvirt.major"]=> + int(%d) + ["connector.version"]=> + string(%d) "%s" + ["connector.major"]=> + int(%d) + ["connector.minor"]=> + int(%d) + ["connector.release"]=> + int(%d) +} +Done -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/tests/test-connect.phpt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/tests/test-connect.phpt diff --git a/src/tests/test-connect.phpt b/src/tests/test-connect.phpt new file mode 100644 index 0000000..2aab021 --- /dev/null +++ b/src/tests/test-connect.phpt @@ -0,0 +1,15 @@ +--TEST-- +libvirt_version +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + $conn = libvirt_connect('test:///default'); + var_dump($conn); + unset($conn); +?> +Done +--EXPECTF-- +resource(%d) of type (Libvirt connection) +Done + -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> PHP 5 => #define add_assoc_string(__arg, __key, __str, __duplicate) add_assoc_string_ex(__arg, __key, strlen(__key)+1, __str, __duplicate) PHP 7 => #define add_assoc_string(__arg, __key, __str) add_assoc_string_ex(__arg, __key, strlen(__key), __str) --- src/libvirt-php.c | 136 +++++++++++++++++++++++++++--------------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 1977039..ee79f0e 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -2003,7 +2003,7 @@ if ((snapshot==NULL) || (snapshot->snapshot==NULL)) RETURN_FALSE;\ #define LONGLONG_ASSOC(out,key,in) \ if (LIBVIRT_G(longlong_to_string_ini)) { \ snprintf(tmpnumber,63,"%llu",in); \ - add_assoc_string_ex(out,key,strlen(key)+1,tmpnumber VIRT_COPY_OPT); \ + add_assoc_string(out,key,tmpnumber VIRT_COPY_OPT); \ } \ else \ { \ @@ -2232,7 +2232,7 @@ PHP_FUNCTION(libvirt_node_get_info) if (retval==-1) RETURN_FALSE; array_init(return_value); - add_assoc_string_ex(return_value, "model", 6, info.model VIRT_COPY_OPT); + add_assoc_string(return_value, "model", info.model VIRT_COPY_OPT); add_assoc_long(return_value, "memory", (long)info.memory); add_assoc_long(return_value, "cpus", (long)info.cpus); add_assoc_long(return_value, "nodes", (long)info.nodes); @@ -2335,9 +2335,9 @@ PHP_FUNCTION(libvirt_node_get_cpu_stats) add_assoc_long(return_value, "cpu", cpunr); else if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS) - add_assoc_string_ex(return_value, "cpu", 4, "all" VIRT_COPY_OPT); + add_assoc_string(return_value, "cpu", "all" VIRT_COPY_OPT); else - add_assoc_string_ex(return_value, "cpu", 4, "unknown" VIRT_COPY_OPT); + add_assoc_string(return_value, "cpu", "unknown" VIRT_COPY_OPT); free(params); params = NULL; @@ -2580,14 +2580,14 @@ PHP_FUNCTION(libvirt_connect_get_machine_types) char tmp3[2048] = { 0 }; snprintf(key, sizeof(key), "%d", k); - //add_assoc_string_ex(arr2, key, strlen(key) + 1, ret3[k] VIRT_COPY_OPT); + //add_assoc_string(arr2, key, ret3[k] VIRT_COPY_OPT); snprintf(tmp3, sizeof(tmp3), "//capabilities/guest/arch[@name=\"%s\"]/machine[text()=\"%s\"]/@maxCpus", ret[i], ret3[k]); numTmp = get_string_from_xpath(caps, tmp3, NULL, NULL); if (numTmp == NULL) - add_assoc_string_ex(arr2, key, strlen(key) + 1, ret3[k] VIRT_COPY_OPT); + add_assoc_string(arr2, key, ret3[k] VIRT_COPY_OPT); else { #if PHP_MAJOR_VERSION >= 7 zval *arr4, zarr4; @@ -2598,8 +2598,8 @@ PHP_FUNCTION(libvirt_connect_get_machine_types) #endif array_init(arr4); - add_assoc_string_ex(arr4, "name", 5, ret3[k] VIRT_COPY_OPT); - add_assoc_string_ex(arr4, "maxCpus", 9, numTmp VIRT_COPY_OPT); + add_assoc_string(arr4, "name", ret3[k] VIRT_COPY_OPT); + add_assoc_string(arr4, "maxCpus", numTmp VIRT_COPY_OPT); add_assoc_zval_ex(arr2, key, strlen(key) + 1, arr4); free(numTmp); @@ -2627,7 +2627,7 @@ PHP_FUNCTION(libvirt_connect_get_machine_types) numTmp = get_string_from_xpath(caps, tmp3, NULL, NULL); if (numTmp == NULL) - add_assoc_string_ex(arr3, key, strlen(key) + 1, ret3[k] VIRT_COPY_OPT); + add_assoc_string(arr3, key, ret3[k] VIRT_COPY_OPT); else { #if PHP_MAJOR_VERSION >= 7 zval *arr4, zarr4; @@ -2638,8 +2638,8 @@ PHP_FUNCTION(libvirt_connect_get_machine_types) #endif array_init(arr4); - add_assoc_string_ex(arr4, "name", 5, ret3[k] VIRT_COPY_OPT); - add_assoc_string_ex(arr4, "maxCpus", 9, numTmp VIRT_COPY_OPT); + add_assoc_string(arr4, "name", ret3[k] VIRT_COPY_OPT); + add_assoc_string(arr4, "maxCpus", numTmp VIRT_COPY_OPT); add_assoc_zval_ex(arr3, key, strlen(key) + 1, arr4); free(numTmp); @@ -2682,21 +2682,21 @@ PHP_FUNCTION(libvirt_connect_get_information) tmp = virConnectGetURI(conn->conn); DPRINTF("%s: Got connection URI of %s...\n", PHPFUNC, tmp); array_init(return_value); - add_assoc_string_ex(return_value, "uri", 4, tmp ? tmp : "unknown" VIRT_COPY_OPT); + add_assoc_string(return_value, "uri", tmp ? tmp : "unknown" VIRT_COPY_OPT); free(tmp); tmp = virConnectGetHostname(conn->conn); - add_assoc_string_ex(return_value, "hostname", 9, tmp ? tmp : "unknown" VIRT_COPY_OPT); + add_assoc_string(return_value, "hostname", tmp ? tmp : "unknown" VIRT_COPY_OPT); free(tmp); if ((virConnectGetVersion(conn->conn, &hvVer) == 0) && (type = virConnectGetType(conn->conn))) { - add_assoc_string_ex(return_value, "hypervisor", 11, (char *)type VIRT_COPY_OPT); + add_assoc_string(return_value, "hypervisor", (char *)type VIRT_COPY_OPT); add_assoc_long(return_value, "hypervisor_major",(long)((hvVer/1000000) % 1000)); add_assoc_long(return_value, "hypervisor_minor",(long)((hvVer/1000) % 1000)); add_assoc_long(return_value, "hypervisor_release",(long)(hvVer %1000)); snprintf(hvStr, sizeof(hvStr), "%s %d.%d.%d", type, (long)((hvVer/1000000) % 1000), (long)((hvVer/1000) % 1000), (long)(hvVer %1000)); - add_assoc_string_ex(return_value, "hypervisor_string", 18, hvStr VIRT_COPY_OPT); + add_assoc_string(return_value, "hypervisor_string", hvStr VIRT_COPY_OPT); } if (strcmp(type, "QEMU") == 0) { @@ -2709,21 +2709,21 @@ PHP_FUNCTION(libvirt_connect_get_information) add_assoc_long(return_value, "hypervisor_maxvcpus", maxvcpus); iTmp = virConnectIsEncrypted(conn->conn); if (iTmp == 1) - add_assoc_string_ex(return_value, "encrypted", 10, "Yes" VIRT_COPY_OPT); + add_assoc_string(return_value, "encrypted", "Yes" VIRT_COPY_OPT); else if (iTmp == 0) - add_assoc_string_ex(return_value, "encrypted", 10, "No" VIRT_COPY_OPT); + add_assoc_string(return_value, "encrypted", "No" VIRT_COPY_OPT); else - add_assoc_string_ex(return_value, "encrypted", 10, "unknown" VIRT_COPY_OPT); + add_assoc_string(return_value, "encrypted", "unknown" VIRT_COPY_OPT); iTmp = virConnectIsSecure(conn->conn); if (iTmp == 1) - add_assoc_string_ex(return_value, "secure", 7, "Yes" VIRT_COPY_OPT); + add_assoc_string(return_value, "secure", "Yes" VIRT_COPY_OPT); else if (iTmp == 0) - add_assoc_string_ex(return_value, "secure", 7, "No" VIRT_COPY_OPT); + add_assoc_string(return_value, "secure", "No" VIRT_COPY_OPT); else - add_assoc_string_ex(return_value, "secure", 7, "unknown" VIRT_COPY_OPT); + add_assoc_string(return_value, "secure", "unknown" VIRT_COPY_OPT); add_assoc_long(return_value, "num_inactive_domains", virConnectNumOfDefinedDomains(conn->conn)); add_assoc_long(return_value, "num_inactive_interfaces", virConnectNumOfDefinedInterfaces(conn->conn)); @@ -2938,14 +2938,14 @@ PHP_FUNCTION(libvirt_connect_get_hypervisor) DPRINTF("%s: virConnectGetType returned %s\n", PHPFUNC, type); array_init(return_value); - add_assoc_string_ex(return_value, "hypervisor", 11, (char *)type VIRT_COPY_OPT); + add_assoc_string(return_value, "hypervisor", (char *)type VIRT_COPY_OPT); add_assoc_long(return_value, "major",(long)((hvVer/1000000) % 1000)); add_assoc_long(return_value, "minor",(long)((hvVer/1000) % 1000)); add_assoc_long(return_value, "release",(long)(hvVer %1000)); snprintf(hvStr, sizeof(hvStr), "%s %d.%d.%d", type, (long)((hvVer/1000000) % 1000), (long)((hvVer/1000) % 1000), (long)(hvVer %1000)); - add_assoc_string_ex(return_value, "hypervisor_string", 18, hvStr VIRT_COPY_OPT); + add_assoc_string(return_value, "hypervisor_string", hvStr VIRT_COPY_OPT); } /* @@ -3045,7 +3045,7 @@ PHP_FUNCTION(libvirt_connect_get_all_domain_stats) add_assoc_bool(arr2, params.field, params.value.b); break; case VIR_TYPED_PARAM_STRING: - add_assoc_string_ex(arr2, params.field, strlen(params.field)+1, params.value.s VIRT_COPY_OPT); + add_assoc_string(arr2, params.field, params.value.s VIRT_COPY_OPT); break; } } @@ -3170,7 +3170,7 @@ char *get_string_from_xpath(char *xml, char *xpath, zval **val, int *retVal) value = (char *)xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1); snprintf(key, sizeof(key), "%d", i); - add_assoc_string_ex(*val, key, strlen(key)+1, value VIRT_COPY_OPT); + add_assoc_string(*val, key, value VIRT_COPY_OPT); ret++; } } @@ -4658,12 +4658,12 @@ PHP_FUNCTION(libvirt_domain_get_screenshot_api) if (WEXITSTATUS(exitStatus) != 0) RETURN_FALSE; - add_assoc_string_ex(return_value, "file", 5, fileNew VIRT_COPY_OPT); - add_assoc_string_ex(return_value, "mime", 5, "image/png" VIRT_COPY_OPT); + add_assoc_string(return_value, "file", fileNew VIRT_COPY_OPT); + add_assoc_string(return_value, "mime", "image/png" VIRT_COPY_OPT); } else { - add_assoc_string_ex(return_value, "file", 5, file VIRT_COPY_OPT); - add_assoc_string_ex(return_value, "mime", 5, mime VIRT_COPY_OPT); + add_assoc_string(return_value, "file", file VIRT_COPY_OPT); + add_assoc_string(return_value, "mime", mime VIRT_COPY_OPT); } } @@ -5220,7 +5220,7 @@ PHP_FUNCTION(libvirt_connect_get_nic_models) tTokenizer t = tokenize(tmp, ","); for (i = 0; i < t.numTokens; i++) { snprintf(tmp2, sizeof(tmp2), "%d", i); - add_assoc_string_ex(return_value, tmp2, strlen(tmp2) + 1, t.tokens[i] VIRT_COPY_OPT); + add_assoc_string(return_value, tmp2, t.tokens[i] VIRT_COPY_OPT); } free_tokens(t); } @@ -5318,14 +5318,14 @@ PHP_FUNCTION(libvirt_connect_get_soundhw_models) } array_init(arr); - add_assoc_string_ex(arr, "name", 5, t.tokens[0] VIRT_COPY_OPT); - add_assoc_string_ex(arr, "description", 12, desc VIRT_COPY_OPT); + add_assoc_string(arr, "name", t.tokens[0] VIRT_COPY_OPT); + add_assoc_string(arr, "description", desc VIRT_COPY_OPT); add_next_index_zval(return_value, arr); } else { char tmp2[16] = { 0 }; snprintf(tmp2, sizeof(tmp2), "%d", n++); - add_assoc_string_ex(return_value, tmp2, strlen(tmp2) + 1, t.tokens[0] VIRT_COPY_OPT); + add_assoc_string(return_value, tmp2, t.tokens[0] VIRT_COPY_OPT); } free_tokens(t); @@ -6847,8 +6847,8 @@ PHP_FUNCTION(libvirt_domain_get_network_info) } array_init(return_value); - add_assoc_string_ex(return_value, "mac", 4, mac VIRT_COPY_OPT); - add_assoc_string_ex(return_value, "network", 8, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "mac", mac VIRT_COPY_OPT); + add_assoc_string(return_value, "network", tmp VIRT_COPY_OPT); free(tmp); free(xpath); @@ -6859,9 +6859,9 @@ PHP_FUNCTION(libvirt_domain_get_network_info) } tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "nic_type", 9, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "nic_type", tmp VIRT_COPY_OPT); else - add_assoc_string_ex(return_value, "nic_type", 9, "default" VIRT_COPY_OPT); + add_assoc_string(return_value, "nic_type", "default" VIRT_COPY_OPT); free(xml); free(xpath); @@ -6946,12 +6946,12 @@ PHP_FUNCTION(libvirt_domain_get_block_info) array_init(return_value); LONGLONG_INIT; - add_assoc_string_ex(return_value, "device", 7, dev VIRT_COPY_OPT); + add_assoc_string(return_value, "device", dev VIRT_COPY_OPT); if (isFile) - add_assoc_string_ex(return_value, "file", 5, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "file", tmp VIRT_COPY_OPT); else - add_assoc_string_ex(return_value, "partition", 10, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "partition", tmp VIRT_COPY_OPT); free(xpath); if (asprintf(&xpath, "//domain/devices/disk/target[@dev='%s']/../driver/@type", dev) < 0) { @@ -6961,7 +6961,7 @@ PHP_FUNCTION(libvirt_domain_get_block_info) free(tmp); tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if (tmp != NULL) - add_assoc_string_ex(return_value, "type", 5, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "type", tmp VIRT_COPY_OPT); LONGLONG_ASSOC(return_value, "capacity", info.capacity); LONGLONG_ASSOC(return_value, "allocation", info.allocation); @@ -7018,7 +7018,7 @@ PHP_FUNCTION(libvirt_domain_xml_xpath) if (rc == 0) RETURN_FALSE; - add_assoc_string_ex(return_value, "xpath", 6, (char *)zpath VIRT_COPY_OPT); + add_assoc_string(return_value, "xpath", (char *)zpath VIRT_COPY_OPT); if (rc < 0) add_assoc_long(return_value, "error_code", (long)rc); } @@ -9117,18 +9117,18 @@ PHP_FUNCTION(libvirt_nodedev_get_information) goto error; } - add_assoc_string_ex(return_value, "name", 5, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "name", tmp VIRT_COPY_OPT); /* Get parent name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/parent", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "parent", 7, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "parent", tmp VIRT_COPY_OPT); /* Get capability */ cap = get_string_from_xpath(xml, "//device/capability/@type", NULL, &retval); if ((cap != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "capability", 11, cap VIRT_COPY_OPT); + add_assoc_string(return_value, "capability", cap VIRT_COPY_OPT); /* System capability is having hardware and firmware sub-blocks */ if (strcmp(cap, "system") == 0) { @@ -9136,92 +9136,92 @@ PHP_FUNCTION(libvirt_nodedev_get_information) free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/hardware/vendor", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "hardware_vendor", 16, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "hardware_vendor", tmp VIRT_COPY_OPT); /* Get hardware version */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/hardware/version", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "hardware_version", 17, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "hardware_version", tmp VIRT_COPY_OPT); /* Get hardware serial */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/hardware/serial", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "hardware_serial", 16, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "hardware_serial", tmp VIRT_COPY_OPT); /* Get hardware UUID */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/hardware/uuid", NULL, &retval); if (tmp != NULL) - add_assoc_string_ex(return_value, "hardware_uuid", 15, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "hardware_uuid", tmp VIRT_COPY_OPT); /* Get firmware vendor */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/firmware/vendor", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "firmware_vendor", 16, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "firmware_vendor", tmp VIRT_COPY_OPT); /* Get firmware version */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/firmware/version", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "firmware_version", 17, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "firmware_version", tmp VIRT_COPY_OPT); /* Get firmware release date */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/firmware/release_date", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "firmware_release_date", 22, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "firmware_release_date", tmp VIRT_COPY_OPT); } /* Get product_id */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/product/@id", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "product_id", 11, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "product_id", tmp VIRT_COPY_OPT); /* Get product_name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/product", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "product_name", 13, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "product_name", tmp VIRT_COPY_OPT); /* Get vendor_id */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/vendor/@id", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "vendor_id", 10, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "vendor_id", tmp VIRT_COPY_OPT); /* Get vendor_name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/vendor", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "vendor_name", 12, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "vendor_name", tmp VIRT_COPY_OPT); /* Get driver name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/driver/name", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "driver_name", 12, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "driver_name", tmp VIRT_COPY_OPT); /* Get driver name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/interface", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "interface_name", 15, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "interface_name", tmp VIRT_COPY_OPT); /* Get driver name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/address", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "address", 8, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "address", tmp VIRT_COPY_OPT); /* Get driver name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/capability/@type", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string_ex(return_value, "capabilities", 11, tmp VIRT_COPY_OPT); + add_assoc_string(return_value, "capabilities", tmp VIRT_COPY_OPT); free(cap); free(tmp); @@ -9426,42 +9426,42 @@ PHP_FUNCTION(libvirt_network_get_information) RETURN_FALSE; } - add_assoc_string_ex(return_value, "name", 5, name VIRT_COPY_OPT); + add_assoc_string(return_value, "name", name VIRT_COPY_OPT); /* Get gateway IP address */ ipaddr = get_string_from_xpath(xml, "//network/ip/@address", NULL, &retval); if (ipaddr && retval > 0) - add_assoc_string_ex(return_value, "ip", 3, ipaddr VIRT_COPY_OPT); + add_assoc_string(return_value, "ip", ipaddr VIRT_COPY_OPT); /* Get netmask */ netmask = get_string_from_xpath(xml, "//network/ip/@netmask", NULL, &retval); if (netmask && retval > 0) { int subnet_bits = get_subnet_bits(netmask); - add_assoc_string_ex(return_value, "netmask", 8, netmask VIRT_COPY_OPT); + add_assoc_string(return_value, "netmask", netmask VIRT_COPY_OPT); add_assoc_long(return_value, "netmask_bits", (long) subnet_bits); /* Format CIDR address representation */ ipaddr[strlen(ipaddr) - 1] = ipaddr[strlen(ipaddr) - 1] - 1; snprintf(fixedtemp, sizeof(fixedtemp), "%s/%d", ipaddr, subnet_bits); - add_assoc_string_ex(return_value, "ip_range", 9, fixedtemp VIRT_COPY_OPT); + add_assoc_string(return_value, "ip_range", fixedtemp VIRT_COPY_OPT); } /* Get forwarding settings */ mode = get_string_from_xpath(xml, "//network/forward/@mode", NULL, &retval); if (mode && retval > 0) - add_assoc_string_ex(return_value, "forwarding", 11, mode VIRT_COPY_OPT); + add_assoc_string(return_value, "forwarding", mode VIRT_COPY_OPT); /* Get forwarding settings */ dev = get_string_from_xpath(xml, "//network/forward/@dev", NULL, &retval); if (dev && retval > 0) - add_assoc_string_ex(return_value, "forward_dev", 12, dev VIRT_COPY_OPT); + add_assoc_string(return_value, "forward_dev", dev VIRT_COPY_OPT); /* Get DHCP values */ dhcp_start = get_string_from_xpath(xml, "//network/ip/dhcp/range/@start", NULL, &retval); dhcp_end = get_string_from_xpath(xml, "//network/ip/dhcp/range/@end", NULL, &retval); if (dhcp_start && dhcp_end && retval > 0) { - add_assoc_string_ex(return_value, "dhcp_start", 11, dhcp_start VIRT_COPY_OPT); - add_assoc_string_ex(return_value, "dhcp_end", 9, dhcp_end VIRT_COPY_OPT); + add_assoc_string(return_value, "dhcp_start", dhcp_start VIRT_COPY_OPT); + add_assoc_string(return_value, "dhcp_end", dhcp_end VIRT_COPY_OPT); } free(dhcp_end); -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> - %p doesn't work with PHP snprintf - store max_connections_ini as long instead of string - store mem as pointer instead of integer - convert test-conn-limit to phpt --- src/libvirt-php.c | 33 ++++++++++++--------------------- src/libvirt-php.h | 4 ++-- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index ee79f0e..af80f06 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -682,7 +682,7 @@ PHP_INI_BEGIN() STD_PHP_INI_ENTRY("libvirt.longlong_to_string", "1", PHP_INI_ALL, OnUpdateBool, longlong_to_string_ini, zend_libvirt_globals, libvirt_globals) STD_PHP_INI_ENTRY("libvirt.iso_path", "/var/lib/libvirt/images/iso", PHP_INI_ALL, OnUpdateString, iso_path_ini, zend_libvirt_globals, libvirt_globals) STD_PHP_INI_ENTRY("libvirt.image_path", "/var/lib/libvirt/images", PHP_INI_ALL, OnUpdateString, image_path_ini, zend_libvirt_globals, libvirt_globals) -STD_PHP_INI_ENTRY("libvirt.max_connections", "5", PHP_INI_ALL, OnUpdateString, max_connections_ini, zend_libvirt_globals, libvirt_globals) +STD_PHP_INI_ENTRY("libvirt.max_connections", "5", PHP_INI_ALL, OnUpdateLong, max_connections_ini, zend_libvirt_globals, libvirt_globals) PHP_INI_END() void change_debug(int val TSRMLS_DC) @@ -697,7 +697,7 @@ static void php_libvirt_init_globals(zend_libvirt_globals *libvirt_globals TSRML libvirt_globals->longlong_to_string_ini = 1; libvirt_globals->iso_path_ini = "/var/lib/libvirt/images/iso"; libvirt_globals->image_path_ini = "/var/lib/libvirt/images"; - libvirt_globals->max_connections_ini = "5"; + libvirt_globals->max_connections_ini = 5; libvirt_globals->binding_resources_count = 0; libvirt_globals->binding_resources = NULL; #ifdef DEBUG_SUPPORT @@ -877,18 +877,13 @@ void free_tokens(tTokenizer t) * @inc [int/bool]: Increment the counter (1 = add memory location) or decrement the counter (0 = remove memory location) from entries. * Returns: 0 on success, -errno otherwise */ -int resource_change_counter(int type, virConnectPtr conn, void *memp, int inc TSRMLS_DC) +int resource_change_counter(int type, virConnectPtr conn, void *mem, int inc TSRMLS_DC) { int i; int pos = -1; int binding_resources_count; - char tmp[64] = { 0 }; - arch_uint mem = 0; resource_info *binding_resources = NULL; - snprintf(tmp, sizeof(tmp), "%p", memp); - sscanf(tmp, "%"UINTx, &mem); - binding_resources_count = LIBVIRT_G(binding_resources_count); binding_resources = LIBVIRT_G(binding_resources); @@ -1011,7 +1006,8 @@ PHP_MINFO_FUNCTION(libvirt) php_info_print_table_row(2, "Libvirt version", version); } - php_info_print_table_row(2, "Max. connections", LIBVIRT_G(max_connections_ini)); + snprintf(path, sizeof(path), "%lu", (unsigned long)LIBVIRT_G(max_connections_ini)); + php_info_print_table_row(2, "Max. connections", path); if (!access(LIBVIRT_G(iso_path_ini), F_OK) == 0) snprintf(path, sizeof(path), "%s - path is invalid. To set the valid path modify the libvirt.iso_path in your php.ini configuration!", @@ -1254,16 +1250,11 @@ void free_resources_on_connection(virConnectPtr conn TSRMLS_DC) * @memp [pointer]: pointer to the memory * Returns: 1 if resource is allocated, 0 otherwise */ -int check_resource_allocation(virConnectPtr conn, int type, void *memp TSRMLS_DC) +int check_resource_allocation(virConnectPtr conn, int type, void *mem TSRMLS_DC) { int binding_resources_count = 0; resource_info *binding_resources = NULL; int i, allocated = 0; - char tmp[64] = { 0 }; - arch_uint mem = 0; - - snprintf(tmp, sizeof(tmp), "%p", memp); - sscanf(tmp, "%"UINTx, &mem); binding_resources_count = LIBVIRT_G(binding_resources_count); binding_resources = LIBVIRT_G(binding_resources); @@ -2120,8 +2111,8 @@ PHP_FUNCTION(libvirt_connect) RETURN_FALSE; } - if ((count_resources(INT_RESOURCE_CONNECTION TSRMLS_CC) + 1) > atoi(LIBVIRT_G(max_connections_ini))) { - DPRINTF("%s: maximum number of connections allowed exceeded (max %s)\n",PHPFUNC, LIBVIRT_G(max_connections_ini)); + if ((count_resources(INT_RESOURCE_CONNECTION TSRMLS_CC) + 1) > LIBVIRT_G(max_connections_ini)) { + DPRINTF("%s: maximum number of connections allowed exceeded (max %lu)\n",PHPFUNC, (unsigned long)LIBVIRT_G(max_connections_ini)); set_error("Maximum number of connections allowed exceeded" TSRMLS_CC); RETURN_FALSE; } @@ -9755,11 +9746,11 @@ PHP_FUNCTION(libvirt_print_binding_resources) for (i = 0; i < binding_resources_count; i++) { if (binding_resources[i].overwrite == 0) { if (binding_resources[i].conn != NULL) - snprintf(tmp, sizeof(tmp), "Libvirt %s resource at 0x%"UINTx" (connection %p)", translate_counter_type(binding_resources[i].type), - binding_resources[i].mem, binding_resources[i].conn); + snprintf(tmp, sizeof(tmp), "Libvirt %s resource at 0x%lx (connection %lx)", translate_counter_type(binding_resources[i].type), + (long)binding_resources[i].mem, (long)binding_resources[i].conn); else - snprintf(tmp, sizeof(tmp), "Libvirt %s resource at 0x%"UINTx, translate_counter_type(binding_resources[i].type), - binding_resources[i].mem); + snprintf(tmp, sizeof(tmp), "Libvirt %s resource at 0x%lx", translate_counter_type(binding_resources[i].type), + (long)binding_resources[i].mem); add_next_index_string(return_value, tmp VIRT_COPY_OPT); } } diff --git a/src/libvirt-php.h b/src/libvirt-php.h index d1f034e..09b3868 100644 --- a/src/libvirt-php.h +++ b/src/libvirt-php.h @@ -166,7 +166,7 @@ typedef struct tTokenizer { typedef struct _resource_info { int type; virConnectPtr conn; - arch_uint mem; + void *mem; int overwrite; } resource_info; @@ -176,7 +176,7 @@ ZEND_BEGIN_MODULE_GLOBALS(libvirt) zend_bool longlong_to_string_ini; char *iso_path_ini; char *image_path_ini; - char *max_connections_ini; + zend_long max_connections_ini; #ifdef DEBUG_SUPPORT int debug; #endif -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/tests/test-conn-limit.phpt | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/tests/test-conn-limit.phpt diff --git a/src/tests/test-conn-limit.phpt b/src/tests/test-conn-limit.phpt new file mode 100644 index 0000000..23f8e98 --- /dev/null +++ b/src/tests/test-conn-limit.phpt @@ -0,0 +1,49 @@ +--TEST-- +libvirt_version +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--INI-- +libvirt.max_connections=3 +--FILE-- +<?php + + $num_ini = ini_get("libvirt.max_connections"); + var_dump($num_ini); + + $num = $num_ini + 1; + + for ($i = 0; $i < $num; $i++) + $conn[] = libvirt_connect('test:///default', false); + var_dump($conn); + + $tmp = libvirt_print_binding_resources(); + var_dump($tmp); + + for ($i = 0; $i < $num; $i++) + unset($conn[$i]); +?> +Done +--EXPECTF-- +string(1) "3" + +%s Maximum number of connections allowed exceeded %s +array(4) { + [0]=> + resource(%d) of type (Libvirt connection) + [1]=> + resource(%d) of type (Libvirt connection) + [2]=> + resource(%d) of type (Libvirt connection) + [3]=> + bool(false) +} +array(3) { + [0]=> + string(%d) "Libvirt connection resource at %s" + [1]=> + string(%d) "Libvirt connection resource at %s" + [2]=> + string(%d) "Libvirt connection resource at %s" +} +Done + -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/tests/test-conn-limit.phpt | 2 +- src/tests/test-connect-get-emulator.phpt | 15 +++++++++++++++ src/tests/test-connect.phpt | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/tests/test-connect-get-emulator.phpt diff --git a/src/tests/test-conn-limit.phpt b/src/tests/test-conn-limit.phpt index 23f8e98..8fa0fc4 100644 --- a/src/tests/test-conn-limit.phpt +++ b/src/tests/test-conn-limit.phpt @@ -1,5 +1,5 @@ --TEST-- -libvirt_version +INI: libvirt.max_connections --SKIPIF-- <?php require_once('skipif.inc'); ?> --INI-- diff --git a/src/tests/test-connect-get-emulator.phpt b/src/tests/test-connect-get-emulator.phpt new file mode 100644 index 0000000..7d8e8ce --- /dev/null +++ b/src/tests/test-connect-get-emulator.phpt @@ -0,0 +1,15 @@ +--TEST-- +libvirt_connect_get_emulator +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + $conn = libvirt_connect('test:///default'); + var_dump(libvirt_connect_get_emulator($conn)); + unset($conn); +?> +Done +--EXPECTF-- +string(%d) "%s" +Done + diff --git a/src/tests/test-connect.phpt b/src/tests/test-connect.phpt index 2aab021..f0cfce9 100644 --- a/src/tests/test-connect.phpt +++ b/src/tests/test-connect.phpt @@ -1,5 +1,5 @@ --TEST-- -libvirt_version +libvirt_connect --SKIPIF-- <?php require_once('skipif.inc'); ?> --FILE-- -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index af80f06..511dcaa 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -1128,11 +1128,11 @@ static void catch_error(void *userData, * @mem [uint]: memory location of the resource to be freed * Returns: None */ -void free_resource(int type, arch_uint mem TSRMLS_DC) +void free_resource(int type, void *mem TSRMLS_DC) { int rv; - DPRINTF("%s: Freeing libvirt %s resource at 0x%"UINTx"\n", __FUNCTION__, translate_counter_type(type), mem); + DPRINTF("%s: Freeing libvirt %s resource at 0x%lx\n", __FUNCTION__, translate_counter_type(type), (unsigned long)mem); if (type == INT_RESOURCE_DOMAIN) { rv = virDomainFree( (virDomainPtr)mem ); @@ -1269,8 +1269,8 @@ int check_resource_allocation(virConnectPtr conn, int type, void *mem TSRMLS_DC) allocated = 1; } - DPRINTF("%s: libvirt %s resource 0x%"UINTx" (conn %p) is%s allocated\n", __FUNCTION__, translate_counter_type(type), - mem, conn, !allocated ? " not" : ""); + DPRINTF("%s: libvirt %s resource 0x%lx (conn %p) is%s allocated\n", __FUNCTION__, translate_counter_type(type), + (unsigned long)mem, conn, !allocated ? " not" : ""); return allocated; } @@ -5365,12 +5365,13 @@ void parse_array(zval *arr, tVMDisk *disk, tVMNetwork *network) else if ((Z_TYPE_P(data) == IS_STRING) && strcmp(ZSTR_VAL(key), "dev") == 0) disk->dev = strdup( Z_STRVAL_P(data) ); else if (strcmp(ZSTR_VAL(key), "size") == 0) { - if (Z_TYPE_P(data) == IS_LONG) + if (Z_TYPE_P(data) == IS_LONG) { disk->size = Z_LVAL_P(data); - else + } else { disk->size = size_def_to_mbytes(Z_STRVAL_P(data)); + } } - else if ((Z_TYPE_P(data) == IS_LONG) && strcmp(ZSTR_VAL(key), "dev") == 0) + else if ((Z_TYPE_P(data) == IS_LONG) && strcmp(ZSTR_VAL(key), "flags") == 0) disk->flags = Z_LVAL_P(data); } else { if (network != NULL) { -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/tests/test-install.phpt | 136 +++++++++++++++++++++++++++++++++++++++++ src/tests/test-libvirt-php.img | 0 2 files changed, 136 insertions(+) create mode 100644 src/tests/test-install.phpt create mode 100644 src/tests/test-libvirt-php.img diff --git a/src/tests/test-install.phpt b/src/tests/test-install.phpt new file mode 100644 index 0000000..eac0875 --- /dev/null +++ b/src/tests/test-install.phpt @@ -0,0 +1,136 @@ +--TEST-- +libvirt_domain_new +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + $logfile = __DIR__ . '/test-install.log'; + @unlink($logfile); + libvirt_logfile_set($logfile, 10); + + $name = 'test'; + $image = __DIR__.'/test-libvirt-php.img'; + $disk_image = '/tmp/test-libvirt-php.img'; + $local_test = true; + $show_vnc_location = false; + $memory = 64; + + echo "# libvirt_connect\n"; + $conn = libvirt_connect('test:///default', false); /* Enable read-write connection */ + var_dump($conn); + + //cleaning + if ($res = libvirt_domain_lookup_by_name($conn, "test")) { + libvirt_domain_destroy($res); + libvirt_domain_undefine($res); + } + + $disks = array( + array( 'path' => $disk_image, 'driver' => 'raw', 'bus' => 'ide', 'dev' => 'hda', 'size' => '1M', + 'flags' => VIR_DOMAIN_DISK_FILE | VIR_DOMAIN_DISK_ACCESS_ALL ) + ); + + $networks = array( + array( 'mac' => '00:11:22:33:44:55', 'network' => 'default', 'model' => 'e1000') + ); + + $networks = array(); + + $flags = VIR_DOMAIN_FLAG_FEATURE_ACPI | VIR_DOMAIN_FLAG_FEATURE_APIC | VIR_DOMAIN_FLAG_FEATURE_PAE; + + if ($local_test) + $flags |= VIR_DOMAIN_FLAG_TEST_LOCAL_VNC; + + echo "# libvirt_domain_new\n"; + $res = libvirt_domain_new($conn, $name, false, $memory, $memory, 1, $image, $disks, $networks, $flags); + var_dump($res); + if ($res == false) + echo 'Installation test failed with error: '.libvirt_get_last_error().'. More info saved into '.$logfile; + + echo "# libvirt_domain_get_name\n"; + var_dump(libvirt_domain_get_name($res)); + + echo "# libvirt_domain_get_id\n"; + var_dump(libvirt_domain_get_id($res)); + + echo "# libvirt_domain_get_uuid\n"; + var_dump(bin2hex(libvirt_domain_get_uuid($res))); + + echo "# libvirt_domain_get_uuid_string\n"; + var_dump(libvirt_domain_get_uuid_string($res)); + + echo "# libvirt_domain_get_info\n"; + var_dump(libvirt_domain_get_info($res)); + + $ok = is_resource($res); + + echo "# libvirt_domain_new_get_vnc\n"; + $vncloc = libvirt_domain_new_get_vnc(); + var_dump($vncloc); + + echo "libvirt_domain_destroy\n"; + var_dump($ret = libvirt_domain_destroy($res)); + if (!$ret) + echo 'Domain destroy failed with error: '.libvirt_get_last_error().'. More info saved into '.$logfile; + + unset($res); + + echo "# libvirt_domain_lookup_by_name\n"; + $res = libvirt_domain_lookup_by_name($conn, $name); + var_dump($res); + if (is_resource($res)) { + echo "# libvirt_domain_undefine\n"; + var_dump(libvirt_domain_undefine($res)); + } + unset($res); + + echo "# libvirt_domain_lookup_by_name\n"; + $res = libvirt_domain_lookup_by_name($conn, $name); + var_dump($res); + + unset($res); + unset($conn); + + @unlink($disk_image); + @unlink($logfile); +?> +Done +--EXPECTF-- +# libvirt_connect +resource(%d) of type (Libvirt connection) +# libvirt_domain_new +resource(%d) of type (Libvirt domain) +# libvirt_domain_get_name +string(12) "test-install" +# libvirt_domain_get_id +int(%d) +# libvirt_domain_get_uuid +string(%d) "%s" +# libvirt_domain_get_uuid_string +string(%d) "%s" +# libvirt_domain_get_info +array(5) { + ["maxMem"]=> + int(65536) + ["memory"]=> + int(65536) + ["state"]=> + int(1) + ["nrVirtCpu"]=> + int(1) + ["cpuUsed"]=> + float(%s) +} +# libvirt_domain_new_get_vnc +string(%d) "%s" +libvirt_domain_destroy +bool(true) +# libvirt_domain_lookup_by_name +resource(%d) of type (Libvirt domain) +# libvirt_domain_undefine +bool(true) +# libvirt_domain_lookup_by_name + +%s Domain not found %s +bool(false) +Done diff --git a/src/tests/test-libvirt-php.img b/src/tests/test-libvirt-php.img new file mode 100644 index 0000000..e69de29 -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/tests/example-no-disk-and-media.xml | 41 +++++++++++++++++++++ src/tests/test-domain-create-and-coredump.phpt | 49 ++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/tests/example-no-disk-and-media.xml create mode 100644 src/tests/test-domain-create-and-coredump.phpt diff --git a/src/tests/example-no-disk-and-media.xml b/src/tests/example-no-disk-and-media.xml new file mode 100644 index 0000000..a691ff4 --- /dev/null +++ b/src/tests/example-no-disk-and-media.xml @@ -0,0 +1,41 @@ +<domain type='test'> + <name>test-guest-no-disk-and-media</name> + <uuid>28a15e00-9c40-ddc1-b6df-9a08921b93f0</uuid> + <memory>65535</memory> + <currentMemory>65535</currentMemory> + <vcpu>1</vcpu> + <os> + <type arch='i686'>hvm</type> + <boot dev='cdrom'/> + </os> + <features> + <acpi/> + <apic/> + <pae/> + </features> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>restart</on_crash> + <devices> + <controller type='ide' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </controller> + <controller type='scsi' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> + </controller> + <serial type='pty'> + <target port='0'/> + </serial> + <console type='pty'> + <target type='serial' port='0'/> + </console> + <input type='mouse' bus='ps2'/> + <graphics type='vnc' port='-1' autoport='yes'/> + <video> + <model type='cirrus' vram='9216' heads='1'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </video> + </devices> +</domain> + diff --git a/src/tests/test-domain-create-and-coredump.phpt b/src/tests/test-domain-create-and-coredump.phpt new file mode 100644 index 0000000..790da97 --- /dev/null +++ b/src/tests/test-domain-create-and-coredump.phpt @@ -0,0 +1,49 @@ +--TEST-- +libvirt_domain_core_dump +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + echo "# libvirt_connect\n"; + var_dump($conn = libvirt_connect('test:///default', false)); + if (!is_resource($conn)) + die('Connection to default hypervisor failed'); + + $xml = file_get_contents(__DIR__.'/example-no-disk-and-media.xml'); + + echo "# libvirt_domain_create_xml\n"; + var_dump($res = libvirt_domain_create_xml($conn, $xml)); + if (!is_resource($res)) + die('Domain definition failed with error: '.libvirt_get_last_error()); + + $name = tempnam(sys_get_temp_dir(), 'guestdumptest'); + echo "# libvirt_domain_core_dump\n"; + var_dump($ret = libvirt_domain_core_dump($res, $name)); + if (!$ret) + die('Cannot dump core of the guest: '.libvirt_get_last_error()); + var_dump(file_exists($name)); + + echo "# libvirt_domain_destroy\n"; + var_dump($ret = libvirt_domain_destroy($res)); + if (!$ret) { + unlink($name); + die('Domain destroy failed with error: '.libvirt_get_last_error()); + } + + unset($res); + unset($conn); + unlink($name); +?> +Done +--EXPECTF-- +# libvirt_connect +resource(%d) of type (Libvirt connection) +# libvirt_domain_create_xml +resource(%d) of type (Libvirt domain) +# libvirt_domain_core_dump +bool(true) +bool(true) +# libvirt_domain_destroy +bool(true) +Done + -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/tests/test-domain-create-and-get-xpath.phpt | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/tests/test-domain-create-and-get-xpath.phpt diff --git a/src/tests/test-domain-create-and-get-xpath.phpt b/src/tests/test-domain-create-and-get-xpath.phpt new file mode 100644 index 0000000..84e8895 --- /dev/null +++ b/src/tests/test-domain-create-and-get-xpath.phpt @@ -0,0 +1,56 @@ +--TEST-- +libvirt_domain_xml_xpath +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + echo "# libvirt_connect\n"; + var_dump($conn = libvirt_connect('test:///default', false)); + if (!is_resource($conn)) + die('Connection to default hypervisor failed'); + + $xml = file_get_contents(__DIR__.'/example-no-disk-and-media.xml'); + + echo "# libvirt_domain_create_xml\n"; + var_dump($res = libvirt_domain_create_xml($conn, $xml)); + if (!is_resource($res)) + die('Domain definition failed with error: '.libvirt_get_last_error()); + + $info = libvirt_domain_xml_xpath($res, '/domain/name'); + if (!$info) + die('Cannot get domain XML and/or xPath expression'); + var_dump($info); + + if (!array_key_exists('num', $info)) + die('Num element is missing in the output array'); + + for ($i = 0; $i < $info['num']; $i++) + if (!array_key_exists($i, $info)) + die("Element $i doesn\'t exist in the output array"); + + echo "# libvirt_domain_destroy\n"; + var_dump($ret = libvirt_domain_destroy($res)); + if (!$ret) { + die('Domain destroy failed with error: '.libvirt_get_last_error()); + } + unset($res); + unset($conn); +?> +Done +--EXPECTF-- +# libvirt_connect +resource(%d) of type (Libvirt connection) +# libvirt_domain_create_xml +resource(%d) of type (Libvirt domain) +array(3) { + [0]=> + string(28) "test-guest-no-disk-and-media" + ["num"]=> + int(1) + ["xpath"]=> + string(12) "/domain/name" +} +# libvirt_domain_destroy +bool(true) +Done + -- 2.5.5

From: Remi Collet <fedora@famillecollet.com> --- src/libvirt-php.c | 163 +++++++++++++++++++++++------------------------------- src/libvirt-php.h | 26 +++++++++ 2 files changed, 95 insertions(+), 94 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 511dcaa..9a32d79 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -55,31 +55,6 @@ const char *features[] = { NULL }; const char *features_binaries[] = { NULL }; #endif -#if PHP_MAJOR_VERSION >= 7 -typedef size_t strsize_t; - -#define VIRT_COPY_OPT -#define VIRT_RETVAL_STRING(str) RETVAL_STRING(str) -#define VIRT_ZVAL_STRINGL(zv,str,len) ZVAL_STRINGL(zv,str,len) - -#define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \ - if ((_state = (_type)zend_fetch_resource(Z_RES_P(*_zval), _name, _le)) == NULL) { \ - RETURN_FALSE; \ - } - -#else -typedef int strsize_t; -typedef long zend_long; -typedef unsigned long zend_ulong; - -#define VIRT_COPY_OPT ,1 -#define VIRT_RETVAL_STRING(str) RETVAL_STRING(str, 1) -#define VIRT_ZVAL_STRINGL(zv,str,len) ZVAL_STRINGL(zv,str,len,1) - -#define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \ - ZEND_FETCH_RESOURCE(_state, _type, _zval, -1, _name, _le); - -#endif /* ZEND thread safe per request globals definition */ int le_libvirt_connection; int le_libvirt_domain; @@ -1994,7 +1969,7 @@ if ((snapshot==NULL) || (snapshot->snapshot==NULL)) RETURN_FALSE;\ #define LONGLONG_ASSOC(out,key,in) \ if (LIBVIRT_G(longlong_to_string_ini)) { \ snprintf(tmpnumber,63,"%llu",in); \ - add_assoc_string(out,key,tmpnumber VIRT_COPY_OPT); \ + VIRT_ADD_ASSOC_STRING(out,key,tmpnumber); \ } \ else \ { \ @@ -2223,7 +2198,7 @@ PHP_FUNCTION(libvirt_node_get_info) if (retval==-1) RETURN_FALSE; array_init(return_value); - add_assoc_string(return_value, "model", info.model VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "model", info.model); add_assoc_long(return_value, "memory", (long)info.memory); add_assoc_long(return_value, "cpus", (long)info.cpus); add_assoc_long(return_value, "nodes", (long)info.nodes); @@ -2326,9 +2301,9 @@ PHP_FUNCTION(libvirt_node_get_cpu_stats) add_assoc_long(return_value, "cpu", cpunr); else if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS) - add_assoc_string(return_value, "cpu", "all" VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "cpu", "all"); else - add_assoc_string(return_value, "cpu", "unknown" VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "cpu", "unknown"); free(params); params = NULL; @@ -2571,14 +2546,14 @@ PHP_FUNCTION(libvirt_connect_get_machine_types) char tmp3[2048] = { 0 }; snprintf(key, sizeof(key), "%d", k); - //add_assoc_string(arr2, key, ret3[k] VIRT_COPY_OPT); + //VIRT_ADD_ASSOC_STRING(arr2, key, ret3[k]); snprintf(tmp3, sizeof(tmp3), "//capabilities/guest/arch[@name=\"%s\"]/machine[text()=\"%s\"]/@maxCpus", ret[i], ret3[k]); numTmp = get_string_from_xpath(caps, tmp3, NULL, NULL); if (numTmp == NULL) - add_assoc_string(arr2, key, ret3[k] VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(arr2, key, ret3[k]); else { #if PHP_MAJOR_VERSION >= 7 zval *arr4, zarr4; @@ -2589,8 +2564,8 @@ PHP_FUNCTION(libvirt_connect_get_machine_types) #endif array_init(arr4); - add_assoc_string(arr4, "name", ret3[k] VIRT_COPY_OPT); - add_assoc_string(arr4, "maxCpus", numTmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(arr4, "name", ret3[k]); + VIRT_ADD_ASSOC_STRING(arr4, "maxCpus", numTmp); add_assoc_zval_ex(arr2, key, strlen(key) + 1, arr4); free(numTmp); @@ -2618,7 +2593,7 @@ PHP_FUNCTION(libvirt_connect_get_machine_types) numTmp = get_string_from_xpath(caps, tmp3, NULL, NULL); if (numTmp == NULL) - add_assoc_string(arr3, key, ret3[k] VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(arr3, key, ret3[k]); else { #if PHP_MAJOR_VERSION >= 7 zval *arr4, zarr4; @@ -2629,8 +2604,8 @@ PHP_FUNCTION(libvirt_connect_get_machine_types) #endif array_init(arr4); - add_assoc_string(arr4, "name", ret3[k] VIRT_COPY_OPT); - add_assoc_string(arr4, "maxCpus", numTmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(arr4, "name", ret3[k]); + VIRT_ADD_ASSOC_STRING(arr4, "maxCpus", numTmp); add_assoc_zval_ex(arr3, key, strlen(key) + 1, arr4); free(numTmp); @@ -2673,21 +2648,21 @@ PHP_FUNCTION(libvirt_connect_get_information) tmp = virConnectGetURI(conn->conn); DPRINTF("%s: Got connection URI of %s...\n", PHPFUNC, tmp); array_init(return_value); - add_assoc_string(return_value, "uri", tmp ? tmp : "unknown" VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "uri", tmp ? tmp : "unknown"); free(tmp); tmp = virConnectGetHostname(conn->conn); - add_assoc_string(return_value, "hostname", tmp ? tmp : "unknown" VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "hostname", tmp ? tmp : "unknown"); free(tmp); if ((virConnectGetVersion(conn->conn, &hvVer) == 0) && (type = virConnectGetType(conn->conn))) { - add_assoc_string(return_value, "hypervisor", (char *)type VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "hypervisor", (char *)type); add_assoc_long(return_value, "hypervisor_major",(long)((hvVer/1000000) % 1000)); add_assoc_long(return_value, "hypervisor_minor",(long)((hvVer/1000) % 1000)); add_assoc_long(return_value, "hypervisor_release",(long)(hvVer %1000)); snprintf(hvStr, sizeof(hvStr), "%s %d.%d.%d", type, (long)((hvVer/1000000) % 1000), (long)((hvVer/1000) % 1000), (long)(hvVer %1000)); - add_assoc_string(return_value, "hypervisor_string", hvStr VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "hypervisor_string", hvStr); } if (strcmp(type, "QEMU") == 0) { @@ -2700,21 +2675,21 @@ PHP_FUNCTION(libvirt_connect_get_information) add_assoc_long(return_value, "hypervisor_maxvcpus", maxvcpus); iTmp = virConnectIsEncrypted(conn->conn); if (iTmp == 1) - add_assoc_string(return_value, "encrypted", "Yes" VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "encrypted", "Yes"); else if (iTmp == 0) - add_assoc_string(return_value, "encrypted", "No" VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "encrypted", "No"); else - add_assoc_string(return_value, "encrypted", "unknown" VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "encrypted", "unknown"); iTmp = virConnectIsSecure(conn->conn); if (iTmp == 1) - add_assoc_string(return_value, "secure", "Yes" VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "secure", "Yes"); else if (iTmp == 0) - add_assoc_string(return_value, "secure", "No" VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "secure", "No"); else - add_assoc_string(return_value, "secure", "unknown" VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "secure", "unknown"); add_assoc_long(return_value, "num_inactive_domains", virConnectNumOfDefinedDomains(conn->conn)); add_assoc_long(return_value, "num_inactive_interfaces", virConnectNumOfDefinedInterfaces(conn->conn)); @@ -2929,14 +2904,14 @@ PHP_FUNCTION(libvirt_connect_get_hypervisor) DPRINTF("%s: virConnectGetType returned %s\n", PHPFUNC, type); array_init(return_value); - add_assoc_string(return_value, "hypervisor", (char *)type VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "hypervisor", (char *)type); add_assoc_long(return_value, "major",(long)((hvVer/1000000) % 1000)); add_assoc_long(return_value, "minor",(long)((hvVer/1000) % 1000)); add_assoc_long(return_value, "release",(long)(hvVer %1000)); snprintf(hvStr, sizeof(hvStr), "%s %d.%d.%d", type, (long)((hvVer/1000000) % 1000), (long)((hvVer/1000) % 1000), (long)(hvVer %1000)); - add_assoc_string(return_value, "hypervisor_string", hvStr VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "hypervisor_string", hvStr); } /* @@ -3036,7 +3011,7 @@ PHP_FUNCTION(libvirt_connect_get_all_domain_stats) add_assoc_bool(arr2, params.field, params.value.b); break; case VIR_TYPED_PARAM_STRING: - add_assoc_string(arr2, params.field, params.value.s VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(arr2, params.field, params.value.s); break; } } @@ -3161,7 +3136,7 @@ char *get_string_from_xpath(char *xml, char *xpath, zval **val, int *retVal) value = (char *)xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1); snprintf(key, sizeof(key), "%d", i); - add_assoc_string(*val, key, value VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(*val, key, value); ret++; } } @@ -4649,12 +4624,12 @@ PHP_FUNCTION(libvirt_domain_get_screenshot_api) if (WEXITSTATUS(exitStatus) != 0) RETURN_FALSE; - add_assoc_string(return_value, "file", fileNew VIRT_COPY_OPT); - add_assoc_string(return_value, "mime", "image/png" VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "file", fileNew); + VIRT_ADD_ASSOC_STRING(return_value, "mime", "image/png"); } else { - add_assoc_string(return_value, "file", file VIRT_COPY_OPT); - add_assoc_string(return_value, "mime", mime VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "file", file); + VIRT_ADD_ASSOC_STRING(return_value, "mime", mime); } } @@ -5211,7 +5186,7 @@ PHP_FUNCTION(libvirt_connect_get_nic_models) tTokenizer t = tokenize(tmp, ","); for (i = 0; i < t.numTokens; i++) { snprintf(tmp2, sizeof(tmp2), "%d", i); - add_assoc_string(return_value, tmp2, t.tokens[i] VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, tmp2, t.tokens[i]); } free_tokens(t); } @@ -5309,14 +5284,14 @@ PHP_FUNCTION(libvirt_connect_get_soundhw_models) } array_init(arr); - add_assoc_string(arr, "name", t.tokens[0] VIRT_COPY_OPT); - add_assoc_string(arr, "description", desc VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(arr, "name", t.tokens[0]); + VIRT_ADD_ASSOC_STRING(arr, "description", desc); add_next_index_zval(return_value, arr); } else { char tmp2[16] = { 0 }; snprintf(tmp2, sizeof(tmp2), "%d", n++); - add_assoc_string(return_value, tmp2, t.tokens[0] VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, tmp2, t.tokens[0]); } free_tokens(t); @@ -6839,8 +6814,8 @@ PHP_FUNCTION(libvirt_domain_get_network_info) } array_init(return_value); - add_assoc_string(return_value, "mac", mac VIRT_COPY_OPT); - add_assoc_string(return_value, "network", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "mac", mac); + VIRT_ADD_ASSOC_STRING(return_value, "network", tmp); free(tmp); free(xpath); @@ -6851,9 +6826,9 @@ PHP_FUNCTION(libvirt_domain_get_network_info) } tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "nic_type", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "nic_type", tmp); else - add_assoc_string(return_value, "nic_type", "default" VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "nic_type", "default"); free(xml); free(xpath); @@ -6938,12 +6913,12 @@ PHP_FUNCTION(libvirt_domain_get_block_info) array_init(return_value); LONGLONG_INIT; - add_assoc_string(return_value, "device", dev VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "device", dev); if (isFile) - add_assoc_string(return_value, "file", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "file", tmp); else - add_assoc_string(return_value, "partition", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "partition", tmp); free(xpath); if (asprintf(&xpath, "//domain/devices/disk/target[@dev='%s']/../driver/@type", dev) < 0) { @@ -6953,7 +6928,7 @@ PHP_FUNCTION(libvirt_domain_get_block_info) free(tmp); tmp = get_string_from_xpath(xml, xpath, NULL, &retval); if (tmp != NULL) - add_assoc_string(return_value, "type", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "type", tmp); LONGLONG_ASSOC(return_value, "capacity", info.capacity); LONGLONG_ASSOC(return_value, "allocation", info.allocation); @@ -7010,7 +6985,7 @@ PHP_FUNCTION(libvirt_domain_xml_xpath) if (rc == 0) RETURN_FALSE; - add_assoc_string(return_value, "xpath", (char *)zpath VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "xpath", (char *)zpath); if (rc < 0) add_assoc_long(return_value, "error_code", (long)rc); } @@ -9109,18 +9084,18 @@ PHP_FUNCTION(libvirt_nodedev_get_information) goto error; } - add_assoc_string(return_value, "name", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "name", tmp); /* Get parent name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/parent", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "parent", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "parent", tmp); /* Get capability */ cap = get_string_from_xpath(xml, "//device/capability/@type", NULL, &retval); if ((cap != NULL) && (retval > 0)) - add_assoc_string(return_value, "capability", cap VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "capability", cap); /* System capability is having hardware and firmware sub-blocks */ if (strcmp(cap, "system") == 0) { @@ -9128,92 +9103,92 @@ PHP_FUNCTION(libvirt_nodedev_get_information) free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/hardware/vendor", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "hardware_vendor", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "hardware_vendor", tmp); /* Get hardware version */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/hardware/version", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "hardware_version", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "hardware_version", tmp); /* Get hardware serial */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/hardware/serial", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "hardware_serial", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "hardware_serial", tmp); /* Get hardware UUID */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/hardware/uuid", NULL, &retval); if (tmp != NULL) - add_assoc_string(return_value, "hardware_uuid", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "hardware_uuid", tmp); /* Get firmware vendor */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/firmware/vendor", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "firmware_vendor", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "firmware_vendor", tmp); /* Get firmware version */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/firmware/version", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "firmware_version", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "firmware_version", tmp); /* Get firmware release date */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/firmware/release_date", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "firmware_release_date", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "firmware_release_date", tmp); } /* Get product_id */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/product/@id", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "product_id", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "product_id", tmp); /* Get product_name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/product", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "product_name", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "product_name", tmp); /* Get vendor_id */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/vendor/@id", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "vendor_id", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "vendor_id", tmp); /* Get vendor_name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/vendor", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "vendor_name", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "vendor_name", tmp); /* Get driver name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/driver/name", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "driver_name", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "driver_name", tmp); /* Get driver name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/interface", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "interface_name", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "interface_name", tmp); /* Get driver name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/address", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "address", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "address", tmp); /* Get driver name */ free(tmp); tmp = get_string_from_xpath(xml, "//device/capability/capability/@type", NULL, &retval); if ((tmp != NULL) && (retval > 0)) - add_assoc_string(return_value, "capabilities", tmp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "capabilities", tmp); free(cap); free(tmp); @@ -9418,42 +9393,42 @@ PHP_FUNCTION(libvirt_network_get_information) RETURN_FALSE; } - add_assoc_string(return_value, "name", name VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "name", name); /* Get gateway IP address */ ipaddr = get_string_from_xpath(xml, "//network/ip/@address", NULL, &retval); if (ipaddr && retval > 0) - add_assoc_string(return_value, "ip", ipaddr VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "ip", ipaddr); /* Get netmask */ netmask = get_string_from_xpath(xml, "//network/ip/@netmask", NULL, &retval); if (netmask && retval > 0) { int subnet_bits = get_subnet_bits(netmask); - add_assoc_string(return_value, "netmask", netmask VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "netmask", netmask); add_assoc_long(return_value, "netmask_bits", (long) subnet_bits); /* Format CIDR address representation */ ipaddr[strlen(ipaddr) - 1] = ipaddr[strlen(ipaddr) - 1] - 1; snprintf(fixedtemp, sizeof(fixedtemp), "%s/%d", ipaddr, subnet_bits); - add_assoc_string(return_value, "ip_range", fixedtemp VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "ip_range", fixedtemp); } /* Get forwarding settings */ mode = get_string_from_xpath(xml, "//network/forward/@mode", NULL, &retval); if (mode && retval > 0) - add_assoc_string(return_value, "forwarding", mode VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "forwarding", mode); /* Get forwarding settings */ dev = get_string_from_xpath(xml, "//network/forward/@dev", NULL, &retval); if (dev && retval > 0) - add_assoc_string(return_value, "forward_dev", dev VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "forward_dev", dev); /* Get DHCP values */ dhcp_start = get_string_from_xpath(xml, "//network/ip/dhcp/range/@start", NULL, &retval); dhcp_end = get_string_from_xpath(xml, "//network/ip/dhcp/range/@end", NULL, &retval); if (dhcp_start && dhcp_end && retval > 0) { - add_assoc_string(return_value, "dhcp_start", dhcp_start VIRT_COPY_OPT); - add_assoc_string(return_value, "dhcp_end", dhcp_end VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "dhcp_start", dhcp_start); + VIRT_ADD_ASSOC_STRING(return_value, "dhcp_end", dhcp_end); } free(dhcp_end); @@ -9587,7 +9562,7 @@ PHP_FUNCTION(libvirt_version) add_assoc_long(return_value, "libvirt.minor",(long)((libVer/1000) % 1000)); add_assoc_long(return_value, "libvirt.major",(long)((libVer/1000000) % 1000)); - add_assoc_string(return_value, "connector.version", PHP_LIBVIRT_WORLD_VERSION VIRT_COPY_OPT); + VIRT_ADD_ASSOC_STRING(return_value, "connector.version", PHP_LIBVIRT_WORLD_VERSION); add_assoc_long(return_value, "connector.major", VERSION_MAJOR); add_assoc_long(return_value, "connector.minor", VERSION_MINOR); add_assoc_long(return_value, "connector.release", VERSION_MICRO); diff --git a/src/libvirt-php.h b/src/libvirt-php.h index 09b3868..a966f67 100644 --- a/src/libvirt-php.h +++ b/src/libvirt-php.h @@ -138,6 +138,32 @@ typedef uint64_t arch_uint; #define UINTx PRIx64 #endif +#if PHP_MAJOR_VERSION >= 7 +typedef size_t strsize_t; + +#define VIRT_COPY_OPT +#define VIRT_RETVAL_STRING(str) RETVAL_STRING(str) +#define VIRT_ZVAL_STRINGL(zv,str,len) ZVAL_STRINGL(zv,str,len) +#define VIRT_ADD_ASSOC_STRING(arr,name,val) add_assoc_string(arr,name,val) +#define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \ + if ((_state = (_type)zend_fetch_resource(Z_RES_P(*_zval), _name, _le)) == NULL) { \ + RETURN_FALSE; \ + } + +#else +typedef int strsize_t; +typedef long zend_long; +typedef unsigned long zend_ulong; + +#define VIRT_COPY_OPT ,1 +#define VIRT_RETVAL_STRING(str) RETVAL_STRING(str, 1) +#define VIRT_ZVAL_STRINGL(zv,str,len) ZVAL_STRINGL(zv,str,len,1) +#define VIRT_ADD_ASSOC_STRING(arr,name,val) add_assoc_string(arr,name,val,1) +#define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \ + ZEND_FETCH_RESOURCE(_state, _type, _zval, -1, _name, _le); + +#endif + int connect_socket(char *server, char *port, int keepalive, int nodelay, int allow_server_override); int socket_has_data(int sfd, long maxtime, int ignoremsg); void socket_read(int sfd, long length); -- 2.5.5

From: Vasiliy Tolstov <v.tolstov@selfip.ru> Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libvirt-php.c | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 57e1b83..27bd828 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -6876,7 +6876,9 @@ PHP_FUNCTION(libvirt_storagepool_list_volumes) GET_STORAGEPOOL_FROM_ARGS("r",&zpool); - expectedcount=virStoragePoolNumOfVolumes (pool->pool); + if ((expectedcount=virStoragePoolNumOfVolumes (pool->pool)) < 0) + RETURN_FALSE; + DPRINTF("%s: virStoragePoolNumOfVolumes(%p) returned %d\n", PHPFUNC, pool->pool, expectedcount); names=(char **)emalloc(expectedcount*sizeof(char *)); @@ -7741,7 +7743,8 @@ PHP_FUNCTION(libvirt_list_storagepools) GET_CONNECTION_FROM_ARGS("r",&zconn); - expectedcount=virConnectNumOfStoragePools(conn->conn); + if ((expectedcount=virConnectNumOfStoragePools(conn->conn)) < 0) + RETURN_FALSE; names=(char **)emalloc(expectedcount*sizeof(char *)); count=virConnectListStoragePools(conn->conn,names,expectedcount); @@ -7761,7 +7764,8 @@ PHP_FUNCTION(libvirt_list_storagepools) efree(names); - expectedcount = virConnectNumOfDefinedStoragePools (conn->conn); + if ((expectedcount = virConnectNumOfDefinedStoragePools (conn->conn)) < 0) + RETURN_FALSE; names = (char **)emalloc (expectedcount * sizeof(char *)); count = virConnectListDefinedStoragePools (conn->conn, names, expectedcount); if ((count != expectedcount) || (count < 0)) @@ -7796,7 +7800,8 @@ PHP_FUNCTION(libvirt_list_active_storagepools) GET_CONNECTION_FROM_ARGS("r",&zconn); - expectedcount=virConnectNumOfStoragePools(conn->conn); + if ((expectedcount=virConnectNumOfStoragePools(conn->conn)) < 0) + RETURN_FALSE; names=(char **)emalloc(expectedcount*sizeof(char *)); count=virConnectListStoragePools(conn->conn,names,expectedcount); @@ -7833,7 +7838,9 @@ PHP_FUNCTION(libvirt_list_inactive_storagepools) GET_CONNECTION_FROM_ARGS("r",&zconn); - expectedcount = virConnectNumOfDefinedStoragePools (conn->conn); + if ((expectedcount = virConnectNumOfDefinedStoragePools (conn->conn)) < 0) + RETURN_FALSE; + names= (char **)emalloc (expectedcount * sizeof(char *)); count = virConnectListDefinedStoragePools (conn->conn, names, expectedcount); if ((count != expectedcount) || (count < 0)) @@ -7872,7 +7879,9 @@ PHP_FUNCTION(libvirt_list_domains) GET_CONNECTION_FROM_ARGS("r",&zconn); - expectedcount=virConnectNumOfDomains (conn->conn); + if ((expectedcount=virConnectNumOfDomains (conn->conn)) < 0) + RETURN_FALSE; + DPRINTF("%s: Found %d domains\n", PHPFUNC, expectedcount); ids=(int *)emalloc(sizeof(int)*expectedcount); @@ -7953,7 +7962,8 @@ PHP_FUNCTION(libvirt_list_domain_resources) GET_CONNECTION_FROM_ARGS("r",&zconn); - expectedcount=virConnectNumOfDomains (conn->conn); + if ((expectedcount=virConnectNumOfDomains (conn->conn)) < 0) + RETURN_FALSE; ids=(int *)emalloc(sizeof(int)*expectedcount); count=virConnectListDomains (conn->conn,ids,expectedcount); @@ -7981,7 +7991,9 @@ PHP_FUNCTION(libvirt_list_domain_resources) } efree(ids); - expectedcount=virConnectNumOfDefinedDomains (conn->conn); + if ((expectedcount=virConnectNumOfDefinedDomains (conn->conn)) < 0) + RETURN_FALSE; + names=(char **)emalloc(expectedcount*sizeof(char *)); count=virConnectListDefinedDomains (conn->conn,names ,expectedcount); if ((count != expectedcount) || (count<0)) @@ -8027,7 +8039,8 @@ PHP_FUNCTION(libvirt_list_active_domain_ids) GET_CONNECTION_FROM_ARGS("r",&zconn); - expectedcount=virConnectNumOfDomains (conn->conn); + if ((expectedcount=virConnectNumOfDomains (conn->conn)) < 0) + RETURN_FALSE; ids=(int *)emalloc(sizeof(int)*expectedcount); count=virConnectListDomains (conn->conn,ids,expectedcount); @@ -8064,7 +8077,8 @@ PHP_FUNCTION(libvirt_list_active_domains) GET_CONNECTION_FROM_ARGS("r",&zconn); - expectedcount=virConnectNumOfDomains (conn->conn); + if ((expectedcount=virConnectNumOfDomains (conn->conn)) < 0) + RETURN_FALSE; ids=(int *)emalloc(sizeof(int)*expectedcount); count=virConnectListDomains (conn->conn,ids,expectedcount); @@ -8115,7 +8129,8 @@ PHP_FUNCTION(libvirt_list_inactive_domains) GET_CONNECTION_FROM_ARGS("r",&zconn); - expectedcount=virConnectNumOfDefinedDomains (conn->conn); + if ((expectedcount=virConnectNumOfDefinedDomains (conn->conn)) < 0) + RETURN_FALSE; names=(char **)emalloc(expectedcount*sizeof(char *)); count=virConnectListDefinedDomains (conn->conn,names ,expectedcount); @@ -8156,7 +8171,9 @@ PHP_FUNCTION(libvirt_list_networks) array_init(return_value); if (flags & VIR_NETWORKS_ACTIVE) { - expectedcount=virConnectNumOfNetworks(conn->conn); + if ((expectedcount=virConnectNumOfNetworks(conn->conn)) < 0) + RETURN_FALSE; + names=(char **)emalloc(expectedcount*sizeof(char *)); count=virConnectListNetworks(conn->conn,names,expectedcount); if ((count != expectedcount) || (count<0)) @@ -8176,7 +8193,8 @@ PHP_FUNCTION(libvirt_list_networks) } if (flags & VIR_NETWORKS_INACTIVE) { - expectedcount=virConnectNumOfDefinedNetworks(conn->conn); + if ((expectedcount=virConnectNumOfDefinedNetworks(conn->conn)) < 0) + RETURN_FALSE; names=(char **)emalloc(expectedcount*sizeof(char *)); count=virConnectListDefinedNetworks(conn->conn,names,expectedcount); if ((count != expectedcount) || (count<0)) @@ -8219,7 +8237,8 @@ PHP_FUNCTION(libvirt_list_nodedevs) GET_CONNECTION_FROM_ARGS("r|s",&zconn,&cap,&cap_len); - expectedcount=virNodeNumOfDevices(conn->conn, cap, 0); + if ((expectedcount=virNodeNumOfDevices(conn->conn, cap, 0)) < 0) + RETURN_FALSE; names=(char **)emalloc(expectedcount*sizeof(char *)); count=virNodeListDevices(conn->conn, cap, names, expectedcount, 0); if ((count != expectedcount) || (count<0)) @@ -8290,7 +8309,8 @@ PHP_FUNCTION(libvirt_nodedev_capabilities) GET_NODEDEV_FROM_ARGS("r",&znodedev); - expectedcount=virNodeDeviceNumOfCaps(nodedev->device); + if ((expectedcount=virNodeDeviceNumOfCaps(nodedev->device)) < 0) + RETURN_FALSE; names=(char **)emalloc(expectedcount*sizeof(char *)); count=virNodeDeviceListCaps(nodedev->device, names, expectedcount); if ((count != expectedcount) || (count<0)) RETURN_FALSE; -- 2.5.5

From: Vasiliy Tolstov <v.tolstov@selfip.ru> Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru> --- src/libvirt-php.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/libvirt-php.h | 1 + 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 27bd828..7bea9e2 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -138,6 +138,7 @@ static zend_function_entry libvirt_functions[] = { PHP_FE(libvirt_domain_set_memory,NULL) PHP_FE(libvirt_domain_set_max_memory,NULL) PHP_FE(libvirt_domain_set_memory_flags,NULL) + PHP_FE(libvirt_domain_block_commit, NULL) PHP_FE(libvirt_domain_block_stats,NULL) PHP_FE(libvirt_domain_block_resize,NULL) PHP_FE(libvirt_domain_block_job_abort,NULL) @@ -1355,11 +1356,40 @@ PHP_MINIT_FUNCTION(libvirt) /* Job was aborted but it's not cleanup up yet */ REGISTER_LONG_CONSTANT("VIR_DOMAIN_JOB_CANCELLED", 5, CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_COMMIT_SHALLOW", VIR_DOMAIN_BLOCK_COMMIT_SHALLOW, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_COMMIT_DELETE", VIR_DOMAIN_BLOCK_COMMIT_DELETE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_COMMIT_ACTIVE", VIR_DOMAIN_BLOCK_COMMIT_ACTIVE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_COMMIT_RELATIVE", VIR_DOMAIN_BLOCK_COMMIT_RELATIVE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES", VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES, CONST_CS | CONST_PERSISTENT); + + + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_COPY_SHALLOW", VIR_DOMAIN_BLOCK_COPY_SHALLOW, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_COPY_REUSE_EXT", VIR_DOMAIN_BLOCK_COPY_REUSE_EXT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC", VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT", VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES", VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES, CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN", VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_JOB_TYPE_PULL", VIR_DOMAIN_BLOCK_JOB_TYPE_PULL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_JOB_TYPE_COPY", VIR_DOMAIN_BLOCK_JOB_TYPE_COPY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT", VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT", VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT, CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_PULL_BANDWIDTH_BYTES", VIR_DOMAIN_BLOCK_PULL_BANDWIDTH_BYTES, CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_REBASE_SHALLOW", VIR_DOMAIN_BLOCK_REBASE_SHALLOW, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT", VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_REBASE_COPY_RAW", VIR_DOMAIN_BLOCK_REBASE_COPY_RAW, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_REBASE_COPY", VIR_DOMAIN_BLOCK_REBASE_COPY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_REBASE_RELATIVE", VIR_DOMAIN_BLOCK_REBASE_RELATIVE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_REBASE_COPY_DEV", VIR_DOMAIN_BLOCK_REBASE_COPY_DEV, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_REBASE_BANDWIDTH_BYTES", VIR_DOMAIN_BLOCK_REBASE_BANDWIDTH_BYTES, CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_RESIZE_BYTES", VIR_DOMAIN_BLOCK_RESIZE_BYTES, CONST_CS | CONST_PERSISTENT); + /* Migration constants */ REGISTER_LONG_CONSTANT("VIR_MIGRATE_LIVE", 1, CONST_CS | CONST_PERSISTENT); /* direct source -> dest host control channel Note the less-common spelling that we're stuck with: */ @@ -6082,6 +6112,40 @@ PHP_FUNCTION(libvirt_domain_block_resize) } /* + * Function name: libvirt_domain_block_commit + * Since version: 0.5.2(-1) + * Description: Function is used to commit block job + * Arguments: @res [resource]: libvirt domain resource, e.g. from libvirt_domain_lookup_by_*() + * @disk [string]: path to the block device, or device shorthand + * @base [string]: path to backing file to merge into, or device shorthand, or NULL for default + * @top [string]: path to file within backing chain that contains data to be merged, or device shorthand, or NULL to merge all possible data + * @bandwidth [int]: (optional) specify bandwidth limit; flags determine the unit + * @flags [int]: bitwise-OR of VIR_DOMAIN_BLOCK_COMMIT_* + * Returns: true on success fail on error + */ +PHP_FUNCTION(libvirt_domain_block_commit) +{ + php_libvirt_domain *domain=NULL; + zval *zdomain; + int retval; + char *disk; + int disk_len; + char *base = NULL; + int base_len; + char *top = NULL; + int top_len; + long bandwidth = 0; + long flags = 0; + + GET_DOMAIN_FROM_ARGS("rsssll",&zdomain, &disk, &disk_len, &base, &base_len, &top, &top_len, &bandwidth, &flags); + + retval=virDomainBlockCommit(domain->domain, disk, base, top, bandwidth, flags); + if (retval == -1) RETURN_FALSE; + + RETURN_TRUE; +} + +/* * Function name: libvirt_domain_block_job_abort * Since version: 0.5.1(-1) * Description: Function is used to abort block job diff --git a/src/libvirt-php.h b/src/libvirt-php.h index eb4b7f4..cb06c2d 100644 --- a/src/libvirt-php.h +++ b/src/libvirt-php.h @@ -403,6 +403,7 @@ PHP_FUNCTION(libvirt_domain_set_memory_flags); PHP_FUNCTION(libvirt_domain_memory_peek); PHP_FUNCTION(libvirt_domain_memory_stats); PHP_FUNCTION(libvirt_domain_update_device); +PHP_FUNCTION(libvirt_domain_block_commit); PHP_FUNCTION(libvirt_domain_block_stats); PHP_FUNCTION(libvirt_domain_block_resize); PHP_FUNCTION(libvirt_domain_block_job_abort); -- 2.5.5

From: Vasiliy Tolstov <v.tolstov@selfip.ru> Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru> Signed-off-by: Yuriy Gromak <sewer@clodo.ru> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libvirt-php.c | 36 ++++++++++++++++++++++++++++++++++++ src/libvirt-php.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 7bea9e2..1af6077 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -143,6 +143,7 @@ static zend_function_entry libvirt_functions[] = { PHP_FE(libvirt_domain_block_resize,NULL) PHP_FE(libvirt_domain_block_job_abort,NULL) PHP_FE(libvirt_domain_block_job_set_speed,NULL) + PHP_FE(libvirt_domain_block_job_info,NULL) PHP_FE(libvirt_domain_interface_stats,NULL) PHP_FE(libvirt_domain_get_connect, NULL) PHP_FE(libvirt_domain_migrate, NULL) @@ -1371,6 +1372,8 @@ PHP_MINIT_FUNCTION(libvirt) REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT", VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES", VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES", VIR_DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN", VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("VIR_DOMAIN_BLOCK_JOB_TYPE_PULL", VIR_DOMAIN_BLOCK_JOB_TYPE_PULL, CONST_CS | CONST_PERSISTENT); @@ -6145,6 +6148,39 @@ PHP_FUNCTION(libvirt_domain_block_commit) RETURN_TRUE; } + +/* + * Function name: libvirt_domain_block_job_info + * Since version: 0.5.2(-1) + * Description: Function is used to request block job information for the given disk + * Arguments: @dom [resource]: libvirt domain resource, e.g. from libvirt_domain_lookup_by_*() + * @disk [string]: path to the block device, or device shorthand + * @flags [int]: bitwise-OR of VIR_DOMAIN_BLOCK_COMMIT_* + * Returns: Array with status virDomainGetBlockJobInfo and blockjob information. +*/ +PHP_FUNCTION(libvirt_domain_block_job_info) +{ + php_libvirt_domain *domain=NULL; + zval *zdomain; + int retval; + char *disk; + int disk_len; + long flags = 0; + virDomainBlockJobInfo info; + + GET_DOMAIN_FROM_ARGS("rs|l",&zdomain, &disk, &disk_len, &flags); + + retval=virDomainGetBlockJobInfo(domain->domain, disk, &info, flags); + + array_init(return_value); + add_assoc_long(return_value, "status", (int)retval); + add_assoc_long(return_value, "type", (int)info.type); + add_assoc_long(return_value, "bandwidth", (unsigned long)info.bandwidth); + add_assoc_long(return_value, "cur", (unsigned long long)info.cur); + add_assoc_long(return_value, "end", (unsigned long long)info.end); +} + + /* * Function name: libvirt_domain_block_job_abort * Since version: 0.5.1(-1) diff --git a/src/libvirt-php.h b/src/libvirt-php.h index cb06c2d..a45b4bd 100644 --- a/src/libvirt-php.h +++ b/src/libvirt-php.h @@ -408,6 +408,7 @@ PHP_FUNCTION(libvirt_domain_block_stats); PHP_FUNCTION(libvirt_domain_block_resize); PHP_FUNCTION(libvirt_domain_block_job_abort); PHP_FUNCTION(libvirt_domain_block_job_set_speed); +PHP_FUNCTION(libvirt_domain_block_job_info); PHP_FUNCTION(libvirt_domain_interface_stats); PHP_FUNCTION(libvirt_domain_get_connect); PHP_FUNCTION(libvirt_domain_migrate); -- 2.5.5

From: Chuck Roydhouse <cer@datto.com> --- src/libvirt-php.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 6b25961..36be055 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -213,6 +213,13 @@ ZEND_ARG_INFO(0, memory) ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_block_commit, 0, 0, 3) +ZEND_ARG_INFO(0, res) +ZEND_ARG_INFO(0, disk) +ZEND_ARG_INFO(0, base) +ZEND_ARG_INFO(0, top) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn_path, 0, 0, 2) ZEND_ARG_INFO(0, conn) ZEND_ARG_INFO(0, path) @@ -238,6 +245,12 @@ ZEND_ARG_INFO(0, bandwidth) ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_block_job_info, 0, 0, 2) +ZEND_ARG_INFO(0, dom) +ZEND_ARG_INFO(0, disk) +ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_migrate, 0, 0, 3) ZEND_ARG_INFO(0, res) ZEND_ARG_INFO(0, dest_conn) @@ -515,12 +528,12 @@ static zend_function_entry libvirt_functions[] = { PHP_FE(libvirt_domain_set_memory, arginfo_libvirt_domain_set_memory) PHP_FE(libvirt_domain_set_max_memory, arginfo_libvirt_domain_set_memory) PHP_FE(libvirt_domain_set_memory_flags, arginfo_libvirt_domain_set_memory_flags) - PHP_FE(libvirt_domain_block_commit, NULL) /* TODO: looks like help dialog? */ + PHP_FE(libvirt_domain_block_commit, arginfo_libvirt_domain_block_commit) PHP_FE(libvirt_domain_block_stats, arginfo_libvirt_conn_path) PHP_FE(libvirt_domain_block_resize, arginfo_libvirt_domain_block_resize) PHP_FE(libvirt_domain_block_job_abort, arginfo_libvirt_domain_block_job_abort) PHP_FE(libvirt_domain_block_job_set_speed, arginfo_libvirt_domain_block_job_set_speed) - PHP_FE(libvirt_domain_block_job_info, NULL) /* TODO: looks like help dialog? */ + PHP_FE(libvirt_domain_block_job_info, arginfo_libvirt_domain_block_job_info) PHP_FE(libvirt_domain_interface_stats, arginfo_libvirt_conn_path) PHP_FE(libvirt_domain_get_connect, arginfo_libvirt_conn) PHP_FE(libvirt_domain_migrate, arginfo_libvirt_domain_migrate) -- 2.5.5

From: Frederic Mora <fmora@datto.com> --- src/tests/qemu-no-disk-and-media.xml | 41 +++++++++ src/tests/test-connect-get-capabilities.phpt | 27 ++++++ src/tests/test-connect-get-info.phpt | 110 +++++++++++++++++++++++++ src/tests/test-connect-get-machine-types.phpt | 30 +++++++ src/tests/test-domain-create-and-shutdown.phpt | 38 +++++++++ src/tests/test-domain-define.phpt | 38 +++++++++ src/tests/test-domain-disk.phpt | 71 ++++++++++++++++ src/tests/test-domain-get.phpt | 91 ++++++++++++++++++++ src/tests/test-domain-lookup-by-name.phpt | 35 ++++++++ src/tests/test-domain-nic.phpt | 52 ++++++++++++ src/tests/test-logfile.phpt | 43 ++++++++++ 11 files changed, 576 insertions(+) create mode 100644 src/tests/qemu-no-disk-and-media.xml create mode 100644 src/tests/test-connect-get-capabilities.phpt create mode 100644 src/tests/test-connect-get-info.phpt create mode 100644 src/tests/test-connect-get-machine-types.phpt create mode 100644 src/tests/test-domain-create-and-shutdown.phpt create mode 100644 src/tests/test-domain-define.phpt create mode 100644 src/tests/test-domain-disk.phpt create mode 100644 src/tests/test-domain-get.phpt create mode 100644 src/tests/test-domain-lookup-by-name.phpt create mode 100644 src/tests/test-domain-nic.phpt create mode 100644 src/tests/test-logfile.phpt diff --git a/src/tests/qemu-no-disk-and-media.xml b/src/tests/qemu-no-disk-and-media.xml new file mode 100644 index 0000000..bad09f9 --- /dev/null +++ b/src/tests/qemu-no-disk-and-media.xml @@ -0,0 +1,41 @@ +<domain type='qemu'> + <name>test-guest-no-disk-and-media</name> + <uuid>28a15e00-9c40-ddc1-b6df-9a08921b93f0</uuid> + <memory>65535</memory> + <currentMemory>65535</currentMemory> + <vcpu>1</vcpu> + <os> + <type arch='i686'>hvm</type> + <boot dev='cdrom'/> + </os> + <features> + <acpi/> + <apic/> + <pae/> + </features> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>restart</on_crash> + <devices> + <controller type='ide' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </controller> + <controller type='scsi' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> + </controller> + <serial type='pty'> + <target port='0'/> + </serial> + <console type='pty'> + <target type='serial' port='0'/> + </console> + <input type='mouse' bus='ps2'/> + <graphics type='vnc' port='-1' autoport='yes'/> + <video> + <model type='cirrus' vram='9216' heads='1'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </video> + </devices> +</domain> + diff --git a/src/tests/test-connect-get-capabilities.phpt b/src/tests/test-connect-get-capabilities.phpt new file mode 100644 index 0000000..3c3d50f --- /dev/null +++ b/src/tests/test-connect-get-capabilities.phpt @@ -0,0 +1,27 @@ +--TEST-- +libvirt_connect_get_capabilities +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + + echo "# libvirt_connect\n"; + var_dump($conn = libvirt_connect('test:///default', false)); + if (!is_resource($conn)) + die('Connection to default hypervisor failed'); + + echo "# libvirt_connect_get_capabilities\n"; + var_dump($res = libvirt_connect_get_emulator($conn)); + if (!$res) { + die('Connect get capabilities failed with error: '.libvirt_get_last_error()); + } + + unset($conn); +?> +Done +--EXPECTF-- +# libvirt_connect +resource(%d) of type (Libvirt connection) +# libvirt_connect_get_capabilities +string(%d) "%s" +Done diff --git a/src/tests/test-connect-get-info.phpt b/src/tests/test-connect-get-info.phpt new file mode 100644 index 0000000..1cfa527 --- /dev/null +++ b/src/tests/test-connect-get-info.phpt @@ -0,0 +1,110 @@ +--TEST-- +libvirt_connect_get_information +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + +echo "# libvirt_connect\n"; +var_dump($conn = libvirt_connect('test:///default', false)); +if (!is_resource($conn)) { + die('Connection to default hypervisor failed'); +} + +echo "# libvirt_node_get_info\n"; +$res = libvirt_node_get_info($conn); + +if (!is_array($res)) { + die("libvirt_node_get_info returned unexpected value: " . print_r($res, true) . + "\nFailed with error: ".libvirt_get_last_error()); +} + +foreach (array('memory', 'cpus') as $k) { + if (!array_key_exists($k, $res) || !is_numeric($res[$k])) { + die("libvirt_node_get_info: Absent or incorrect key \'$k\'. Value: " . print_r($res, true) . + "\nFailed with error: ".libvirt_get_last_error()); + } +} + +unset($res); + +echo "# libvirt_connect_get_uri\n"; +var_dump(libvirt_connect_get_uri($conn)); + +echo "# libvirt_connect_get_hostname\n"; +var_dump(libvirt_connect_get_hostname($conn)); + +echo "# libvirt_domain_get_counts\n"; +$counts = libvirt_domain_get_counts($conn); + +if (!is_array($counts)) { + die("libvirt_domain_get_counts returned unexpected value: " . print_r($counts, true) . + "\nFailed with error: ".libvirt_get_last_error()); +} + +foreach (array("total", "active", "inactive") as $k) { + if (!array_key_exists($k, $counts) || !is_numeric($counts[$k])) { + die("libvirt_domain_get_counts: Absent or incorrect key \'$k\'. Value: " . print_r($counts, true) . + "\nFailed with error: ".libvirt_get_last_error()); + } +} + +echo "# libvirt_list_active_domains\n"; +var_dump(count(libvirt_list_active_domains($conn)) == $counts['active']); + +echo "# libvirt_list_inactive_domains\n"; +var_dump(count(libvirt_list_inactive_domains($conn)) == $counts['inactive']); + +unset($count); + +echo "# libvirt_connect_get_hypervisor\n"; +$res = libvirt_connect_get_hypervisor($conn); +if (!is_array($res)) { + die("libvirt_connect_get_hypervisor returned unexpected value: " . print_r($res, true) . + "\nFailed with error: ".libvirt_get_last_error()); +} +unset($res); + +echo "# libvirt_connect_get_maxvcpus\n"; +var_dump(is_numeric(libvirt_connect_get_maxvcpus($conn))); + +echo "# libvirt_connect_get_information\n"; +$res = @libvirt_connect_get_information($conn); // Need to suppress driver-dependent warning messages +if (!is_array($res)) { + die("libvirt_connect_get_information returned unexpected value: " . print_r($res, true) . + "\nFailed with error: ".libvirt_get_last_error()); +} +unset($res); + +echo "# libvirt_connect_get_encrypted\n"; +var_dump(libvirt_connect_get_encrypted($conn) != -1); + +echo "# libvirt_connect_get_secure\n"; +var_dump(libvirt_connect_get_secure($conn) != -1); + +unset($conn); + +?> +Done +--EXPECTF-- +# libvirt_connect +resource(%d) of type (Libvirt connection) +# libvirt_node_get_info +# libvirt_connect_get_uri +string(%d) "%s" +# libvirt_connect_get_hostname +string(%d) "%s" +# libvirt_domain_get_counts +# libvirt_list_active_domains +bool(true) +# libvirt_list_inactive_domains +bool(true) +# libvirt_connect_get_hypervisor +# libvirt_connect_get_maxvcpus +bool(true) +# libvirt_connect_get_information +# libvirt_connect_get_encrypted +bool(true) +# libvirt_connect_get_secure +bool(true) +Done diff --git a/src/tests/test-connect-get-machine-types.phpt b/src/tests/test-connect-get-machine-types.phpt new file mode 100644 index 0000000..c9b0cd8 --- /dev/null +++ b/src/tests/test-connect-get-machine-types.phpt @@ -0,0 +1,30 @@ +--TEST-- +libvirt_connect_get_machine_types +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + + echo "# libvirt_connect\n"; + var_dump($conn = libvirt_connect('test:///default', false)); + if (!is_resource($conn)) + die('Connection to default hypervisor failed'); + + echo "# libvirt_connect_get_machine_types\n"; + $res = libvirt_connect_get_machine_types($conn); + if (!$res) { + die('Get machine types failed with error: '.libvirt_get_last_error()); + } + if (!is_array($res)) { + die("libvirt_connect_get_machine_types returned unexpected value: " . print_r($res, true) . + "\nFailed with error: ".libvirt_get_last_error()); + } + unset($res); + unset($conn); +?> +Done +--EXPECTF-- +# libvirt_connect +resource(%d) of type (Libvirt connection) +# libvirt_connect_get_machine_types +Done diff --git a/src/tests/test-domain-create-and-shutdown.phpt b/src/tests/test-domain-create-and-shutdown.phpt new file mode 100644 index 0000000..2bed1ab --- /dev/null +++ b/src/tests/test-domain-create-and-shutdown.phpt @@ -0,0 +1,38 @@ +--TEST-- +libvirt_domain_shutdown +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + echo "# libvirt_connect\n"; + var_dump($conn = libvirt_connect('test:///default', false)); + if (!is_resource($conn)) + die('Connection to default hypervisor failed'); + + $xml = file_get_contents(__DIR__.'/example-no-disk-and-media.xml'); + + echo "# libvirt_domain_create_xml\n"; + var_dump($res = libvirt_domain_create_xml($conn, $xml)); + if (!is_resource($res)) + die('Domain definition failed with error: '.libvirt_get_last_error()); + + echo "# libvirt_domain_shutdown\n"; + var_dump($ret = libvirt_domain_shutdown($res)); + if (!$ret) { + die('Domain shutdown failed with error: '.libvirt_get_last_error()); + } + + unset($res); + unset($conn); + +?> +Done +--EXPECTF-- +# libvirt_connect +resource(%d) of type (Libvirt connection) +# libvirt_domain_create_xml +resource(%d) of type (Libvirt domain) +# libvirt_domain_shutdown +bool(true) +Done + diff --git a/src/tests/test-domain-define.phpt b/src/tests/test-domain-define.phpt new file mode 100644 index 0000000..114a127 --- /dev/null +++ b/src/tests/test-domain-define.phpt @@ -0,0 +1,38 @@ +--TEST-- +libvirt_domain_define_xml +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + + echo "# libvirt_connect\n"; + var_dump($conn = libvirt_connect('test:///default', false)); + if (!is_resource($conn)) + die('Connection to default hypervisor failed'); + + $xml = file_get_contents(__DIR__.'/example-no-disk-and-media.xml'); + + echo "# libvirt_domain_define_xml\n"; + var_dump($dom = libvirt_domain_define_xml($conn, $xml)); + if (!is_resource($dom)) + die('Domain definition failed with error: '.libvirt_get_last_error()); + + echo "# libvirt_domain_undefine\n"; + var_dump($ret = libvirt_domain_undefine($dom)); + if (!$ret) { + unlink($name); + die('Domain undefine failed with error: '.libvirt_get_last_error()); + } + + unset($dom); + unset($conn); +?> +Done +--EXPECTF-- +# libvirt_connect +resource(%d) of type (Libvirt connection) +# libvirt_domain_define_xml +resource(%d) of type (Libvirt domain) +# libvirt_domain_undefine +bool(true) +Done diff --git a/src/tests/test-domain-disk.phpt b/src/tests/test-domain-disk.phpt new file mode 100644 index 0000000..c2b7cb5 --- /dev/null +++ b/src/tests/test-domain-disk.phpt @@ -0,0 +1,71 @@ +--TEST-- +libvirt_domain_disk +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + +$disk_devname = 'hda'; // Disk that will be added to existing guest config +$disk_devtype = 'ide'; +$disk_iodriver = 'raw'; +$disk_image = '/tmp/test-libvirt-php.img'; +touch($disk_image); + +$logfile = __DIR__ . '/test.log'; +@unlink($logfile); +echo "# libvirt_logfile_set\n"; +if (!libvirt_logfile_set($logfile, 100)) { // Log file will be 100 KB max + die('Logfile set failed with error: '.libvirt_get_last_error()); +} + +echo "# libvirt_connect\n"; +var_dump($conn = libvirt_connect('qemu:///session', false)); +if (!is_resource($conn)) + die('Connection to default hypervisor failed. Is libvirt started? What about the QEMU driver?'); + +// libvirt_domain_disk_add needs a persistent guest loaded from a file +$xml = file_get_contents(__DIR__.'/qemu-no-disk-and-media.xml'); +echo "# libvirt_domain_define_xml\n"; +var_dump($dom = libvirt_domain_define_xml($conn, $xml)); +if (!is_resource($dom)) { + die('Domain definition failed with error: '.libvirt_get_last_error()); +} + +echo "# libvirt_domain_disk_add\n"; +// The doc is a wrong. It says the function returns a domain resource. +// It actually returns a boolean! +var_dump($ret = libvirt_domain_disk_add($dom, $disk_image, $disk_devname, $disk_devtype, $disk_iodriver, 0)); +if (!$ret) { + die('Domain disk add failed with error: '.libvirt_get_last_error()); +} + +echo "# libvirt_domain_get_disk_devices\n"; +$info = libvirt_domain_get_disk_devices($dom); +var_dump(is_array($info)); +if (!array_key_exists('num', $info)) + die('libvirt_domain_get_disk_devices: Num element is missing in the output array'); + +echo "# libvirt_domain_undefine\n"; +var_dump($ret = libvirt_domain_undefine($dom)); +if (!$ret) { + die('Domain undefine failed with error: '.libvirt_get_last_error()); +} + +unset($dom); +unset($conn); + +?> +Done +--EXPECTF-- +# libvirt_logfile_set +# libvirt_connect +resource(%d) of type (Libvirt connection) +# libvirt_domain_define_xml +resource(%d) of type (Libvirt domain) +# libvirt_domain_disk_add +bool(true) +# libvirt_domain_get_disk_devices +bool(true) +# libvirt_domain_undefine +bool(true) +Done \ No newline at end of file diff --git a/src/tests/test-domain-get.phpt b/src/tests/test-domain-get.phpt new file mode 100644 index 0000000..c723210 --- /dev/null +++ b/src/tests/test-domain-get.phpt @@ -0,0 +1,91 @@ +--TEST-- +libvirt_domain_get_xml +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + +echo "# libvirt_connect\n"; +var_dump($conn = libvirt_connect('test:///default', false)); +if (!is_resource($conn)) + die('Connection to default hypervisor failed'); + +// We need a running domain to be able to pull the id +$xml = file_get_contents(__DIR__.'/example-no-disk-and-media.xml'); +echo "# libvirt_domain_create_xml\n"; +var_dump($dom = libvirt_domain_create_xml($conn, $xml)); +if (!is_resource($dom)) { + die('Domain definition failed with error: '.libvirt_get_last_error()); +} + +echo "# libvirt_domain_get_name\n"; +var_dump($dom_name = libvirt_domain_get_name($dom)); + +echo "# libvirt_domain_get_uuid_string\n"; +var_dump($dom_uuid_str = libvirt_domain_get_uuid_string($dom)); + +echo "# libvirt_domain_get_uuid\n"; +var_dump($dom_uuid = libvirt_domain_get_uuid($dom)); + +echo "# libvirt_domain_get_id\n"; +var_dump($dom_id = libvirt_domain_get_id($dom)); + +echo "# libvirt_domain_lookup_by_uuid_string\n"; +var_dump($dom2 = libvirt_domain_lookup_by_uuid_string($conn, $dom_uuid_str)); +if (!is_resource($dom2)) { + die('Domain lookup by UUID string failed with error: '.libvirt_get_last_error()); +} +unset($dom2); + +echo "# libvirt_domain_lookup_by_id\n"; +var_dump($dom2 = libvirt_domain_lookup_by_id($conn, $dom_id)); +if (!is_resource($dom2)) { + die('Domain lookup by ID failed with error: '.libvirt_get_last_error()); +} +unset($dom2); + +echo "# libvirt_domain_is_persistent\n"; +var_dump(libvirt_domain_is_persistent($dom) !== -1); + +echo "# libvirt_domain_get_xml_desc\n"; +$xmlstr = libvirt_domain_get_xml_desc($dom, NULL); + +$xmlok = (strpos($xmlstr, "<name>{$dom_name}</name>") && + strpos($xmlstr, "<uuid>{$dom_uuid_str}</uuid>")); +var_dump($xmlok); + +echo "# libvirt_domain_shutdown\n"; +var_dump($ret = libvirt_domain_shutdown($dom)); +if (!$ret) { + die('Domain shutdown failed with error: '.libvirt_get_last_error()); +} + +unset($res); +unset($dom); +unset($conn); +?> +Done +--EXPECTF-- +# libvirt_connect +resource(%d) of type (Libvirt connection) +# libvirt_domain_create_xml +resource(%d) of type (Libvirt domain) +# libvirt_domain_get_name +string(%d) "test-guest-no-disk-and-media" +# libvirt_domain_get_uuid_string +string(36) "%s" +# libvirt_domain_get_uuid +string(%d) "%s" +# libvirt_domain_get_id +int(%d) +# libvirt_domain_lookup_by_uuid_string +resource(%d) of type (Libvirt domain) +# libvirt_domain_lookup_by_id +resource(%d) of type (Libvirt domain) +# libvirt_domain_is_persistent +bool(true) +# libvirt_domain_get_xml_desc +bool(true) +# libvirt_domain_shutdown +bool(true) +Done diff --git a/src/tests/test-domain-lookup-by-name.phpt b/src/tests/test-domain-lookup-by-name.phpt new file mode 100644 index 0000000..8beb43c --- /dev/null +++ b/src/tests/test-domain-lookup-by-name.phpt @@ -0,0 +1,35 @@ +--TEST-- +libvirt_domain_lookup_by_name +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + + echo "# libvirt_connect\n"; + var_dump($conn = libvirt_connect('test:///default', false)); + if (!is_resource($conn)) + die('Connection to default hypervisor failed'); + // Loads domain of type 'test', name 'test-guest-no-disk-and-media' + $xml = file_get_contents(__DIR__.'/example-no-disk-and-media.xml'); + + echo "# libvirt_domain_create_xml\n"; + var_dump($res = libvirt_domain_create_xml($conn, $xml)); + if (!is_resource($res)) + die('Domain definition failed with error: '.libvirt_get_last_error()); + + echo "# libvirt_domain_lookup_by_name\n"; + var_dump($dom = libvirt_domain_lookup_by_name($conn, "test")); + + unset($dom); + unset($res); + unset($conn); +?> +Done +--EXPECTF-- +# libvirt_connect +resource(%d) of type (Libvirt connection) +# libvirt_domain_create_xml +resource(%d) of type (Libvirt domain) +# libvirt_domain_lookup_by_name +resource(%d) of type (Libvirt domain) +Done diff --git a/src/tests/test-domain-nic.phpt b/src/tests/test-domain-nic.phpt new file mode 100644 index 0000000..ac72c64 --- /dev/null +++ b/src/tests/test-domain-nic.phpt @@ -0,0 +1,52 @@ +--TEST-- +libvirt_domain_nic +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + +$mac = '00:11:22:33:44:55'; // Parms for defining a NIC +$network = 'default'; +$model = 'e1000'; + +echo "# libvirt_connect\n"; +var_dump($conn = libvirt_connect('qemu:///session', false)); +if (!is_resource($conn)) + die('Connection to default hypervisor failed. Is libvirt started? What about the QEMU driver?'); + +// libvirt_domain_nic_add needs a persistent guest loaded from a file +$xml = file_get_contents(__DIR__.'/qemu-no-disk-and-media.xml'); +echo "# libvirt_domain_define_xml\n"; +var_dump($dom = libvirt_domain_define_xml($conn, $xml)); +if (!is_resource($dom)) { + die('Domain definition failed with error: '.libvirt_get_last_error()); +} + +echo "# libvirt_domain_nic_add\n"; +// The doc is wrong. It says the function returns a domain resource. +// It actually returns a boolean! +var_dump($ret = libvirt_domain_nic_add($dom, $mac, $network, $model, 0)); +if (!$ret) { + die('Domain nic add failed with error: '.libvirt_get_last_error()); +} + +echo "# libvirt_domain_get_interface_devices\n"; +$info = libvirt_domain_get_interface_devices($dom); +var_dump(is_array($info)); +if (!array_key_exists('num', $info)) + die('libvirt_domain_get_interface_devices: Num element is missing in the output array'); + +unset($conn); + +?> +Done +--EXPECTF-- +# libvirt_connect +resource(%d) of type (Libvirt connection) +# libvirt_domain_define_xml +resource(%d) of type (Libvirt domain) +# libvirt_domain_nic_add +bool(true) +# libvirt_domain_get_interface_devices +bool(true) +Done \ No newline at end of file diff --git a/src/tests/test-logfile.phpt b/src/tests/test-logfile.phpt new file mode 100644 index 0000000..4cfae15 --- /dev/null +++ b/src/tests/test-logfile.phpt @@ -0,0 +1,43 @@ +--TEST-- +libvirt_logfile_set +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php + +$logfile = 'test.log'; +@unlink($logfile); + +echo "# libvirt_logfile_set\n"; +if (!libvirt_logfile_set($logfile, 1)) { + die('Logfile set failed with error: '.libvirt_get_last_error()); +} + +echo "# libvirt_connect\n"; +var_dump($conn = libvirt_connect('test:///default', false)); +if (!is_resource($conn)) { + die('Connection to default hypervisor failed'); +} + +unset($res); +unset($conn); + +$fp = fopen($logfile, 'r'); +$log = fread($fp, filesize($logfile)); +fclose($fp); + +$logok = (strpos($log, 'libvirt_connect: Connection') && + strpos($log, 'libvirt_connection_dtor: virConnectClose')); + +unlink($logfile); + +var_dump($logok); + +?> +Done +--EXPECTF-- +# libvirt_logfile_set +# libvirt_connect +resource(%d) of type (Libvirt connection) +bool(true) +Done -- 2.5.5

--- INSTALL.PHPEXT | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 INSTALL.PHPEXT diff --git a/INSTALL.PHPEXT b/INSTALL.PHPEXT new file mode 100644 index 0000000..e8b6a55 --- /dev/null +++ b/INSTALL.PHPEXT @@ -0,0 +1,14 @@ +Installing using the PHP extension build system +*********************************************** + +libvirt-php supports being built using `phpize`, +a tool that's part of the PHP SDK for building PHP +extensions. + +To build this way, change into the src subdirectory +and run `phpize`. Then run `./configure && make && make install` +to build and install it. Refer to INSTALL for more information +on how to use ./configure. + +The PHP extension build system also has its own tests, +which can be run by doing `make tests`. \ No newline at end of file -- 2.5.5

--- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 51a2cfe..ed3c9d6 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([libvirt-php], [0.5.1], [http://libvirt.org]) +AC_INIT([libvirt-php], [0.5.2], [http://libvirt.org]) AM_INIT_AUTOMAKE([-Wall -Werror -Wno-portability]) AC_CONFIG_FILES([Makefile tools/Makefile src/Makefile tests/Makefile docs/Makefile]) AM_MAINTAINER_MODE([enable]) -- 2.5.5

2016-04-09 1:08 GMT+03:00 Neal Gompa <ngompa13@gmail.com>:
First, I apologize if this was sent twice to anyone. I had an error in my git send-email configuration.
This patch set primarily adds support for PHP 7 to libvirt-php, but also adds the capability for libvirt-php to be built using the standard PHP extension build system method.
Thats fine! -- Vasiliy Tolstov, e-mail: v.tolstov@selfip.ru
participants (3)
-
Michal Privoznik
-
Neal Gompa
-
Vasiliy Tolstov