/***************************** {{{ 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 }}} ********************************/ #ifndef PHP_DBOBJ_H #define PHP_DBOBJ_H //String-with-length-definition #define STRINGLD(paramName) char* paramName, zend_uint paramName ## L //String-with-length-usage #define STRINGLU(paramName) paramName, paramName ## L //Zval String-with-length-usage #define Z_STRINGLU(paramName) Z_STRVAL(paramName), Z_STRLEN(paramName) #define Z_STRINGLU_P(paramName) Z_STRVAL_P(paramName), Z_STRLEN_P(paramName) #define Z_STRINGLU_PP(paramName) Z_STRVAL_PP(paramName), Z_STRLEN_PP(paramName) //"string with length" macros defined before all other, we hope this helps them to be expanded first (important if it is a macro parameter) #define _GNU_SOURCE #ifdef HAVE_CONFIG_H #include "config.h" #endif //exception #define EXCEPTION (EG(exception)) #include #include #include #include #include "VERSION.h" #ifndef DBOBJ_VERSION #error DBOBJ_VERSION not defined! (check VERSION.h) #endif extern zend_module_entry dbobj_module_entry; #define phpext_dbobj_ptr &dbobj_module_entry #ifdef PHP_WIN32 # if defined(DBOBJ_EXPORTS) || (!defined(COMPILE_DL_DBOBJ)) # define DBOBJ_API __declspec(dllexport) # elif defined(COMPILE_DL_DBOBJ) # define DBOBJ_API __declspec(dllimport) # else # define DBOBJ_API /* nothing special */ # endif #else # define DBOBJ_API /* nothing special */ #endif #include "access.h" #include #ifdef ZTS #include #endif typedef unsigned char bool; PHP_MINIT_FUNCTION(dbobj); PHP_MSHUTDOWN_FUNCTION(dbobj); PHP_RINIT_FUNCTION(dbobj); PHP_RSHUTDOWN_FUNCTION(dbobj); PHP_MINFO_FUNCTION(dbobj); ZEND_BEGIN_MODULE_GLOBALS(dbobj) HashTable objCache; HashTable garbage_list; HashTable dbConnections; zend_bool case_sensitive; //ini setting, default value for perclass setting HashTable localClassConfigs; //DISABLED: these settings should be only perclass (perconnection) // char* default_read_access_str; // char* default_write_access_str; // enum accessT default_read_access; // enum accessT default_write_access; // PGconn* conn; // cursorCounterT cursorCounter; //the next free cursor number ZEND_END_MODULE_GLOBALS(dbobj) ZEND_EXTERN_MODULE_GLOBALS(dbobj) /* In every utility function you add that needs to use variables in php_dbobj_globals, call TSRMLS_FETCH(); after declaring other variables used by that function, or better yet, pass in TSRMLS_CC after the last function argument and declare your utility function with TSRMLS_DC after the last declared argument. Always refer to the globals in your function as DBOBJ_G(variable). You are encouraged to rename these macros something shorter, see examples in any other php module directory. */ #ifdef ZTS #define DBOBJ_G(v) TSRMG(dbobj_globals_id, zend_dbobj_globals *, v) #define mutex_alloc() tsrm_mutex_alloc() #define mutex_free(mutex) tsrm_mutex_free(mutex) #define mutex_lock(mutex) tsrm_mutex_lock(mutex) #define mutex_unlock(mutex) tsrm_mutex_unlock(mutex) //for things that shoudn't be optimized in multi-threaded enviroment #define ZTS_VOLATILE volatile #else #define DBOBJ_G(v) (dbobj_globals.v) //non-zts aspect should never call mutex_alloc or mutex_free, it shoudn't have any mutex variables! #define mutex_lock(mutex) do{}while(0) #define mutex_unlock(mutex) do{}while(0) #define ZTS_VOLATILE #endif //for error reporting when we don't know the size of the error string //FIXME todo it would be nicer if the buffer size was determined dinamically // (using snprintf in an iteration => man snprintf) #define EMERGENCY_BUFFER_SIZE ( 8 * 1024 ) #if PHP_DEBUG #define DBOBJ_DEBUG 1 #else #define DBOBJ_DEBUG 0 #endif #if DBOBJ_DEBUG # define DBOBJ_ERROR(...) DBOBJ_ERROR_CRIT(__VA_ARGS__) # define DBOBJ_ERROR_CRIT(format, ...) {char *tmp=emalloc(EMERGENCY_BUFFER_SIZE); \ snprintf(tmp,EMERGENCY_BUFFER_SIZE , "%s:%d " format, __FILE__, __LINE__, ##__VA_ARGS__); \ zend_error(E_ERROR, tmp); \ efree(tmp);} # define DBOBJ_WARNING(format, ...) {char *tmp=emalloc(EMERGENCY_BUFFER_SIZE); \ snprintf(tmp,EMERGENCY_BUFFER_SIZE , "%s:%d " format, __FILE__, __LINE__, ##__VA_ARGS__); \ zend_error(E_WARNING, tmp); \ efree(tmp);} # define DBOBJ_ERROR_EX(format, ...) { \ TSRMLS_FETCH(); \ zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "%s:%d " format, __FILE__, __LINE__, ##__VA_ARGS__);} # define DBOBJ_NOTICE(format, ...) {char *tmp=emalloc(EMERGENCY_BUFFER_SIZE); \ snprintf(tmp,EMERGENCY_BUFFER_SIZE , "%s:%d " format, __FILE__, __LINE__, ##__VA_ARGS__); \ zend_error(E_NOTICE, tmp); \ efree(tmp);} #else //DBOBJ_DEBUG # ifdef NDEBUG # undef NDEBUG # endif # define NDEBUG 1 # define DBOBJ_ERROR(...) zend_error(E_ERROR, __VA_ARGS__) # define DBOBJ_ERROR_CRIT(...) zend_error(E_ERROR, __VA_ARGS__) # define DBOBJ_WARNING(...) zend_error(E_WARNING, __VA_ARGS__) # define DBOBJ_NOTICE(...) zend_error(E_NOTICE, __VA_ARGS__) #endif #define DBOBJ_LOG_SQL(query) do{}while(0) //#define DBOBJ_LOG_SQL(query) php_printf("SQL: %s\n", query) //CALl Method #define CALM(object, function, ...) (object)->vt->function ((object) , ##__VA_ARGS__) #define CALMT(object, function, ...) (object)->vt->function ((object) , ##__VA_ARGS__ TSRMLS_CC) #define SAFE_ALLOCA_LIMIT 1024 #define safe_alloca(size) ((size < SAFE_ALLOCA_LIMIT) ? do_alloca(size) : emalloc(size)) #define free_safe_alloca(ptr, size) ((size < SAFE_ALLOCA_LIMIT) ? free_alloca(ptr) : efree(ptr)) void pe_e_freeer(void *pDest); void pe_e_ptr_freeer(void *pDest); void pe_permanent_freeer(void *pDest); void pe_permanent_ptr_freeer(void *pDest); void void_dtor(void *ptr); //does nothing union _zend_function* dbobj_general_get_method(zend_class_entry* ce, char *methodName, int methodNameL TSRMLS_DC); #endif /* PHP_DBOBJ_H */ /* * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */