* add libvirt_list_active_storagepools&
libvirt_list_inactive_storagepools
* modified EXTRA_DIST for necessary files
* generate libvirt-php.spec from .in file
* bug fix for memeory leak
---
Makefile.am | 2 +-
configure.ac | 1 +
libvirt-php.spec | 82 --------------------------
libvirt-php.spec.in | 82 ++++++++++++++++++++++++++
src/Makefile.am | 2 +-
src/libvirt.c | 159 ++++++++++++++++++++++++++++++++++++++++++++++----
src/libvirt_php.h | 2 +
tools/Makefile.am | 2 +
8 files changed, 235 insertions(+), 97 deletions(-)
delete mode 100644 libvirt-php.spec
create mode 100644 libvirt-php.spec.in
diff --git a/Makefile.am b/Makefile.am
index 2e73743..45f396b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,3 +1,3 @@
SUBDIRS = tools src docs
-EXTRA_DIST = libvirt-php.spec
+EXTRA_DIST = libvirt-php.spec.in
diff --git a/configure.ac b/configure.ac
index f79317d..8d81b9d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -110,4 +110,5 @@ fi
AC_SUBST([PHPIZE])
AC_SUBST([PHPCONFIG])
AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_FILES([$PACKAGE.spec])
AC_OUTPUT
diff --git a/libvirt-php.spec b/libvirt-php.spec
deleted file mode 100644
index 51a9add..0000000
--- a/libvirt-php.spec
+++ /dev/null
@@ -1,82 +0,0 @@
-%define req_libvirt_version 0.6.2
-
-%if 0%{?suse_version}
-%define php_confdir %{_sysconfdir}/php5/conf.d
-%define php_extdir %{_libdir}/php5/extensions
-%else
-%define php_confdir %{_sysconfdir}/php.d
-%define php_extdir %{_libdir}/php/modules
-%endif
-
-Name: libvirt-php
-Version: 0.4
-Release: 1%{?dist}%{?extra_release}
-Summary: PHP language binding for Libvirt
-
-%if 0%{?suse_version}
-Group: Development/Libraries/PHP
-%else
-Group: Development/Libraries
-%endif
-License: PHP
-URL:
http://libvirt.org/
-Source0:
http://libvirt.org/sources/libvirt-php-%{version}.tar.gz
-BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
-
-BuildRequires: php-devel
-BuildRequires: libvirt-devel>= %{req_libvirt_version}
-BuildRequires: libxml2-devel
-%if 0%{?suse_version}
-BuildRequires: xhtml-dtd
-%else
-BuildRequires: xhtml1-dtds
-%endif
-Requires: libvirt>= %{req_libvirt_version}
-%if 0%{?suse_version}
-Requires: php5
-%else
-Requires: php
-%endif
-
-%description
-PHP language bindings for Libvirt API.
-For more details see:
http://phplibvirt.cybersales.cz/ http://www.libvirt.org/
http://www.php.net/
-
-%package -n libvirt-php-doc
-Summary: Document of libvirt-php
-Group: Development/Libraries/PHP
-Requires: libvirt-php = %{version}
-
-%description -n libvirt-php-doc
-PHP language bindings for Libvirt API.
-For more details see:
http://phplibvirt.cybersales.cz/ http://www.libvirt.org/
http://www.php.net/
-
-This package contain the document for libvirt-php.
-
-%prep
-%setup -q -n libvirt-php-%{version}
-
-%build
-%configure
-./configure --with-html-dir=%{_datadir}/doc --with-html-subdir=%{name}-%{version}/html
-make %{?_smp_mflags}
-
-%install
-make install DESTDIR=%{buildroot}
-
-%clean
-rm -rf %{buildroot}
-
-%files
-%defattr(-,root,root,-)
-%{php_extdir}/libvirt-php.so
-%config(noreplace) %{php_confdir}/libvirt-php.ini
-
-%files -n libvirt-php-doc
-%defattr(-,root,root,-)
-%doc
-%dir %{_datadir}/doc/%{name}-%{version}
-%{_datadir}/doc/%{name}-%{version}/html
-
-%changelog
-
diff --git a/libvirt-php.spec.in b/libvirt-php.spec.in
new file mode 100644
index 0000000..465532c
--- /dev/null
+++ b/libvirt-php.spec.in
@@ -0,0 +1,82 @@
+%define req_libvirt_version 0.6.2
+
+%if 0%{?suse_version}
+%define php_confdir %{_sysconfdir}/php5/conf.d
+%define php_extdir %{_libdir}/php5/extensions
+%else
+%define php_confdir %{_sysconfdir}/php.d
+%define php_extdir %{_libdir}/php/modules
+%endif
+
+Name: @PACKAGE@
+Version: @VERSION@
+Release: 1%{?dist}%{?extra_release}
+Summary: PHP language binding for Libvirt
+
+%if 0%{?suse_version}
+Group: Development/Libraries/PHP
+%else
+Group: Development/Libraries
+%endif
+License: PHP
+URL:
http://libvirt.org/
+Source0:
http://libvirt.org/sources/libvirt-php-%{version}.tar.gz
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
+
+BuildRequires: php-devel
+BuildRequires: libvirt-devel>= %{req_libvirt_version}
+BuildRequires: libxml2-devel
+%if 0%{?suse_version}
+BuildRequires: xhtml-dtd
+%else
+BuildRequires: xhtml1-dtds
+%endif
+Requires: libvirt>= %{req_libvirt_version}
+%if 0%{?suse_version}
+Requires: php5
+%else
+Requires: php
+%endif
+
+%description
+PHP language bindings for Libvirt API.
+For more details see:
http://phplibvirt.cybersales.cz/ http://www.libvirt.org/
http://www.php.net/
+
+%package -n libvirt-php-doc
+Summary: Document of libvirt-php
+Group: Development/Libraries/PHP
+Requires: libvirt-php = %{version}
+
+%description -n libvirt-php-doc
+PHP language bindings for Libvirt API.
+For more details see:
http://phplibvirt.cybersales.cz/ http://www.libvirt.org/
http://www.php.net/
+
+This package contain the document for libvirt-php.
+
+%prep
+%setup -q -n libvirt-php-%{version}
+
+%build
+%configure
+./configure --with-html-dir=%{_datadir}/doc --with-html-subdir=%{name}-%{version}/html
+make %{?_smp_mflags}
+
+%install
+make install DESTDIR=%{buildroot}
+
+%clean
+rm -rf %{buildroot}
+
+%files
+%defattr(-,root,root,-)
+%{php_extdir}/libvirt-php.so
+%config(noreplace) %{php_confdir}/libvirt-php.ini
+
+%files -n libvirt-php-doc
+%defattr(-,root,root,-)
+%doc
+%dir %{_datadir}/doc/%{name}-%{version}
+%{_datadir}/doc/%{name}-%{version}/html
+
+%changelog
+
diff --git a/src/Makefile.am b/src/Makefile.am
index d301ae2..9c7101d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,7 +3,7 @@ PHPEDIR=$(shell php-config --extension-dir)
PHPCDIR=$(shell php-config --configure-options | sed -n
's|.*--with-config-file-scan-dir=\([^ ]*\).*|\1|p')
DEFINES=-DHAVE_CONFIG_H
-EXTRA_DIST = libvirt.c php_libvirt.h
+EXTRA_DIST = libvirt.c libvirt_php.h
all-am: build clean-temp
diff --git a/src/libvirt.c b/src/libvirt.c
index 9293224..230aff2 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -109,6 +109,8 @@ static function_entry libvirt_functions[] = {
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)
@@ -1994,10 +1996,11 @@ PHP_FUNCTION(libvirt_storagepool_get_info)
array_init(return_value);
// @todo: fix the long long returns
+ LONGLONG_INIT
add_assoc_long(return_value, "state", (long)poolInfo.state);
- add_assoc_long(return_value, "capacity", poolInfo.capacity);
- add_assoc_long(return_value, "allocation", poolInfo.allocation);
- add_assoc_long(return_value, "available", poolInfo.available);
+ LONGLONG_ASSOC(return_value, "capacity", poolInfo.capacity);
+ LONGLONG_ASSOC(return_value, "allocation", poolInfo.allocation);
+ LONGLONG_ASSOC(return_value, "available", poolInfo.available);
}
/*
@@ -2426,18 +2429,110 @@ PHP_FUNCTION(libvirt_list_storagepools)
names=emalloc(expectedcount*sizeof(char *));
count=virConnectListStoragePools(conn->conn,names,expectedcount);
- if ((count != expectedcount) || (count<0)) RETURN_FALSE;
+ if ((count != expectedcount) || (count<0))
+ {
+ efree (names);
+ RETURN_FALSE;
+ }
+
array_init(return_value);
for (i=0;i<count;i++)
{
add_next_index_string(return_value, names[i],1);
free(names[i]);
}
+ efree(names);
+
+
+ expectedcount = virConnectNumOfDefinedStoragePools (conn->conn);
+ names= emalloc (expectedcount * sizeof(char *));
+ count = virConnectListDefinedStoragePools (conn->conn, names, expectedcount);
+ if ((count != expectedcount) || (count< 0))
+ {
+ efree (names);
+ RETURN_FALSE;
+ }
+
+ for (i = 0; i< count; i++)
+ {
+ add_next_index_string (return_value, names[i], 1);
+ free (names[i]);
+ }
+ efree (names);
+}
+/*
+ Function name: libvirt_list_active_storagepools
+ Description: Function is used to list active storage pools on the connection
+ Arguments: @res [resource]: libvirt connection resource
+ Returns: libvirt storagepool names array for the connection
+*/
+PHP_FUNCTION(libvirt_list_active_storagepools)
+{
+ php_libvirt_connection *conn=NULL;
+ zval *zconn;
+ int count=-1;
+ int expectedcount=-1;
+ char **names;
+ int i;
+
+ GET_CONNECTION_FROM_ARGS("r",&zconn);
+
+ expectedcount=virConnectNumOfStoragePools(conn->conn);
+
+ names=emalloc(expectedcount*sizeof(char *));
+ count=virConnectListStoragePools(conn->conn,names,expectedcount);
+
+ if ((count != expectedcount) || (count<0))
+ {
+ efree (names);
+ RETURN_FALSE;
+ }
+ array_init(return_value);
+ for (i=0;i<count;i++)
+ {
+ add_next_index_string(return_value, names[i],1);
+ free(names[i]);
+ }
efree(names);
}
/*
+ Function name: libvirt_list_inactive_storagepools
+ Description: Function is used to list inactive storage pools on the connection
+ Arguments: @res [resource]: libvirt connection resource
+ Returns: libvirt storagepool names array for the connection
+*/
+PHP_FUNCTION(libvirt_list_inactive_storagepools)
+{
+ php_libvirt_connection *conn=NULL;
+ zval *zconn;
+ int count=-1;
+ int expectedcount=-1;
+ char **names;
+ int i;
+
+ GET_CONNECTION_FROM_ARGS("r",&zconn);
+
+ expectedcount = virConnectNumOfDefinedStoragePools (conn->conn);
+ names= emalloc (expectedcount * sizeof(char *));
+ count = virConnectListDefinedStoragePools (conn->conn, names, expectedcount);
+ if ((count != expectedcount) || (count< 0))
+ {
+ efree (names);
+ RETURN_FALSE;
+ }
+
+ array_init(return_value);
+ for (i = 0; i< count; i++)
+ {
+ add_next_index_string (return_value, names[i], 1);
+ free (names[i]);
+ }
+ efree (names);
+}
+
+/*
Function name: libvirt_list_domains
Description: Function is used to list domains on the connection
Arguments: @res [resource]: libvirt connection resource
@@ -2513,7 +2608,11 @@ PHP_FUNCTION(libvirt_list_domain_resources)
ids=emalloc(sizeof(int)*expectedcount);
count=virConnectListDomains (conn->conn,ids,expectedcount);
- if ((count != expectedcount) || (count<0)) RETURN_FALSE;
+ if ((count != expectedcount) || (count<0))
+ {
+ efree (ids);
+ RETURN_FALSE;
+ }
array_init(return_value);
for (i=0;i<count;i++)
{
@@ -2535,7 +2634,11 @@ PHP_FUNCTION(libvirt_list_domain_resources)
expectedcount=virConnectNumOfDefinedDomains (conn->conn);
names=emalloc(expectedcount*sizeof(char *));
count=virConnectListDefinedDomains (conn->conn,names ,expectedcount);
- if ((count != expectedcount) || (count<0)) RETURN_FALSE;
+ if ((count != expectedcount) || (count<0))
+ {
+ efree (names);
+ RETURN_FALSE;
+ }
for (i=0;i<count;i++)
{
domain=virDomainLookupByName (conn->conn,names[i]);
@@ -2576,7 +2679,11 @@ PHP_FUNCTION(libvirt_list_active_domain_ids)
ids=emalloc(sizeof(int)*expectedcount);
count=virConnectListDomains (conn->conn,ids,expectedcount);
- if ((count != expectedcount) || (count<0)) RETURN_FALSE;
+ if ((count != expectedcount) || (count<0))
+ {
+ efree (ids);
+ RETURN_FALSE;
+ }
array_init(return_value);
for (i=0;i<count;i++)
{
@@ -2608,7 +2715,12 @@ PHP_FUNCTION(libvirt_list_active_domains)
ids=emalloc(sizeof(int)*expectedcount);
count=virConnectListDomains (conn->conn,ids,expectedcount);
- if ((count != expectedcount) || (count<0)) RETURN_FALSE;
+ if ((count != expectedcount) || (count<0))
+ {
+ efree (ids);
+ RETURN_FALSE;
+ }
+
array_init(return_value);
for (i=0;i<count;i++)
{
@@ -2616,7 +2728,12 @@ PHP_FUNCTION(libvirt_list_active_domains)
if (domain!=NULL)
{
name=virDomainGetName(domain);
- if (name==NULL) RETURN_FALSE;
+ if (name==NULL)
+ {
+ efree (ids);
+ RETURN_FALSE;
+ }
+
add_next_index_string(return_value, name, 1);
}
}
@@ -2645,7 +2762,11 @@ PHP_FUNCTION(libvirt_list_inactive_domains)
names=emalloc(expectedcount*sizeof(char *));
count=virConnectListDefinedDomains (conn->conn,names ,expectedcount);
- if ((count != expectedcount) || (count<0)) RETURN_FALSE;
+ if ((count != expectedcount) || (count<0))
+ {
+ efree (names);
+ RETURN_FALSE;
+ }
for (i=0;i<count;i++)
{
add_next_index_string(return_value, names[i],1);
@@ -2678,7 +2799,11 @@ PHP_FUNCTION(libvirt_list_networks)
expectedcount=virConnectNumOfNetworks(conn->conn);
names=emalloc(expectedcount*sizeof(char *));
count=virConnectListNetworks(conn->conn,names,expectedcount);
- if ((count != expectedcount) || (count<0)) RETURN_FALSE;
+ if ((count != expectedcount) || (count<0))
+ {
+ efree (names);
+ RETURN_FALSE;
+ }
for (i=0;i<count;i++)
{
@@ -2694,7 +2819,11 @@ PHP_FUNCTION(libvirt_list_networks)
expectedcount=virConnectNumOfDefinedNetworks(conn->conn);
names=emalloc(expectedcount*sizeof(char *));
count=virConnectListDefinedNetworks(conn->conn,names,expectedcount);
- if ((count != expectedcount) || (count<0)) RETURN_FALSE;
+ if ((count != expectedcount) || (count<0))
+ {
+ efree (names);
+ RETURN_FALSE;
+ }
for (i=0;i<count;i++)
{
@@ -2732,7 +2861,11 @@ PHP_FUNCTION(libvirt_list_nodedevs)
expectedcount=virNodeNumOfDevices(conn->conn, cap, 0);
names=emalloc(expectedcount*sizeof(char *));
count=virNodeListDevices(conn->conn, cap, names, expectedcount, 0);
- if ((count != expectedcount) || (count<0)) RETURN_FALSE;
+ if ((count != expectedcount) || (count<0))
+ {
+ efree (names);
+ RETURN_FALSE;
+ }
array_init(return_value);
for (i=0;i<count;i++)
diff --git a/src/libvirt_php.h b/src/libvirt_php.h
index 8667217..3cdc305 100644
--- a/src/libvirt_php.h
+++ b/src/libvirt_php.h
@@ -168,6 +168,8 @@ PHP_FUNCTION(libvirt_list_active_domains);
PHP_FUNCTION(libvirt_list_active_domain_ids);
PHP_FUNCTION(libvirt_list_inactive_domains);
PHP_FUNCTION(libvirt_list_storagepools);
+PHP_FUNCTION(libvirt_list_active_storagepools);
+PHP_FUNCTION(libvirt_list_inactive_storagepools);
PHP_FUNCTION(libvirt_version);
PHP_FUNCTION(libvirt_check_version);
diff --git a/tools/Makefile.am b/tools/Makefile.am
index b334717..e508371 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,3 +1,5 @@
+EXTRA_DIST = generate-api-docs.c
+
all-am:
$(CC) -Wall -o generate-api-docs generate-api-docs.c
./generate-api-docs ../src/libvirt.c ../docs/api-reference.html.in
--
Michal Novotny<minovotn(a)redhat.com>, RHCE
Virtualization Team (xen userspace), Red Hat