Move out some macros that are shared between multiple source files into a separate file called util.h. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/Makefile.am | 1 + src/libvirt-php.c | 19 +++++++++++++++++ src/libvirt-php.h | 39 ---------------------------------- src/sockets.c | 1 + src/util.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/vncfunc.c | 1 + 6 files changed, 85 insertions(+), 39 deletions(-) create mode 100644 src/util.h diff --git a/src/Makefile.am b/src/Makefile.am index 68b6371..39a47e9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,6 +18,7 @@ LIBVIRT_PHP_SYMBOL_FILE = \ php_plugindir = $(extensiondir) php_plugin_LTLIBRARIES = libvirt-php.la libvirt_php_la_SOURCES = \ + util.h \ vncfunc.c \ sockets.c \ libvirt-php.c libvirt-php.h diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 6b145de..b9256db 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -27,6 +27,7 @@ #endif #include "libvirt-php.h" +#include "util.h" #ifndef EXTWIN // From vncfunc.c @@ -35,6 +36,10 @@ int vnc_get_dimensions(char *server, char *port, int *width, int *height); int connect_socket(char *server, char *port, int keepalive, int nodelay, int allow_server_override); #endif +#ifdef DEBUG_SUPPORT +int gdebug; +#endif + #ifdef DEBUG_CORE #define DPRINTF(fmt, ...) \ if (LIBVIRT_G(debug)) \ @@ -794,6 +799,20 @@ zend_module_entry libvirt_module_entry = { ZEND_GET_MODULE(libvirt) #endif +ZEND_BEGIN_MODULE_GLOBALS(libvirt) + char *last_error; + char *vnc_location; + zend_bool longlong_to_string_ini; + char *iso_path_ini; + char *image_path_ini; + zend_long max_connections_ini; +#ifdef DEBUG_SUPPORT + int debug; +#endif + resource_info *binding_resources; + int binding_resources_count; +ZEND_END_MODULE_GLOBALS(libvirt) + /* PHP init options */ 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) diff --git a/src/libvirt-php.h b/src/libvirt-php.h index ce885e5..39bd520 100644 --- a/src/libvirt-php.h +++ b/src/libvirt-php.h @@ -17,14 +17,6 @@ #ifndef PHP_LIBVIRT_H #define PHP_LIBVIRT_H 1 -#define DEBUG_SUPPORT - -#ifdef DEBUG_SUPPORT -#define DEBUG_CORE -#define DEBUG_VNC -#endif - -#define ARRAY_CARDINALITY(array) (sizeof(array) / sizeof(array[0])) /* Network constants */ #define VIR_NETWORKS_ACTIVE 1 @@ -151,20 +143,6 @@ typedef struct tTokenizer { int numTokens; } tTokenizer; -#define IS_BIGENDIAN (*(uint16_t *)"\0\xff" < 0x100) - -#define SWAP2_BY_ENDIAN(le, v1, v2) (((le && IS_BIGENDIAN) || (!le && !IS_BIGENDIAN)) ? ((v2 << 8) + v1) : ((v1 << 8) + v2)) -#define PUT2_BYTE_ENDIAN(le, val, v1, v2) { if ((le && IS_BIGENDIAN) || (!le && !IS_BIGENDIAN)) { v2 = val >> 8; v1 = val % 256; } else { v1 = val >> 8; v2 = val % 256; } } -#define SWAP2_BYTES_ENDIAN(le, a, b) { if ((le && IS_BIGENDIAN) || (!le && !IS_BIGENDIAN)) { uint8_t _tmpval; _tmpval = a; a = b; b = _tmpval; } } - -#define UINT32STR(var, val) \ - var[0] = (val >> 24) & 0xff; \ - var[1] = (val >> 16) & 0xff; \ - var[2] = (val >> 8) & 0xff; \ - var[3] = (val ) & 0xff; - -#define GETUINT32(var) (uint32_t)(((uint32_t)var[0] << 24) + ((uint32_t)var[1] << 16) + ((uint32_t)var[2] << 8) + ((uint32_t)var[3])) - typedef struct _resource_info { int type; virConnectPtr conn; @@ -172,20 +150,6 @@ typedef struct _resource_info { int overwrite; } resource_info; -ZEND_BEGIN_MODULE_GLOBALS(libvirt) - char *last_error; - char *vnc_location; - zend_bool longlong_to_string_ini; - char *iso_path_ini; - char *image_path_ini; - zend_long max_connections_ini; -#ifdef DEBUG_SUPPORT - int debug; -#endif - resource_info *binding_resources; - int binding_resources_count; -ZEND_END_MODULE_GLOBALS(libvirt) - #ifdef ZTS #define LIBVIRT_G(v) TSRMG(libvirt_globals_id, zend_libvirt_globals *, v) #else @@ -324,9 +288,6 @@ 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); -#ifdef DEBUG_SUPPORT -int gdebug; -#endif #define PHP_LIBVIRT_CONNECTION_RES_NAME "Libvirt connection" #define PHP_LIBVIRT_DOMAIN_RES_NAME "Libvirt domain" diff --git a/src/sockets.c b/src/sockets.c index 71ceb7b..92ea373 100644 --- a/src/sockets.c +++ b/src/sockets.c @@ -8,6 +8,7 @@ */ #include "libvirt-php.h" +#include "util.h" #ifdef DEBUG_SOCKETS #define DPRINTF(fmt, ...) \ diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..119d573 --- /dev/null +++ b/src/util.h @@ -0,0 +1,63 @@ +/* + * util.h: common, generic utility functions + * + * See COPYING for the license of this software + * + * Written by: + * Michal Privoznik <mprivozn@xxxxxxxxxx> + */ + +#ifndef __UTIL_H__ +# define __UTIL_H__ + +# include <stdint.h> + +# define DEBUG_SUPPORT + +# ifdef DEBUG_SUPPORT +# define DEBUG_CORE +# define DEBUG_VNC +extern int gdebug; +# endif + +# define ARRAY_CARDINALITY(array) (sizeof(array) / sizeof(array[0])) + +# define IS_BIGENDIAN (*(uint16_t *)"\0\xff" < 0x100) + +# define SWAP2_BY_ENDIAN(le, v1, v2) \ + (((le && IS_BIGENDIAN) || (!le && !IS_BIGENDIAN)) ? ((v2 << 8) + v1) : ((v1 << 8) + v2)) + +# define PUT2_BYTE_ENDIAN(le, val, v1, v2) \ + do { \ + if ((le && IS_BIGENDIAN) || (!le && !IS_BIGENDIAN)) { \ + v2 = val >> 8; \ + v1 = val % 256; \ + } else { \ + v1 = val >> 8; \ + v2 = val % 256; \ + } \ + } while (0) + +# define SWAP2_BYTES_ENDIAN(le, a, b) \ + do { \ + if ((le && IS_BIGENDIAN) || (!le && !IS_BIGENDIAN)) { \ + uint8_t _tmpval; \ + _tmpval = a; \ + a = b; \ + b = _tmpval; \ + } \ + } while (0) + +# define UINT32STR(var, val) \ + var[0] = (val >> 24) & 0xff; \ + var[1] = (val >> 16) & 0xff; \ + var[2] = (val >> 8) & 0xff; \ + var[3] = (val ) & 0xff; + +# define GETUINT32(var) \ + (uint32_t)(((uint32_t)var[0] << 24) + \ + ((uint32_t)var[1] << 16) + \ + ((uint32_t)var[2] << 8) + \ + ((uint32_t)var[3])) + +#endif /* __UTIL_H__ */ diff --git a/src/vncfunc.c b/src/vncfunc.c index 6e2f220..393624f 100644 --- a/src/vncfunc.c +++ b/src/vncfunc.c @@ -8,6 +8,7 @@ */ #include "libvirt-php.h" +#include "util.h" #ifdef DEBUG_VNC #define DPRINTF(fmt, ...) \ -- 2.8.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list