From: Remi Collet <fedora(a)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 e1a9cef..4fa24d6 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;
@@ -2025,7 +2000,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 \
{ \
@@ -2254,7 +2229,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);
@@ -2357,9 +2332,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;
@@ -2602,14 +2577,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;
@@ -2620,8 +2595,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);
@@ -2649,7 +2624,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;
@@ -2660,8 +2635,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);
@@ -2704,21 +2679,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) {
@@ -2731,21 +2706,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));
@@ -2960,14 +2935,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);
}
/*
@@ -3067,7 +3042,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;
}
}
@@ -3192,7 +3167,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++;
}
}
@@ -4680,12 +4655,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);
}
}
@@ -5242,7 +5217,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);
}
@@ -5340,14 +5315,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);
@@ -6937,8 +6912,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);
@@ -6949,9 +6924,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);
@@ -7036,12 +7011,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/(a)type", dev) < 0)
{
@@ -7051,7 +7026,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);
@@ -7108,7 +7083,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);
}
@@ -9227,18 +9202,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) {
@@ -9246,92 +9221,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);
@@ -9536,42 +9511,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);
@@ -9705,7 +9680,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 105be20..fa2cd2e 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