diff options
author | James Moore <jmoore@php.net> | 2002-11-12 14:29:42 +0000 |
---|---|---|
committer | James Moore <jmoore@php.net> | 2002-11-12 14:29:42 +0000 |
commit | 41114c05fe2b34f763d7da14b29c0b1c6aacb7fb (patch) | |
tree | c6b2130e0002ad7970ddc55a6e15c54191874bd6 /ext/w32api/php_w32api.h | |
parent | 1a3e0f04871c2c396568d2e7272c93dc0bba7af0 (diff) | |
download | php-git-41114c05fe2b34f763d7da14b29c0b1c6aacb7fb.tar.gz |
Rewrite of the W32api extension
@ New version of w32api extension. Old API deprecated (jmoore)
Diffstat (limited to 'ext/w32api/php_w32api.h')
-rw-r--r-- | ext/w32api/php_w32api.h | 404 |
1 files changed, 306 insertions, 98 deletions
diff --git a/ext/w32api/php_w32api.h b/ext/w32api/php_w32api.h index cbe52234ea..05a353265f 100644 --- a/ext/w32api/php_w32api.h +++ b/ext/w32api/php_w32api.h @@ -1,8 +1,8 @@ /* +----------------------------------------------------------------------+ - | PHP Version 4 | + | PHP version 4.0 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2002 The PHP Group | + | Copyright (c) 1997-2001 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -12,126 +12,334 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: James Moore <jmoore@php.net> | + | Authors: James Moore <jmoore@php.net> | +----------------------------------------------------------------------+ - */ +*/ - /* $Id$ */ +/* $Id$ */ -#if HAVE_W32API +#if HAVE_W32API #ifndef PHP_W32API_H #define PHP_W32API_H +/* ================================================================================================ + * Type Definitions + * ================================================================================================ + */ +typedef struct _w32api_lib_handle w32api_lib_handle; +typedef struct _w32api_func_handle w32api_func_handle; +typedef struct _w32api_type_handle w32api_type_handle; +typedef struct _w32api_type_instance w32api_type_instance; +typedef struct _arguments arguments; +typedef struct _argument argument; +typedef union _w32api_parser_function_definition_union w32api_parser_function_definition_union; +typedef struct _w32api_func_handle_ptr w32api_func_handle_ptr; +typedef struct _w32api_type_handle_ptr w32api_type_handle_ptr; +typedef union _w32api_parser_type_definition_union w32api_parser_type_definition_union; +typedef struct _member member; +typedef struct _members members; +typedef union _w32api_result w32api_result; +typedef struct _w32api_dynamic_param w32api_dynamic_param; + +struct _w32api_lib_handle +{ + HINSTANCE handle; /* Handle for our library */ + char *library_name; /* name of our library */ + int ref_count; /* reference counter */ +}; + +struct _w32api_func_handle_ptr /* Temporary structure */ +{ /* To work around problems */ + w32api_func_handle *hnd; /* at 3am.. Ill sort it out */ +}; /* When I can think straight */ + +struct _w32api_type_handle_ptr /* Ditto.. should really combine */ +{ /* These two into a union at least */ + w32api_type_handle *hnd; +}; + +struct _w32api_type_handle +{ + char *type_name; /* Name of our type */ + long size; /* Size of type */ + members *member_list; /* Pointer List of members */ + long member_count; /* Number of members */ +}; + +struct _w32api_type_instance +{ + w32api_type_handle *type; /* pointer to w32api_type_handle */ + zval **values; /* First element of an array of ptr's to zvals */ +}; + +struct _w32api_func_handle +{ + FARPROC handle; /* Handle for our function */ + w32api_lib_handle *lib; /* Pointer to the library handle */ + char *function_name; /* Name of our function (Alias is store if supplied) */ + long return_type_id; /* ID of return type */ + char *return_type_name; /* Name of return type (if W32API_COMPLEX) */ + long flags; /* Flags for function */ + arguments *argument_list; /* Pointer List of arguments */ +}; + +struct _arguments +{ + argument *arg; /* Current Argument */ + arguments *next_arg; /* Next Arugment */ + arguments *prev_arg; /* Previous Argument */ +}; + +struct _argument +{ + long type_id; /* ID of the return type */ + char *type_name; /* Name of type (if W32API_COMPLEX) */ + char *argument_name; /* Name of argument, currently not used */ + long flags; /* Currently used for byref/byval */ +}; + +struct _member +{ + char *member_name; + long member_type_id; + char *member_type_name; + long flags; + long offset; +}; + +struct _members +{ + member *member; + members *next_member; + members *prev_member; +}; + +union _w32api_result +{ + int ival; + unsigned long lval; + DWORD dwval; + void *ptr; + float fval; + double dval; + __int64 i64val; +}; + +struct _w32api_dynamic_param +{ + long flags; + int width; + union { + unsigned long argument; + void *argument_ptr; + }; +}; + + +union _w32api_parser_function_definition_union +{ + char *s; + arguments *arg; +}; + +union _w32api_parser_type_definition_union +{ + char *s; + members *type; +}; + +/* ================================================================================================ + * Constants + * ================================================================================================ + */ + +/* Recognised Base types */ +#define W32API_UNKNOWN -1 +#define W32API_NULL 1 +#define W32API_INT 2 +#define W32API_LONG 3 +#define W32API_DOUBLE 4 +#define W32API_FLOAT 5 +#define W32API_STRING 6 +#define W32API_BYTE 7 +#define W32API_BOOL 8 +#define W32API_COMPLEX 9 + +/* Function Flags */ +#define W32API_ARGPTR (1<<0) +#define W32API_BORLAND (1<<1) +#define W32API_CDECL (1<<2) +#define W32API_REAL4 (1<<3) +#define W32API_REAL8 (1<<4) + +/* ================================================================================================ + * Utility Macros + * ================================================================================================ + */ +#define PROP_SET_ARGS zend_property_reference *property_reference, pval *value +#define PROP_GET_ARGS zend_property_reference *property_reference + +#define W32API_PROP_SET_FUNCTION_N(class_name) w32api_set_property_handler_##class_name +#define W32API_PROP_GET_FUNCTION_N(class_name) w32api_get_property_handler_##class_name +#define W32API_CALL_FUNCTION_N(class_name) w32api_call_handler_##class_name + +#define W32API_PROP_SET_FUNCTION(class_name) PHP_W32API_API int W32API_PROP_SET_FUNCTION_N(class_name)(PROP_SET_ARGS) +#define W32API_PROP_GET_FUNCTION(class_name) PHP_W32API_API zval W32API_PROP_GET_FUNCTION_N(class_name)(PROP_GET_ARGS) +#define W32API_CALL_FUNCITON(class_name) PHP_W32API_API void W32API_CALL_FUNCTION_N(class_name)(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference) + +#define W32API_CLASS_FUNCTION(class_name, function_name) PHP_FUNCTION(##class_name##function_name) +#define W32API_CLASS_FN(class_name, function_name) PHP_FN(##class_name##function_name) +#define W32API_CLASS_FE(class_name, function_name, function_args) {#function_name, W32API_CLASS_FN(class_name, function_name), function_args}, + +/* ================================================================================================ + * Module exports, Global Variables and General Definitions + * ================================================================================================ + */ extern zend_module_entry w32api_module_entry; -#define phpext_w32api_ptr &w32api_module_entry +#define phpext_w32api_ptr &w32api_module_entry; -#ifdef PHP_WIN32 #define PHP_W32API_API __declspec(dllexport) -#else -#define PHP_W32API_API -#endif #ifdef ZTS #include "TSRM.h" -#endif +#endif /* ZTS */ ZEND_BEGIN_MODULE_GLOBALS(w32api) - HashTable *regfuncs; // HashTable of Registered function handles - HashTable *libraries; // HashTable holding pointers to the libariers - HashTable *types; // Handles for users' types - int le_dynaparm; // Resource handle - DWORD call_type; // Type of call we use when calling a DLL. + zend_class_entry *win32_ce; /* The class entry for our win32 class */ + zend_class_entry *type_ce; /* The class entry for our type class */ + HashTable *funcs; /* Functions we registered */ + HashTable *libraries; /* Libraries we load using LoadLibrary */ + HashTable *types; /* Types we have registed with us */ + HashTable *callbacks; /* Callbacks we have registered with us */ + long le_type_instance; /* Resource hanlde for runtime instances */ ZEND_END_MODULE_GLOBALS(w32api) +ZEND_DECLARE_MODULE_GLOBALS(w32api) + #ifdef ZTS -#define W32_G(v) TSRMG(w32api_globals_id, zend_w32api_globals *, v) +#define WG(v) TSRMG(w32api_globals_id, zend_w32api_globals *, v) #else -#define W32_G(v) (w32api_globals.v) +#define WG(v) (w32api_globals.v) #endif -#define W32_REG_CONST(cname) REGISTER_LONG_CONSTANT(#cname, cname, CONST_CS | CONST_PERSISTENT); - -#define DC_MICROSOFT 0x0000 // Default -#define DC_BORLAND 0x0001 // Borland compat -#define DC_CALL_CDECL 0x0010 // __cdecl -#define DC_CALL_STD 0x0020 // __stdcall -#define DC_RETVAL_MATH4 0x0100 // Return value in ST -#define DC_RETVAL_MATH8 0x0200 // Return value in ST - -#define DC_CALL_STD_BO (DC_CALL_STD | DC_BORLAND) -#define DC_CALL_STD_MS (DC_CALL_STD | DC_MICROSOFT) -#define DC_CALL_STD_M8 (DC_CALL_STD | DC_RETVAL_MATH8) - -#define DC_FLAG_ARGPTR 0x00000002 - -typedef struct W32APIFE { - FARPROC fp; // Pointer to the function - char *rettype; // return value type - int retvaltype; // if complex = 1 if simple = 0 -} W32APIFE; - -typedef struct _field { - char *fname; // Fields name - char *type; // Type of field - int fsize; // size of field -} field; - -typedef struct runtime_struct { - char *name; // structs name - long size; // structs size - void *fields; // pointer to an array of fields -} runtime_struct; - -#pragma pack(1) // Set struct packing to one byte - -typedef union RESULT { // Various result types - int Int; // Generic four-byte type - long Long; // Four-byte long - void *Pointer; // 32-bit pointer - float Float; // Four byte real - double Double; // 8-byte real - __int64 int64; // big int (64-bit) -} RESULT; - - -typedef struct DYNAPARM { - DWORD dwFlags; // Parameter flags - int nWidth; // Byte width - union { // - DWORD dwArg; // 4-byte argument - void *pArg; // Pointer to argument - }; -} DYNAPARM; - - -PHP_W32API_API RESULT php_w32api_dynamic_dll_call( - int Flags, - DWORD lpFunction, - int nArgs, - DYNAPARM Param[], - LPVOID pRet, - int nRetSize - ); -static void php_w32api_init_globals(zend_w32api_globals *w32api_globals); -static void php_w32api_dtor_libary(void *data); -static void php_w32api_unload_libraries(); - -PHP_MINFO_FUNCTION(w32api); +/* ================================================================================================ + * Startup, Shutdown and Info Functions + * ================================================================================================ + */ PHP_MINIT_FUNCTION(w32api); PHP_MSHUTDOWN_FUNCTION(w32api); +PHP_RINIT_FUNCTION(w32api); +PHP_RSHUTDOWN_FUNCTION(w32api); +PHP_MINFO_FUNCTION(w32api); +static void php_w32api_init_globals(zend_w32api_globals *w32api_globals); +static void php_w32api_hash_lib_dtor(void *data); +static void php_w32api_hash_func_dtor(void *data); +static void php_w32api_hash_callback_dtor(void *data); +static void php_w32api_hash_type_dtor(void *data); +static void w32api_type_instance_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC); + +/* ================================================================================================ + * Win32 Class Functions + * ================================================================================================ + */ +int win32_class_init(TSRMLS_D); +int win32_class_rshutdown(TSRMLS_D); +W32API_CLASS_FUNCTION(win32, registerfunction); +W32API_CLASS_FUNCTION(win32, unregisterfunction); +W32API_CLASS_FUNCTION(win32, registercallback); +W32API_CLASS_FUNCTION(win32, definetype); +W32API_CLASS_FUNCTION(win32, gettypesize); +W32API_CLASS_FUNCTION(win32, inittype); +W32API_CLASS_FUNCTION(win32, decref); +W32API_CLASS_FUNCTION(win32, invokefunction); + + +/* ================================================================================================ + * Type Class Functions + * ================================================================================================ + */ +int type_class_init(TSRMLS_DC); + +W32API_CLASS_FUNCTION(type, clone); +W32API_PROP_SET_FUNCTION(type); +W32API_PROP_GET_FUNCTION(type); + +/* ================================================================================================ + * Utility Functions + * ================================================================================================ + */ + +static int php_w32api_load_function (char *definition, int definition_len, int flags TSRMLS_DC); +static void php_w32api_unload_function (w32api_func_handle **fh TSRMLS_DC); + +static int php_w32api_load_library (char *library_name, w32api_lib_handle **lh TSRMLS_DC); +static void php_w32api_unload_library (w32api_lib_handle *lh, int flags TSRMLS_DC); + +static int php_w32api_register_callback(char *function_definition, int function_definition_len TSRMLS_DC); + +static void php_w32api_free_arguments(arguments *argument_list); +static void php_w32api_free_members(members *member_list); + +static int php_w32api_get_type_id_from_name(char *type); +static unsigned char *php_w32api_do_arg_types(arguments **arguments); + +void php_w32api_marshall_zval_to_c(argument *arg, w32api_dynamic_param *dp, zval *pzval TSRMLS_DC); + +static void php_w32api_init_type(w32api_type_handle *th, zval *obj TSRMLS_DC); +static int php_w32api_do_prop_get(zval *object, zval *return_value, zend_llist_element **element TSRMLS_DC); +static int php_w32api_do_prop_set(zval *object, zval *value, zend_llist_element **element TSRMLS_DC); +static void *php_w32api_complex_marshall_zval_to_c(zval *pzval, int *width, void *data TSRMLS_DC); + +/* ================================================================================================ + * Parser & Scanner Functions + * ================================================================================================ + */ +#define w32api_parser_load_alias_function w32api_parser_load_function_ex +#define w32api_parser_load_function(return_type, function_name, arguments, library_name) w32api_parser_load_function_ex (return_type, function_name, NULL, arguments, library_name) +#define w32api_parser_make_argument_byref(arg_type, arg_name) w32api_parser_make_argument(arg_type, arg_name, BYREF_FORCE) +#define w32api_parser_make_argument_byval(arg_type, arg_name) w32api_parser_make_argument(arg_type, arg_name, BYREF_NONE) + +#define w32api_parser_type_make_byref_value(member_name, member_type) w32api_parser_type_make_value(member_name, member_type, BYREF_FORCE) +#define w32api_parser_type_make_byval_value(member_name, member_type) w32api_parser_type_make_value(member_name, member_type, BYREF_NONE) + +w32api_func_handle *w32api_parser_load_function_ex(char *return_type, char *function_name, char *alias_name, arguments *argument_list, char *library_name); +arguments *w32api_parser_make_argument(char *arg_type, char *arg_name, int byref); +arguments *w32api_parser_join_arguments(arguments *lval, arguments *rval); +int w32api_function_definition_error(char *s); + +w32api_type_handle *w32api_parser_register_type(char *type_name, members *member_list); +members *w32api_parser_type_make_value(char *member_name, char *type_name, long flags); +members *w32api_parser_type_join_values(members *lval, members *rval); +int w32api_type_definition_error(char *s); + +struct yy_buffer_state *w32api_function_definition_scan_bytes(char *bytes, int len); /* Definied in w32api_function_definition_scanner.c */ +int w32api_function_definition_parse(void *fh); /* Definied in w32api_function_definition_parser.c */ + +struct yy_buffer_state *w32api_type_definition_scan_bytes(char *bytes, int len); /* Definied in w32api_type_definition_scanner.c */ +int w32api_type_definition_parse(void *th); /* Definied in w32api_type_definition_parser.c */ + + +/* ================================================================================================ + * Various Debugging Functions + * ================================================================================================ + */ +#ifndef NDEBUG +W32API_CLASS_FUNCTION(win32, dump_library_hash); +W32API_CLASS_FUNCTION(win32, dump_function_hash); +W32API_CLASS_FUNCTION(win32, dump_callback_hash); +W32API_CLASS_FUNCTION(win32, dump_type_hash); + +int php_w32api_dump_library_hash_cb(void *pData TSRMLS_DC); +int php_w32api_dump_function_hash_cb(void *pData TSRMLS_DC); +int php_w32api_dump_callback_hash_cb(void *pData TSRMLS_DC); +int php_w32api_dump_type_hash_cb(void *pData TSRMLS_DC); -PHP_FUNCTION(w32api_register_function); -PHP_FUNCTION(w32api_invoke_function); -PHP_FUNCTION(w32api_deftype); -PHP_FUNCTION(w32api_init_dtype); -PHP_FUNCTION(w32api_set_call_method); +void php_w32api_print_arguments(arguments *argument_list); +void php_w32api_print_members(members *member_list); -static void register_constants(int module_number); -static void w32api_free_dynaparm(zend_rsrc_list_entry *rsrc TSRMLS_DC); -void get_arg_pointer(zval **value, void ** argument); -DYNAPARM w32api_convert_zval_to_dynparam(zval ** carg TSRMLS_DC); +#endif /* ifndef NDEBUG */ -#endif /* PHP_W32API_H */ -#endif /* HAVE_W32API */
\ No newline at end of file +#endif /* ifndef PHP_W32API_H */ +#endif /* if HAVE_W32API */
\ No newline at end of file |