/***************************** {{{ LICENSE ********************************\ * dbobj, the relational object persistence module for PHP * * Copyright (C) 2006 Adam Banko * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * \***************************** LICENSE }}} ********************************/ #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_dbobj.h" #include "dbobj.h" #include "dbobjIterator.h" #include "dbTypes.h" #include "objTypes.h" #include "objType/relation.h" #include "dbDriver.h" #include "classConfig.h" #include "localClassConfig.h" ZEND_DECLARE_MODULE_GLOBALS(dbobj) /* {{{ dbobj_functions[] */ function_entry dbobj_functions[] = { PHP_FE(dbobj_find, NULL) //explicit dbobj initializaton {NULL, NULL, NULL} // Must be the last line in dbobj_functions[] }; /* }}} */ /* {{{ dbobj_module_entry */ zend_module_entry dbobj_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, #endif "dbobj", dbobj_functions, PHP_MINIT(dbobj), PHP_MSHUTDOWN(dbobj), PHP_RINIT(dbobj), PHP_RSHUTDOWN(dbobj), PHP_MINFO(dbobj), #if ZEND_MODULE_API_NO >= 20010901 DBOBJ_VERSION, //version number #endif STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_DBOBJ ZEND_GET_MODULE(dbobj); #endif /* {{{ PHP_INI */ PHP_INI_BEGIN() #if 0 //Disabled: moved to perclass STD_PHP_INI_ENTRY("dbobj.default_read_access", "public", PHP_INI_ALL, OnUpdateDefault_read_access, default_read_access_str, zend_dbobj_globals, dbobj_globals) STD_PHP_INI_ENTRY("dbobj.default_write_access", "private", PHP_INI_ALL, OnUpdateDefault_write_access, default_write_access_str, zend_dbobj_globals, dbobj_globals) //a dbobj_init hasznalja, ha nincs parametere PHP_INI_ENTRY("dbobj.connStr", " ", PHP_INI_ALL, NULL) #endif //a parametereket case sensitive modon kezeljuk-e STD_PHP_INI_ENTRY("dbobj.case_sensitive", "1", PHP_INI_ALL, OnUpdateBool, case_sensitive, zend_dbobj_globals, dbobj_globals) PHP_INI_END() /* }}} */ /* {{{ php_dbobj_init_globals */ static void php_dbobj_init_globals(zend_dbobj_globals *dbobj_globals) { #if 0 //Disabled: moved to perclass dbobj_globals->default_read_access = DBOBJ_ACC_PUBLIC; dbobj_globals->default_write_access = DBOBJ_ACC_PRIVATE; #endif } /* }}} */ /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(dbobj) { ZEND_INIT_MODULE_GLOBALS(dbobj, php_dbobj_init_globals, NULL); REGISTER_INI_ENTRIES(); php_dbobj_MINIT_classConfig(module_number TSRMLS_CC); php_dbobj_MINIT_dbobj(module_number TSRMLS_CC); php_dbobj_MINIT_dbobjIterator(module_number TSRMLS_CC); php_dbobj_MINIT_dbTypes(TSRMLS_C); php_dbobj_MINIT_objTypes(TSRMLS_C); php_dbobj_MINIT_objType_relation(TSRMLS_C); php_dbobj_MINIT_dbDriver(TSRMLS_C); php_dbobj_MINIT_localClassConfig(); return SUCCESS; } /* }}} */ /* {{{ PHP_MSHUTDOWN_FUNCTION */ PHP_MSHUTDOWN_FUNCTION(dbobj) { php_dbobj_MSHUTDOWN_classConfig(SHUTDOWN_FUNC_ARGS_PASSTHRU); php_dbobj_MSHUTDOWN_objType_relation(TSRMLS_C); php_dbobj_MSHUTDOWN_localClassConfig(); UNREGISTER_INI_ENTRIES(); return SUCCESS; } /* }}} */ /* Remove if there's nothing to do at request start */ /* {{{ PHP_RINIT_FUNCTION */ PHP_RINIT_FUNCTION(dbobj) { php_dbobj_RINIT_dbobj(TSRMLS_C); php_dbobj_RINIT_dbobjIterator(TSRMLS_C); php_dbobj_RINIT_localClassConfig(TSRMLS_C); php_dbobj_RINIT_dbDriver(TSRMLS_C); return SUCCESS; } /* }}} */ /* Remove if there's nothing to do at request end */ /* {{{ PHP_RSHUTDOWN_FUNCTION */ PHP_RSHUTDOWN_FUNCTION(dbobj) { php_dbobj_RSHUTDOWN_dbobj(TSRMLS_C); php_dbobj_RSHUTDOWN_localClassConfig(TSRMLS_C); php_dbobj_RSHUTDOWN_dbDriver(TSRMLS_C); return SUCCESS; } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(dbobj) { php_info_print_table_start(); php_info_print_table_header(2, "dbobj support", "enabled"); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); } /* }}} */ //{{{ pe_e_freeer void pe_e_freeer(void *pDest){ efree(pDest); }//}}} //{{{ pe_e_ptr_freeer void pe_e_ptr_freeer(void *pDest){ efree(*(void**)pDest); }//}}} //{{{ pe_permanent_freeer void pe_permanent_freeer(void *pDest) { pefree(pDest, 1); }//}}} //{{{ pe_permanent_ptr_freeer void pe_permanent_ptr_freeer(void *pDest) { pefree(*(void**)pDest, 1); }//}}} //{{{void_dtor(...) void void_dtor(void *ptr) {} //yes, it does nothing //}}} /* {{{visibility_string * zend_visibility_string masolata */ static char *visibility_string(zend_uint fn_flags) { if (fn_flags & ZEND_ACC_PRIVATE) { return "private"; } if (fn_flags & ZEND_ACC_PROTECTED) { return "protected"; } if (fn_flags & ZEND_ACC_PUBLIC) { return "public"; } return ""; }//}}} /* {{{dbobj_general_get_method * ALAPGONDOLAT: zend_std_get_method */ union _zend_function* dbobj_general_get_method(zend_class_entry* ce, char *methodName, int methodNameL TSRMLS_DC) { zend_function *fbc; char *lc_methodName; lc_methodName = emalloc(methodNameL+1); /* Create a zend_copy_str_tolower(dest, src, src_length); */ zend_str_tolower_copy(lc_methodName, methodName, methodNameL); if (zend_hash_find(&ce->function_table, lc_methodName, methodNameL+1, (void **)&fbc) == FAILURE) { efree(lc_methodName); return NULL; } /* Check access level */ if (fbc->op_array.fn_flags & ZEND_ACC_PUBLIC) { /* Ensure that we haven't overridden a private function and end up calling * the overriding public function... */ if (EG(scope) && fbc->op_array.fn_flags & ZEND_ACC_CHANGED) { zend_function *priv_fbc; if (zend_hash_find(&EG(scope)->function_table, lc_methodName, methodNameL+1, (void **) &priv_fbc)==SUCCESS && priv_fbc->common.fn_flags & ZEND_ACC_PRIVATE && priv_fbc->common.scope == EG(scope)) { fbc = priv_fbc; } } } else if (fbc->op_array.fn_flags & ZEND_ACC_PRIVATE) { zend_function *updated_fbc; /* Ensure that if we're calling a private function, we're allowed to do so. */ /* * ALAPGONDOLAT: zend_check_private_int */ /* We may call a private function if: * 1. The class of our object is the same as the scope, and the private * function (EX(fbc)) has the same scope. * 2. One of our parent classes are the same as the scope, and it contains * a private function with the same name that has the same scope. */ if (fbc->common.scope == ce && EG(scope) == ce) { /* rule #1 checks out ok, allow the function call */ return fbc; } /* Check rule #2 */ ce = ce->parent; while (ce) { if (ce == EG(scope)) { if (zend_hash_find(&ce->function_table, lc_methodName, methodNameL+1, (void **) &fbc)==SUCCESS && fbc->op_array.fn_flags & ZEND_ACC_PRIVATE && fbc->common.scope == EG(scope)) { updated_fbc = fbc; } break; } ce = ce->parent; } updated_fbc = NULL; /***/ if (!updated_fbc) { zend_error(E_ERROR, "Call to %s method %s::%s() from context '%s'", visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), methodName, EG(scope) ? EG(scope)->name : ""); } fbc = updated_fbc; } else if ((fbc->common.fn_flags & ZEND_ACC_PROTECTED)) { /* Ensure that if we're calling a protected function, we're allowed to do so. */ if (!zend_check_protected(fbc->common.scope, EG(scope))) { zend_error(E_ERROR, "Call to %s method %s::%s() from context '%s'", visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), methodName, EG(scope) ? EG(scope)->name : ""); } } efree(lc_methodName); return fbc; }//}}} /* * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */