static unsigned char arg1and2_force_ref[] = { 2, BYREF_FORCE, BYREF_FORCE };
/* register rpc callback function */
-RPC_REGISTER_HANDLERS_START(com)
+RPC_REGISTER_HANDLERS_BEGIN(com)
TRUE, /* poolable */
HASH_AS_INT_WITH_SIGNATURE,
com_hash,
RPC_REGISTER_HANDLERS_END()
/* register ini settings */
-RPC_INI_START(com)
+PHP_INI_BEGIN()
PHP_INI_ENTRY_EX("com.allow_dcom", "0", PHP_INI_SYSTEM, NULL, php_ini_boolean_displayer_cb)
PHP_INI_ENTRY_EX("com.autoregister_typelib", "0", PHP_INI_SYSTEM, NULL, php_ini_boolean_displayer_cb)
PHP_INI_ENTRY_EX("com.autoregister_verbose", "0", PHP_INI_SYSTEM, NULL, php_ini_boolean_displayer_cb)
PHP_INI_ENTRY_EX("com.autoregister_casesensitive", "1", PHP_INI_SYSTEM, NULL, php_ini_boolean_displayer_cb)
PHP_INI_ENTRY("com.typelib_file", "", PHP_INI_SYSTEM, com_typelib_file_change)
-RPC_INI_END()
+PHP_INI_END()
/* register userspace functions */
-RPC_FUNCTION_ENTRY_START(com)
+RPC_FUNCTION_ENTRY_BEGIN(com)
ZEND_FALIAS(com_invoke, rpc_call, NULL)
ZEND_FE(com_addref, NULL)
ZEND_FE(com_release, NULL)
ZEND_FE(com_print_typeinfo, NULL)
RPC_FUNCTION_ENTRY_END()
+zend_module_entry com_module_entry = {
+ ZE2_STANDARD_MODULE_HEADER,
+ "com",
+ RPC_FUNCTION_ENTRY(com),
+ ZEND_MINIT(com),
+ ZEND_MSHUTDOWN(com),
+ NULL,
+ NULL,
+ ZEND_MINFO(com),
+ "0.1a",
+ STANDARD_MODULE_PROPERTIES
+};
+
/* register class methods */
-RPC_METHOD_ENTRY_START(com)
+RPC_METHOD_ENTRY_BEGIN(com)
ZEND_FALIAS(addref, com_addref, NULL)
ZEND_FALIAS(release, com_release, NULL)
ZEND_FALIAS(next, com_next, NULL)
RPC_METHOD_ENTRY_END()
-/* init function that is called before the class is registered
- * so you can do any tricky stuff in here
- */
-RPC_INIT_FUNCTION(com)
+ZEND_MINIT_FUNCTION(com)
{
CreateBindCtx(0, &pBindCtx);
php_variant_init(module_number TSRMLS_CC);
+
+ RPC_REGISTER_LAYER(com);
+ REGISTER_INI_ENTRIES();
+
+ return SUCCESS;
}
-RPC_SHUTDOWN_FUNCTION(com)
+ZEND_MSHUTDOWN_FUNCTION(com)
{
php_variant_shutdown(TSRMLS_C);
pBindCtx->lpVtbl->Release(pBindCtx);
+
+ UNREGISTER_INI_ENTRIES();
+
+ return SUCCESS;
+}
+
+ZEND_MINFO_FUNCTION(com)
+{
+ DISPLAY_INI_ENTRIES();
}
+#ifdef COMPILE_DL_COM
+ZEND_GET_MODULE(com);
+#endif
+
/* rpc handler functions */
static int com_hash(rpc_string name, rpc_string *hash, void *data, int num_args, char *arg_types, int type)
#include "php.h"
#include "php_ini.h"
-#define RPC_HANDLER(layer) {#layer, layer##_handler_init, layer##_handler_shutdown, \
- &layer##_object_handlers, &layer##_class_entry, \
- layer##_function_entry, layer##_method_entry, \
- layer##_ini_entry}
-
-#define RPC_DECLARE_HANDLER(layer) void layer##_handler_init(int module_number TSRMLS_DC); \
- void layer##_handler_shutdown(TSRMLS_D); \
- rpc_object_handlers layer##_object_handlers; \
+#define RPC_REGISTER_LAYER(layer) rpc_register_layer(&layer##_handler_entry TSRMLS_CC);
+#define RPC_DECLARE_HANDLER(layer) rpc_object_handlers layer##_object_handlers; \
zend_class_entry *layer##_class_entry; \
function_entry layer##_function_entry[]; \
function_entry layer##_method_entry[]; \
- zend_ini_entry layer##_ini_entry[];
+ static rpc_handler_entry layer##_handler_entry = \
+ {#layer, &layer##_object_handlers, &layer##_class_entry,\
+ layer##_function_entry, layer##_method_entry}
-#define RPC_INIT_FUNCTION(layer) void layer##_handler_init(int module_number TSRMLS_DC)
-#define RPC_SHUTDOWN_FUNCTION(layer) void layer##_handler_shutdown(TSRMLS_D)
-
-#define RPC_REGISTER_HANDLERS_START(layer) zend_class_entry *layer##_class_entry; \
+#define RPC_REGISTER_HANDLERS_BEGIN(layer) zend_class_entry *layer##_class_entry; \
rpc_object_handlers layer##_object_handlers = {
#define RPC_REGISTER_HANDLERS_END() };
-#define RPC_INI_START(layer) zend_ini_entry layer##_ini_entry[] = {
-#define RPC_INI_END() { 0, 0, NULL, 0, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, NULL } };
-
-#define RPC_FUNCTION_ENTRY_START(layer) function_entry layer##_function_entry[] = { \
+#define RPC_FUNCTION_ENTRY(layer) layer##_function_entry
+#define RPC_FUNCTION_ENTRY_BEGIN(layer) function_entry layer##_function_entry[] = { \
ZEND_FALIAS(layer##_load, rpc_load, NULL) \
ZEND_FALIAS(layer##_call, rpc_call, NULL) \
ZEND_FALIAS(layer##_get, rpc_get, NULL) \
#define RPC_FUNCTION_ENTRY_END() {NULL, NULL, NULL} \
};
-#define RPC_METHOD_ENTRY_START(layer) function_entry layer##_method_entry[] = {
+#define RPC_METHOD_ENTRY_BEGIN(layer) function_entry layer##_method_entry[] = {
#define RPC_METHOD_ENTRY_END() {NULL, NULL, NULL} \
};
/* handler entry */
typedef struct _rpc_handler_entry {
char *name;
- void (*rpc_handler_init)();
- void (*rpc_handler_shutdown)();
rpc_object_handlers *handlers;
zend_class_entry **ce;
function_entry *functions;
function_entry *methods;
- zend_ini_entry *ini;
} rpc_handler_entry;
/* class/method/function hash */
zend_uint dummy;
} rpc_proxy;
+ZEND_API rpc_register_layer(rpc_handler_entry *entry TSRMLS_DC);
#endif /* HANDLER_H */
\ No newline at end of file
#include "php_rpc.h"
#include "rpc.h"
-#include "layer.h"
#include "hash.h"
+#include "handler.h"
static void rpc_instance_dtor(void *);
static void rpc_class_dtor(void *);
static void rpc_string_dtor(void *);
static void rpc_objects_delete(void *, zend_object_handle TSRMLS_DC);
+static void rpc_ini_cb(void *arg TSRMLS_DC);
/* object handler */
static zval* rpc_read(zval *, zval *, int TSRMLS_DC);
zend_class_entry rpc_class_entry;
+static zend_class_entry *rpc_entry;
static zend_function *rpc_ctor;
-static HashTable *handlers;
-static TsHashTable *pool;
-static TsHashTable *classes;
-static zend_llist *classes_list;
+static HashTable handlers;
+static TsHashTable pool;
+static TsHashTable classes;
+static zend_llist classes_list;
+static zend_llist layers;
#ifdef COMPILE_DL_RPC
ZEND_GET_MODULE(rpc);
#endif
-ZEND_INI_BEGIN()
-ZEND_INI_END()
-
/* {{{ ZEND_MINIT_FUNCTION
*/
ZEND_MINIT_FUNCTION(rpc)
{
zend_internal_function *zif;
- zend_class_entry *rpc_entry;
/* rpc base class entry */
INIT_CLASS_ENTRY(rpc_class_entry, "rpc", NULL);
rpc_entry = zend_register_internal_class(&rpc_class_entry TSRMLS_CC);
- handlers = (HashTable *) pemalloc(sizeof(HashTable), TRUE);
- pool = (TsHashTable *) pemalloc(sizeof(TsHashTable), TRUE);
- classes = (TsHashTable *) pemalloc(sizeof(TsHashTable), TRUE);
- classes_list = (zend_llist *) pemalloc(sizeof(zend_llist), TRUE);
-
- zend_hash_init(handlers, 0, NULL, NULL, TRUE);
- zend_ts_hash_init(pool, sizeof(rpc_internal **), NULL, rpc_instance_dtor, TRUE);
- zend_ts_hash_init(classes, 0, NULL, NULL, TRUE);
- zend_llist_init(classes_list, sizeof(rpc_class_hash **), rpc_class_dtor, TRUE);
-
- FOREACH_HANDLER {
- /*
- handle = DL_LOAD(path);
- if (!handle) {
-#ifndef ZEND_WIN32
- fprintf(stderr, "Failed loading %s: %s\n", path, DL_ERROR());
-#else
- fprintf(stderr, "Failed loading %s\n", path);
-#endif
- return FAILURE;
- }
-
- extension_version_info = (zend_extension_version_info *) DL_FETCH_SYMBOL(handle, "extension_version_info");
- new_extension = (zend_extension *) DL_FETCH_SYMBOL(handle, "zend_extension_entry");
- if (!extension_version_info || !new_extension) {
- fprintf(stderr, "%s doesn't appear to be a valid Zend extension\n", path);
- return FAILURE;
- }
-*/
- zend_class_entry ce;
-
- HANDLER.rpc_handler_init(module_number TSRMLS_CC);
-
- /* create a class entry for every rpc handler */
- INIT_CLASS_ENTRY(ce,
- HANDLER.name,
- HANDLER.methods);
-
- ce.create_object = rpc_objects_new;
-
- /* load all available rpc handler into a hash */
- zend_hash_add(handlers, HANDLER.name, strlen(HANDLER.name) + 1, &(HANDLER.handlers), sizeof(rpc_object_handlers *), NULL);
-
- /* register classes and functions */
- *HANDLER.ce = zend_register_internal_class_ex(&ce, rpc_entry, NULL TSRMLS_CC);
- zend_register_functions(NULL, HANDLER.functions, NULL, MODULE_PERSISTENT TSRMLS_CC);
- zend_register_ini_entries(HANDLER.ini, module_number TSRMLS_CC);
- }
-
+ zend_hash_init(&handlers, 0, NULL, NULL, TRUE);
+ zend_ts_hash_init(&pool, sizeof(rpc_internal **), NULL, rpc_instance_dtor, TRUE);
+ zend_ts_hash_init(&classes, 0, NULL, NULL, TRUE);
+ zend_llist_init(&classes_list, sizeof(rpc_class_hash **), rpc_class_dtor, TRUE);
+ zend_llist_init(&layers, sizeof(char *), NULL, TRUE);
zif = (zend_internal_function *) emalloc(sizeof(zend_internal_function));
zend_hash_add(&(rpc_entry->function_table), rpc_entry->name, rpc_entry->name_length + 1, zif, sizeof(zend_function), &rpc_ctor);
efree(zif);
- REGISTER_INI_ENTRIES();
-
return SUCCESS;
}
/* }}} */
*/
ZEND_MSHUTDOWN_FUNCTION(rpc)
{
- FOREACH_HANDLER {
- HANDLER.rpc_handler_shutdown(TSRMLS_C);
- }
-
/* destroy instances first */
- zend_ts_hash_destroy(pool);
+ zend_ts_hash_destroy(&pool);
- zend_ts_hash_destroy(classes);
- zend_llist_destroy(classes_list);
- zend_hash_destroy(handlers);
+ zend_ts_hash_destroy(&classes);
+ zend_llist_destroy(&classes_list);
+ zend_llist_destroy(&layers);
+ zend_hash_destroy(&handlers);
- pefree(handlers, TRUE);
- pefree(classes, TRUE);
-
- UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
/* }}} */
ZEND_MINFO_FUNCTION(rpc)
{
php_info_print_table_start();
- php_info_print_table_header(2, "rpc support", "enabled");
+ zend_llist_apply(&layers, rpc_ini_cb TSRMLS_CC);
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
/* }}} */
+
+ZEND_API rpc_register_layer(rpc_handler_entry *entry TSRMLS_DC)
+{
+ zend_class_entry ce;
+
+ INIT_CLASS_ENTRY(ce, entry->name, entry->methods);
+
+ ce.create_object = rpc_objects_new;
+
+ /* load all available rpc handler into a hash */
+ zend_hash_add(&handlers, entry->name, strlen(entry->name) + 1, &(entry->handlers), sizeof(rpc_object_handlers *), NULL);
+ zend_llist_add_element(&layers, &(entry->name));
+
+ /* register classes */
+ *(entry->ce) = zend_register_internal_class_ex(&ce, rpc_entry, NULL TSRMLS_CC);
+}
static void rpc_class_dtor(void *pDest)
{
pefree(*intern, TRUE);
}
+static void rpc_ini_cb(void *arg TSRMLS_DC)
+{
+ char *name = *((char **) arg);
+ php_info_print_table_header(2, name, "loaded");
+}
+
static zend_object_value rpc_create_proxy(TSRMLS_D)
{
zend_object_value *zov;
pefree(intern, TRUE);
} else if (RPC_CLASS(intern) && RPC_CLASS(intern)->poolable) {
if (RPC_CLASS(intern)->name.str) {
- zend_ts_hash_add(pool, RPC_CLASS(intern)->name.str, RPC_CLASS(intern)->name.len + 1, &intern, sizeof(rpc_internal *), NULL);
+ zend_ts_hash_add(&pool, RPC_CLASS(intern)->name.str, RPC_CLASS(intern)->name.len + 1, &intern, sizeof(rpc_internal *), NULL);
} else {
- zend_ts_hash_index_update(pool, RPC_CLASS(intern)->name.len + 1, &intern, sizeof(rpc_internal *), NULL);
+ zend_ts_hash_index_update(&pool, RPC_CLASS(intern)->name.len + 1, &intern, sizeof(rpc_internal *), NULL);
}
} else {
if (intern->data != NULL) {
/**/
/* constructor */
-ZEND_FUNCTION(rpc_load)
+ZEND_API ZEND_FUNCTION(rpc_load)
{
zval *object = getThis();
zval ***args, ***args_free;
GET_SIGNATURE(intern, class_val.str, class_val.len, hash_val, num_args, arg_types);
/* check if already hashed */
- if (zend_ts_hash_find(classes, hash_val.str, hash_val.len + 1, (void **) &class_hash_find) != SUCCESS) {
+ if (zend_ts_hash_find(&classes, hash_val.str, hash_val.len + 1, (void **) &class_hash_find) != SUCCESS) {
class_hash = pemalloc(sizeof(rpc_class_hash), TRUE);
/* set up the cache */
* also track all instaces in a llist for destruction later on, because there might be duplicate entries in
* the hashtable and we can't determine if a pointer references to an already freed element
*/
- zend_ts_hash_add(classes, hash_val.str, hash_val.len + 1, &class_hash, sizeof(rpc_class_hash *), (void **) &class_hash_find);
- tsrm_mutex_lock(classes->mx_writer);
- zend_llist_add_element(classes_list, class_hash_find);
- tsrm_mutex_unlock(classes->mx_writer);
+ zend_ts_hash_add(&classes, hash_val.str, hash_val.len + 1, &class_hash, sizeof(rpc_class_hash *), (void **) &class_hash_find);
+ tsrm_mutex_lock(classes.mx_writer);
+ zend_llist_add_element(&classes_list, class_hash_find);
+ tsrm_mutex_unlock(classes.mx_writer);
if (class_hash->name.str) {
/* register string hashcode */
- zend_ts_hash_add(classes, class_hash->name.str, class_hash->name.len + 1, &class_hash, sizeof(rpc_class_hash *), NULL);
+ zend_ts_hash_add(&classes, class_hash->name.str, class_hash->name.len + 1, &class_hash, sizeof(rpc_class_hash *), NULL);
} else if (!class_hash->name.str && (RPC_HT(intern)->hash_type & HASH_AS_INT)) {
/* register int hashcode */
- zend_ts_hash_index_update(classes, class_hash->name.len, &class_hash, sizeof(rpc_class_hash *), NULL);
+ zend_ts_hash_index_update(&classes, class_hash->name.len, &class_hash, sizeof(rpc_class_hash *), NULL);
}
} else {
class_hash = *class_hash_find;
}
} else {
/* integer classname (hashcode) */
- if (zend_ts_hash_index_find(classes, class_val.len, (void**) &class_hash_find) != SUCCESS) {
+ if (zend_ts_hash_index_find(&classes, class_val.len, (void**) &class_hash_find) != SUCCESS) {
class_hash = pemalloc(sizeof(rpc_class_hash), TRUE);
/* set up the cache */
intern->ce = class_hash->ce;
/* register int hashcode, we don't know more */
- zend_ts_hash_index_update(classes, class_hash->name.len, &class_hash, sizeof(rpc_class_hash *), NULL);
+ zend_ts_hash_index_update(&classes, class_hash->name.len, &class_hash, sizeof(rpc_class_hash *), NULL);
} else {
class_hash = *class_hash_find;
intern->ce = class_hash->ce;
/* assign cache structure */
RPC_CLASS(intern) = class_hash;
- if (zend_ts_hash_remove_key_or_index(pool, RPC_CLASS(intern)->name.str, RPC_CLASS(intern)->name.len + 1, (void **) &pool_intern) == SUCCESS) {
+ if (zend_ts_hash_remove_key_or_index(&pool, RPC_CLASS(intern)->name.str, RPC_CLASS(intern)->name.len + 1, (void **) &pool_intern) == SUCCESS) {
intern->data = pool_intern->data;
pefree(pool_intern, TRUE);
}
}
-ZEND_FUNCTION(rpc_call)
+ZEND_API ZEND_FUNCTION(rpc_call)
{
zval *object = getThis();
zval ***args, ***args_free;
}
}
-ZEND_FUNCTION(rpc_set)
+ZEND_API ZEND_FUNCTION(rpc_set)
{
zval *object, *value;
char *property = NULL;
}
}
-ZEND_FUNCTION(rpc_get)
+ZEND_API ZEND_FUNCTION(rpc_get)
{
zval *object;
char *property = NULL;
}
}
-ZEND_FUNCTION(rpc_singleton)
+ZEND_API ZEND_FUNCTION(rpc_singleton)
{
zval *object;
rpc_internal *intern;
}
}
-ZEND_FUNCTION(rpc_poolable)
+ZEND_API ZEND_FUNCTION(rpc_poolable)
{
zval *object;
rpc_internal *intern;
intern->function_table.mx_writer = tsrm_mutex_alloc();
intern->mx_handler = tsrm_mutex_alloc();
- if (zend_hash_find(handlers, class_type->name, class_type->name_length + 1, (void **) &(intern->handlers)) != SUCCESS) {
+ if (zend_hash_find(&handlers, class_type->name, class_type->name_length + 1, (void **) &(intern->handlers)) != SUCCESS) {
/* TODO: exception */
}