Also util now includes all the PHP headers.
---
src/libvirt-php.c | 1 -
src/libvirt-php.h | 157 +-----------------------------------------------
src/util.h | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 175 insertions(+), 157 deletions(-)
diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index 0e0c620..504a8f2 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -17,7 +17,6 @@
#endif
#include "libvirt-php.h"
-#include "util.h"
#include "vncfunc.h"
#include "sockets.h"
diff --git a/src/libvirt-php.h b/src/libvirt-php.h
index bfc1934..aa3fbf3 100644
--- a/src/libvirt-php.h
+++ b/src/libvirt-php.h
@@ -7,7 +7,6 @@
#ifndef PHP_LIBVIRT_H
#define PHP_LIBVIRT_H 1
-
/* Network constants */
#define VIR_NETWORKS_ACTIVE 1
#define VIR_NETWORKS_INACTIVE 2
@@ -28,27 +27,6 @@
#include "config.h"
#endif
-#ifdef COMPILE_DL_LIBVIRT
-#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"
-#endif
-
-#include "php_ini.h"
-#ifdef EXTWIN
-#include "ext/standard/info.h"
-#else
-#include "standard/info.h"
-#endif
-#endif
-
#ifndef VERSION
#define VERSION "0.5.1"
#define VERSION_MAJOR 0
@@ -63,6 +41,7 @@
#include <libxml/xpath.h>
#include <fcntl.h>
#include <sys/types.h>
+#include "util.h"
#ifndef EXTWIN
#include <inttypes.h>
@@ -109,139 +88,6 @@ typedef uint64_t arch_uint;
#define UINTx PRIx64
#endif
-#if PHP_MAJOR_VERSION >= 7
-typedef size_t strsize_t;
-typedef zend_resource virt_resource;
-typedef virt_resource *virt_resource_handle;
-
-#define VIRT_RETURN_RESOURCE(_resource) \
- RETVAL_RES(_resource)
-
-#define VIRT_REGISTER_RESOURCE(_resource, _le_resource) \
- VIRT_RETURN_RESOURCE(zend_register_resource(_resource, _le_resource))
-
-#define VIRT_REGISTER_LIST_RESOURCE(_name) do { \
- zval zret; \
- ZVAL_RES(&zret, zend_register_resource(res_##_name, le_libvirt_##_name)); \
- add_next_index_zval(return_value, &zret); \
- } while(0)
-
-#define VIRT_RESOURCE_HANDLE(_resource) \
- Z_RES_P(_resource)
-
-#define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \
- if ((_state = (_type)zend_fetch_resource(Z_RES_P(*_zval), _name, _le)) == NULL) { \
- RETURN_FALSE; \
- }
-
-#define VIRT_RETVAL_STRING(_str) \
- RETVAL_STRING(_str)
-#define VIRT_RETVAL_STRINGL(_str, _len) \
- RETVAL_STRINGL(_str, _len)
-#define VIRT_RETURN_STRING(_str) \
- RETURN_STRING(_str)
-#define VIRT_RETURN_STRINGL(_str, _len) \
- RETURN_STRINGL(_str, _len)
-#define VIRT_ZVAL_STRINGL(_zv, _str, _len) \
- ZVAL_STRINGL(_zv, _str, _len)
-#define VIRT_ADD_INDEX_STRING(_arg, _idx, _str) \
- add_index_string(_arg, _idx, _str)
-#define VIRT_ADD_NEXT_INDEX_STRING(_arg, _str) \
- add_next_index_string(_arg, _str)
-#define VIRT_ADD_ASSOC_STRING(_arg, _key, _str) \
- add_assoc_string(_arg, _key, _str)
-#define VIRT_ADD_ASSOC_STRING_EX(_arg, _key, _key_len, _value) \
- add_assoc_string_ex(_arg, _key, _key_len, _value)
-
-#define VIRT_FOREACH(_ht, _pos, _zv) \
- for (zend_hash_internal_pointer_reset_ex(_ht, &_pos); \
- (_zv = zend_hash_get_current_data_ex(_ht, &_pos)) != NULL; \
- zend_hash_move_forward_ex(_ht, &_pos)) \
-
-#define VIRT_FOREACH_END(_dummy)
-
-#define VIRT_HASH_CURRENT_KEY_INFO(_ht, _pos, _idx, _info) \
- do { \
- zend_string *tmp_key_info; \
- _info.type = zend_hash_get_current_key_ex(_ht, &tmp_key_info, &_idx,
&_pos); \
- _info.name = ZSTR_VAL(tmp_key_info); \
- _info.length = ZSTR_LEN(tmp_key_info); \
- } while(0)
-
-#define VIRT_ARRAY_INIT(_name) do { \
- zval z##_name; \
- _name = &z##_name; \
- array_init(_name); \
- } while(0)
-
-#else /* PHP_MAJOR_VERSION < 7 */
-typedef int strsize_t;
-typedef long zend_long;
-typedef unsigned long zend_ulong;
-typedef zend_rsrc_list_entry virt_resource;
-typedef long virt_resource_handle;
-
-#define VIRT_RETURN_RESOURCE(_resource) \
- RETVAL_RESOURCE((long) _resource)
-
-#define VIRT_REGISTER_RESOURCE(_resource, _le_resource) \
- ZEND_REGISTER_RESOURCE(return_value, _resource, _le_resource)
-
-#define VIRT_REGISTER_LIST_RESOURCE(_name) do { \
- zval *zret; \
- ALLOC_INIT_ZVAL(zret); \
- ZEND_REGISTER_RESOURCE(zret, res_##_name, le_libvirt_##_name); \
- add_next_index_zval(return_value, zret); \
- } while(0)
-
-#define VIRT_RESOURCE_HANDLE(_resource) \
- Z_LVAL_P(_resource)
-
-#define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \
- ZEND_FETCH_RESOURCE(_state, _type, _zval, -1, _name, _le);
-
-#define VIRT_RETVAL_STRING(_str) \
- RETVAL_STRING(_str, 1)
-#define VIRT_RETVAL_STRINGL(_str, _len) \
- RETVAL_STRINGL(_str, _len, 1)
-#define VIRT_RETURN_STRING(_str) \
- RETURN_STRING(_str, 1)
-#define VIRT_RETURN_STRINGL(_str, _len) \
- RETURN_STRINGL(_str, _len, 1)
-#define VIRT_ZVAL_STRINGL(_zv, _str, _len) \
- ZVAL_STRINGL(_zv, _str, _len, 1)
-#define VIRT_ADD_INDEX_STRING(_arg, _idx, _str) \
- add_index_string(_arg, _idx, _str, 1)
-#define VIRT_ADD_NEXT_INDEX_STRING(_arg, _str) \
- add_next_index_string(_arg, _str, 1)
-#define VIRT_ADD_ASSOC_STRING(_arg, _key, _str) \
- add_assoc_string(_arg, _key, _str, 1)
-#define VIRT_ADD_ASSOC_STRING_EX(_arg, _key, _key_len, _value) \
- add_assoc_string_ex(_arg, _key, _key_len, _value, 1)
-
-#define VIRT_FOREACH(_ht, _pos, _zv) \
- { \
- zval **pzv = &_zv; \
- for (zend_hash_internal_pointer_reset_ex(_ht, &_pos); \
- zend_hash_get_current_data_ex(_ht, (void **) &pzv, &_pos) == SUCCESS; \
- zend_hash_move_forward_ex(_ht, &_pos)) { \
- _zv = *pzv;
-
-#define VIRT_FOREACH_END(_dummy) \
- }}
-
-#define VIRT_HASH_CURRENT_KEY_INFO(_ht, _pos, _idx, _info) \
- do { \
- _info.type = zend_hash_get_current_key_ex(_ht, &_info.name, &_info.length,
&_idx, 0, &_pos); \
- } while(0)
-
-#define VIRT_ARRAY_INIT(_name) do {\
- ALLOC_INIT_ZVAL(_name); \
- array_init(_name); \
- } while(0)
-
-#endif /* PHP_MAJOR_VERSION < 7 */
-
typedef struct tTokenizer {
char **tokens;
int numTokens;
@@ -366,7 +212,6 @@ typedef struct _php_libvirt_hash_key_info {
/* Private definitions */
int set_logfile(char *filename, long maxsize TSRMLS_DC);
-char *get_datetime(void);
char *get_string_from_xpath(char *xml, char *xpath, zval **val, int *retVal);
char **get_array_from_xpath(char *xml, char *xpath, int *num);
diff --git a/src/util.h b/src/util.h
index 836b13f..949dea3 100644
--- a/src/util.h
+++ b/src/util.h
@@ -9,6 +9,27 @@
# include <stdint.h>
+# ifdef COMPILE_DL_LIBVIRT
+# 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>
+# endif
+
+# include <php_ini.h>
+# ifdef EXTWIN
+# include <ext/standard/info.h>
+# else
+# include <standard/info.h>
+# endif
+#endif
+
# define DEBUG_SUPPORT
# ifdef DEBUG_SUPPORT
@@ -62,6 +83,159 @@
((uint32_t)var[2] << 8) + \
((uint32_t)var[3]))
+# if PHP_MAJOR_VERSION >= 7
+ typedef size_t strsize_t;
+ typedef zend_resource virt_resource;
+ typedef virt_resource *virt_resource_handle;
+
+# define VIRT_RETURN_RESOURCE(_resource) \
+ RETVAL_RES(_resource)
+
+# define VIRT_REGISTER_RESOURCE(_resource, _le_resource) \
+ VIRT_RETURN_RESOURCE(zend_register_resource(_resource, _le_resource))
+
+# define VIRT_REGISTER_LIST_RESOURCE(_name) do { \
+ zval zret; \
+ ZVAL_RES(&zret, zend_register_resource(res_##_name, le_libvirt_##_name)); \
+ add_next_index_zval(return_value, &zret); \
+ } while(0)
+
+# define VIRT_RESOURCE_HANDLE(_resource) \
+ Z_RES_P(_resource)
+
+# define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \
+ if ((_state = (_type)zend_fetch_resource(Z_RES_P(*_zval), _name, _le)) == NULL) { \
+ RETURN_FALSE; \
+ }
+
+# define VIRT_RETVAL_STRING(_str) \
+ RETVAL_STRING(_str)
+
+# define VIRT_RETVAL_STRINGL(_str, _len) \
+ RETVAL_STRINGL(_str, _len)
+
+# define VIRT_RETURN_STRING(_str) \
+ RETURN_STRING(_str)
+
+# define VIRT_RETURN_STRINGL(_str, _len) \
+ RETURN_STRINGL(_str, _len)
+
+# define VIRT_ZVAL_STRINGL(_zv, _str, _len) \
+ ZVAL_STRINGL(_zv, _str, _len)
+
+# define VIRT_ADD_INDEX_STRING(_arg, _idx, _str) \
+ add_index_string(_arg, _idx, _str)
+
+# define VIRT_ADD_NEXT_INDEX_STRING(_arg, _str) \
+ add_next_index_string(_arg, _str)
+
+# define VIRT_ADD_ASSOC_STRING(_arg, _key, _str) \
+ add_assoc_string(_arg, _key, _str)
+
+# define VIRT_ADD_ASSOC_STRING_EX(_arg, _key, _key_len, _value) \
+ add_assoc_string_ex(_arg, _key, _key_len, _value)
+
+# define VIRT_FOREACH(_ht, _pos, _zv) \
+ for (zend_hash_internal_pointer_reset_ex(_ht, &_pos); \
+ (_zv = zend_hash_get_current_data_ex(_ht, &_pos)) != NULL; \
+ zend_hash_move_forward_ex(_ht, &_pos)) \
+
+# define VIRT_FOREACH_END(_dummy)
+
+# define VIRT_HASH_CURRENT_KEY_INFO(_ht, _pos, _idx, _info) \
+ do { \
+ zend_string *tmp_key_info; \
+ _info.type = zend_hash_get_current_key_ex(_ht, &tmp_key_info, &_idx,
&_pos); \
+ _info.name = ZSTR_VAL(tmp_key_info); \
+ _info.length = ZSTR_LEN(tmp_key_info); \
+ } while(0)
+
+# define VIRT_ARRAY_INIT(_name) do { \
+ zval z##_name; \
+ _name = &z##_name; \
+ array_init(_name); \
+ } while(0)
+
+# else /* PHP_MAJOR_VERSION < 7 */
+ typedef int strsize_t;
+ typedef long zend_long;
+ typedef unsigned long zend_ulong;
+ typedef zend_rsrc_list_entry virt_resource;
+ typedef long virt_resource_handle;
+
+# define VIRT_RETURN_RESOURCE(_resource) \
+ RETVAL_RESOURCE((long) _resource)
+
+# define VIRT_REGISTER_RESOURCE(_resource, _le_resource) \
+ ZEND_REGISTER_RESOURCE(return_value, _resource, _le_resource)
+
+# define VIRT_REGISTER_LIST_RESOURCE(_name) do { \
+ zval *zret; \
+ ALLOC_INIT_ZVAL(zret); \
+ ZEND_REGISTER_RESOURCE(zret, res_##_name, le_libvirt_##_name); \
+ add_next_index_zval(return_value, zret); \
+ } while(0)
+
+# define VIRT_RESOURCE_HANDLE(_resource) \
+ Z_LVAL_P(_resource)
+
+# define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \
+ ZEND_FETCH_RESOURCE(_state, _type, _zval, -1, _name, _le);
+
+# define VIRT_RETVAL_STRING(_str) \
+ RETVAL_STRING(_str, 1)
+
+# define VIRT_RETVAL_STRINGL(_str, _len) \
+ RETVAL_STRINGL(_str, _len, 1)
+
+# define VIRT_RETURN_STRING(_str) \
+ RETURN_STRING(_str, 1)
+
+# define VIRT_RETURN_STRINGL(_str, _len) \
+ RETURN_STRINGL(_str, _len, 1)
+
+# define VIRT_ZVAL_STRINGL(_zv, _str, _len) \
+ ZVAL_STRINGL(_zv, _str, _len, 1)
+
+# define VIRT_ADD_INDEX_STRING(_arg, _idx, _str) \
+ add_index_string(_arg, _idx, _str, 1)
+
+# define VIRT_ADD_NEXT_INDEX_STRING(_arg, _str) \
+ add_next_index_string(_arg, _str, 1)
+
+# define VIRT_ADD_ASSOC_STRING(_arg, _key, _str) \
+ add_assoc_string(_arg, _key, _str, 1)
+
+# define VIRT_ADD_ASSOC_STRING_EX(_arg, _key, _key_len, _value) \
+ add_assoc_string_ex(_arg, _key, _key_len, _value, 1)
+
+# define VIRT_FOREACH(_ht, _pos, _zv) \
+ { \
+ zval **pzv = &_zv; \
+ for (zend_hash_internal_pointer_reset_ex(_ht, &_pos); \
+ zend_hash_get_current_data_ex(_ht, (void **) &pzv, &_pos) == SUCCESS; \
+ zend_hash_move_forward_ex(_ht, &_pos)) { \
+ _zv = *pzv;
+
+# define VIRT_FOREACH_END(_dummy) \
+ }}
+
+# define VIRT_HASH_CURRENT_KEY_INFO(_ht, _pos, _idx, _info) \
+ do { \
+ _info.type = zend_hash_get_current_key_ex(_ht, &_info.name, &_info.length,
&_idx, 0, &_pos); \
+ } while(0)
+
+# define VIRT_ARRAY_INIT(_name) do {\
+ ALLOC_INIT_ZVAL(_name); \
+ array_init(_name); \
+ } while(0)
+
+# endif /* PHP_MAJOR_VERSION < 7 */
+
+# ifndef PHP_FE_END
+# define PHP_FE_END {NULL, NULL, NULL}
+# endif
+
void debugPrint(const char *source,
const char *fmt, ...);
--
2.13.3