On 13.04.2016 18:13, Neal Gompa wrote:
From: Remi Collet <fedora(a)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 3603392..3f47075 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;
@@ -1946,7 +1957,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, ...) \
@@ -1956,7 +1967,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, ...) \
@@ -1966,7 +1977,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, ...) \
@@ -1976,7 +1987,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, ...) \
@@ -1986,7 +1997,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, ...) \
@@ -1996,7 +2007,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, ...) \
@@ -2006,7 +2017,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 \
@@ -2100,7 +2111,7 @@ PHP_FUNCTION(libvirt_connect)
php_libvirt_connection *conn;
php_libvirt_cred_value *creds=NULL;
zval* zcreds=NULL;
- zval **data;
+ zval *data;
So @data is now a single pointer ...
int i;
int j;
int credscount=0;
@@ -2115,9 +2126,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;
@@ -2162,9 +2171,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) {
.. but _PP says it's a double pointer. The !PHP7 code needs to be
updated too.
+ 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 {
Michal