57 const char *default_handler;
58 const dba_handler *default_hptr;
60 unsigned int connection_counter;
65#define DBA_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(dba, v)
101 if (zend_hash_num_elements(
key) != 2) {
109 group_str = zval_try_get_string(group);
116 name_str = zval_try_get_string(
name);
135#define DBA_RELEASE_HT_KEY_CREATION() if (key_ht) {zend_string_release_ex(key_str, false);}
137#define CHECK_DBA_CONNECTION(info) \
138 if (info == NULL) { \
139 zend_throw_error(NULL, "DBA connection has already been closed"); \
144#define DBA_WRITE_CHECK(info) \
145 if ((info)->mode != DBA_WRITER && (info)->mode != DBA_TRUNC && (info)->mode != DBA_CREAT) { \
146 php_error_docref(NULL, E_WARNING, "Cannot perform a modification on a readonly database"); \
152#define DBA_NAMED_HND(alias, name, flags) \
154 #alias, flags, dba_open_##name, dba_close_##name, dba_fetch_##name, dba_update_##name, \
155 dba_exists_##name, dba_delete_##name, dba_firstkey_##name, dba_nextkey_##name, \
156 dba_optimize_##name, dba_sync_##name, dba_info_##name \
159#define DBA_HND(name, flags) DBA_NAMED_HND(name, name, flags)
165static const dba_handler
handler[] = {
167 DBA_HND(gdbm, DBA_LOCK_EXT)
170 DBA_HND(dbm, DBA_LOCK_ALL)
173 DBA_HND(ndbm, DBA_LOCK_ALL)
176 DBA_HND(
cdb, DBA_STREAM_OPEN|DBA_LOCK_ALL)
178#ifdef DBA_CDB_BUILTIN
179 DBA_NAMED_HND(
cdb_make,
cdb, DBA_STREAM_OPEN|DBA_LOCK_ALL)
182 DBA_HND(db1, DBA_LOCK_ALL)
185 DBA_HND(db2, DBA_LOCK_ALL)
188 DBA_HND(db3, DBA_LOCK_ALL)
191 DBA_HND(db4, DBA_LOCK_ALL)
194 DBA_HND(
inifile, DBA_STREAM_OPEN|DBA_LOCK_ALL|DBA_CAST_AS_FD)
197 DBA_HND(
flatfile, DBA_STREAM_OPEN|DBA_LOCK_ALL|DBA_NO_APPEND)
200 DBA_HND(qdbm, DBA_LOCK_EXT)
203 DBA_HND(tcadb, DBA_LOCK_ALL)
206 DBA_HND(lmdb, DBA_LOCK_EXT)
208 {
NULL, 0,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL }
212#define DBA_DEFAULT "flatfile"
213#elif defined(DBA_DB4)
214#define DBA_DEFAULT "db4"
215#elif defined(DBA_DB3)
216#define DBA_DEFAULT "db3"
217#elif defined(DBA_DB2)
218#define DBA_DEFAULT "db2"
219#elif defined(DBA_DB1)
220#define DBA_DEFAULT "db1"
221#elif defined(DBA_GDBM)
222#define DBA_DEFAULT "gdbm"
223#elif defined(DBA_NBBM)
224#define DBA_DEFAULT "ndbm"
225#elif defined(DBA_DBM)
226#define DBA_DEFAULT "dbm"
227#elif defined(DBA_QDBM)
228#define DBA_DEFAULT "qdbm"
229#elif defined(DBA_TCADB)
230#define DBA_DEFAULT "tcadb"
231#elif defined(DBA_LMDB)
232#define DBA_DEFAULT "lmdb"
234#define DBA_DEFAULT ""
243static void dba_close_info(dba_info *info)
248 info->hnd->close(info);
255 if (info->fp && info->fp != info->lock.fp) {
256 if (info->flags & DBA_PERSISTENT) {
263 if (info->flags & DBA_PERSISTENT) {
270 pefree(info, info->flags & DBA_PERSISTENT);
274static int remove_pconnection_from_list(
zval *
zv,
void *
p)
287 dba_info *info = (dba_info *) rsrc->
ptr;
289 dba_close_info(info);
294static void dba_close_connection(dba_connection *connection)
296 bool persistent = connection->info->flags & DBA_PERSISTENT;
299 dba_close_info(connection->info);
302 connection->info =
NULL;
304 if (connection->hash) {
307 connection->hash =
NULL;
313 dba_connection *intern = zend_object_alloc(
sizeof(dba_connection), class_type);
323 zend_throw_error(
NULL,
"Cannot directly construct Dba\\Connection, use dba_open() or dba_popen() instead");
340static inline dba_connection *dba_connection_from_obj(
zend_object *obj)
342 return (dba_connection *)((
char *)(obj) -
XtOffsetOf(dba_connection, std));
345#define Z_DBA_CONNECTION_P(zv) dba_connection_from_obj(Z_OBJ_P(zv))
346#define Z_DBA_INFO_P(zv) Z_DBA_CONNECTION_P(zv)->info
348static void dba_connection_free_obj(
zend_object *obj)
350 dba_connection *connection = dba_connection_from_obj(obj);
352 if (connection->info) {
353 dba_close_connection(connection);
362 const dba_handler *hptr;
365 DBA_G(default_hptr) =
NULL;
366 return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
375 DBA_G(default_hptr) = hptr;
376 return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
380 STD_PHP_INI_ENTRY(
"dba.default_handler", DBA_DEFAULT,
PHP_INI_ALL, OnUpdateDefaultHandler, default_handler, zend_dba_globals, dba_globals)
387#if defined(COMPILE_DL_DBA) && defined(ZTS)
390 dba_globals->default_handler =
"";
391 dba_globals->default_hptr =
NULL;
407 register_dba_symbols(module_number);
409 dba_connection_ce = register_class_Dba_Connection();
410 dba_connection_ce->
create_object = dba_connection_create_object;
415 dba_connection_object_handlers.
free_obj = dba_connection_free_obj;
416 dba_connection_object_handlers.
get_constructor = dba_connection_get_constructor;
418 dba_connection_object_handlers.
cast_object = dba_connection_cast_object;
438 const dba_handler *hptr;
441 for(hptr =
handler; hptr->name; hptr++) {
442 smart_str_appends(&
handlers, hptr->name);
464 dba_info *info =
NULL;
475 info = Z_DBA_INFO_P(
id);
476 CHECK_DBA_CONNECTION(info);
477 DBA_WRITE_CHECK(info);
480 key_str = php_dba_make_key(key_ht);
488 DBA_RELEASE_HT_KEY_CREATION();
493static dba_info *php_dba_find(
const zend_string *path)
498 dba_info *info = Z_DBA_INFO_P(
zv);
499 if (info && zend_string_equals(path, info->path)) {
517 return duplicated_str;
525 const dba_handler *hptr;
527 int lock_mode, lock_flag = 0;
528 const char *file_mode;
529 const char *lock_file_mode =
NULL;
534 bool need_creation = 0;
542 zend_long driver_flags = DBA_DEFAULT_DRIVER_FLAGS;
543 bool is_flags_null =
true;
546 &permission, &map_size, &driver_flags, &is_flags_null)) {
558 if (handler_str &&
ZSTR_LEN(handler_str) == 0) {
568 if (!is_flags_null && driver_flags < 0) {
574 size_t resource_key_len =
spprintf(&resource_key, 0,
582 if ((le = zend_hash_str_find_ptr(&
EG(persistent_list), resource_key, resource_key_len)) !=
NULL) {
583 if (le->
type != le_pdb) {
590 dba_connection *connection = Z_DBA_CONNECTION_P(
return_value);
591 connection->info = (dba_info *)le->
ptr;
592 connection->hash = zend_string_init(resource_key, resource_key_len,
persistent);
597 if (zend_hash_exists(&DBA_G(connections), connection->hash)) {
608 hptr = DBA_G(default_hptr);
638 bool is_test_lock =
false;
639 bool is_db_lock =
false;
640 bool is_lock_ignored =
false;
662 if ((hptr->flags & DBA_LOCK_ALL) == 0) {
667 is_lock_ignored =
true;
672 if ((hptr->flags & DBA_LOCK_ALL) == 0) {
673 lock_flag = (hptr->flags & DBA_LOCK_ALL);
679 lock_flag = DBA_LOCK_ALL;
680 if ((hptr->flags & DBA_LOCK_ALL) == 0) {
690 lock_flag = (hptr->flags&DBA_LOCK_ALL);
697 lock_mode = (lock_flag & DBA_LOCK_READER) ?
LOCK_SH : 0;
702 lock_mode = (lock_flag & DBA_LOCK_WRITER) ?
LOCK_EX : 0;
707 if (hptr->flags & (DBA_NO_APPEND|DBA_CAST_AS_FD)) {
713 lock_mode = (lock_flag & DBA_LOCK_CREAT) ?
LOCK_EX : 0;
721 if (!need_creation) {
722 lock_file_mode =
"r+b";
725 lock_file_mode =
"a+b";
728 if (!need_creation) {
733 lock_file_mode =
"w+b";
737 if (!need_creation) {
750 lock_mode = (lock_flag & DBA_LOCK_TRUNC) ?
LOCK_EX : 0;
758 if (!lock_file_mode) {
759 lock_file_mode = file_mode;
762 if (is_lock_ignored) {
768 if ((hptr->flags & DBA_LOCK_ALL) == 0) {
782 zval *connection_zval;
783 dba_connection *connection;
784 if ((connection_zval =
zend_hash_str_find(&DBA_G(connections), resource_key, resource_key_len)) ==
NULL) {
789 connection->info->path = php_dba_zend_string_dup_safe(path,
persistent);
790 connection->info->mode = modenr;
791 connection->info->file_permission = permission;
792 connection->info->map_size = map_size;
793 connection->info->driver_flags = driver_flags;
794 connection->info->flags = (hptr->flags & ~DBA_LOCK_ALL) | (lock_flag & DBA_LOCK_ALL) | (
persistent ? DBA_PERSISTENT : 0);
795 connection->info->lock.mode = lock_mode;
796 connection->hash = zend_string_init(resource_key, resource_key_len,
persistent);
809 if (hptr->flags & DBA_LOCK_ALL) {
811 if ((other = php_dba_find(connection->info->path)) !=
NULL) {
815 error =
"Unable to establish lock (database file already open)";
823 if (!
error && lock_mode) {
828 if (!
strcmp(file_mode,
"r")) {
832 lock_file_mode =
"rb";
838 if (!connection->info->lock.fp) {
840 lock_file_mode =
"a+b";
843 if (!connection->info->lock.fp) {
846 if (connection->info->lock.fp) {
851 connection->info->path = php_dba_zend_string_dup_safe(opened_path,
persistent);
853 error =
"Unable to determine path for locking";
865 if (!connection->info->lock.fp) {
870 error =
"Stream does not support locking";
873 error =
"Unable to establish lock";
878 if (!
error && (hptr->flags&DBA_STREAM_OPEN)==DBA_STREAM_OPEN) {
879 if (connection->info->lock.fp && is_db_lock) {
880 connection->info->fp = connection->info->lock.fp;
884 if (!connection->info->fp) {
888 if (hptr->flags & (DBA_NO_APPEND|DBA_CAST_AS_FD)) {
896 }
else if (modenr == DBA_CREAT) {
897 int flags = fcntl(connection->info->fd, F_GETFL);
898 fcntl(connection->info->fd, F_SETFL,
flags & ~O_APPEND);
899#elif defined(PHP_WIN32)
900 }
else if (modenr == DBA_CREAT && need_creation && !restarted) {
901 if (connection->info->lock.fp !=
NULL) {
904 if (connection->info->fp != connection->info->lock.fp) {
907 connection->info->fp =
NULL;
908 connection->info->lock.fp =
NULL;
909 connection->info->fd = -1;
911 lock_file_mode =
"r+b";
931 connection->info->hnd = hptr;
937 dba_close_connection(connection);
949 dba_close_info(connection->info);
950 connection->info =
NULL;
974 dba_connection *connection =
NULL;
980 connection = Z_DBA_CONNECTION_P(
id);
981 CHECK_DBA_CONNECTION(connection->info);
983 bool persistent = connection->info->flags & DBA_PERSISTENT;
985 dba_close_connection(connection);
997 dba_info *info =
NULL;
1006 info = Z_DBA_INFO_P(
id);
1007 CHECK_DBA_CONNECTION(info);
1010 key_str = php_dba_make_key(key_ht);
1018 DBA_RELEASE_HT_KEY_CREATION();
1026 dba_info *info =
NULL;
1053 info = Z_DBA_INFO_P(
id);
1054 CHECK_DBA_CONNECTION(info);
1057 key_str = php_dba_make_key(key_ht);
1065 if (!
strcmp(info->hnd->name,
"cdb")) {
1071 }
else if (!
strcmp(info->hnd->name,
"inifile")) {
1090 if ((
val = info->hnd->fetch(info, key_str, skip)) ==
NULL) {
1091 DBA_RELEASE_HT_KEY_CREATION();
1094 DBA_RELEASE_HT_KEY_CREATION();
1130 dba_info *info =
NULL;
1136 info = Z_DBA_INFO_P(
id);
1137 CHECK_DBA_CONNECTION(info);
1153 dba_info *info =
NULL;
1159 info = Z_DBA_INFO_P(
id);
1160 CHECK_DBA_CONNECTION(info);
1177 dba_info *info =
NULL;
1186 info = Z_DBA_INFO_P(
id);
1187 CHECK_DBA_CONNECTION(info);
1188 DBA_WRITE_CHECK(info);
1191 key_str = php_dba_make_key(key_ht);
1199 DBA_RELEASE_HT_KEY_CREATION();
1223 dba_info *info =
NULL;
1229 info = Z_DBA_INFO_P(
id);
1230 CHECK_DBA_CONNECTION(info);
1231 DBA_WRITE_CHECK(info);
1233 if (info->hnd->optimize(info) ==
SUCCESS) {
1245 dba_info *info =
NULL;
1251 info = Z_DBA_INFO_P(
id);
1252 CHECK_DBA_CONNECTION(info);
1254 if (info->hnd->sync(info) ==
SUCCESS) {
1265 const dba_handler *hptr;
1274 for(hptr =
handler; hptr->name; hptr++) {
1277 char *str = hptr->info(hptr,
NULL);
1298 dba_connection *connection = Z_DBA_CONNECTION_P(
zv);
1299 if (connection->info) {
strchr(string $haystack, string $needle, bool $before_needle=false)
dba_handlers(bool $full_info=false)
dba_exists(string|array $key, Dba\Connection $dba)
dba_sync(Dba\Connection $dba)
dba_close(Dba\Connection $dba)
dba_delete(string|array $key, Dba\Connection $dba)
dba_key_split(string|false|null $key)
dba_nextkey(Dba\Connection $dba)
dba_insert(string|array $key, string $value, Dba\Connection $dba)
dba_optimize(Dba\Connection $dba)
dba_popen(string $path, string $mode, ?string $handler=null, int $permission=0o644, int $map_size=0, ?int $flags=null)
dba_open(string $path, string $mode, ?string $handler=null, int $permission=0o644, int $map_size=0, ?int $flags=null)
dba_replace(string|array $key, string $value, Dba\Connection $dba)
dba_fetch(string|array $key, $dba, $skip=0)
dba_firstkey(Dba\Connection $dba)
foreach($dp as $el) foreach( $dp as $el) if( $pass2< 2) echo ""
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
php_info_print_table_start()
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled")
php_info_print_table_end()
#define PHP_MSHUTDOWN_FUNCTION
#define PHP_MINIT_FUNCTION
#define PHP_MINFO_FUNCTION
#define PHP_GINIT_FUNCTION
#define PHP_GSHUTDOWN_FUNCTION
#define PHP_MODULE_GLOBALS
unsigned const char * pos
#define STD_PHP_INI_ENTRY
unsigned char key[REFLECTION_KEY_LEN]
#define php_stream_cast(stream, as, ret, show_err)
#define php_stream_stat_path(path, ssb)
#define php_stream_pclose(stream)
#define PHP_STREAM_FREE_CLOSE_PERSISTENT
#define php_stream_supports_lock(stream)
#define php_stream_free(stream, close_options)
#define php_stream_close(stream)
#define PHP_STREAM_FREE_CLOSE
#define STREAM_OPEN_PERSISTENT
#define php_stream_lock(stream, mode)
#define php_stream_open_wrapper(path, mode, options, opened)
struct _php_stream_statbuf php_stream_statbuf
zend_object *(* create_object)(zend_class_entry *class_type)
const zend_object_handlers * default_object_handlers
zend_object_compare_t compare
zend_object_free_obj_t free_obj
zend_object_cast_t cast_object
zend_object_get_constructor_t get_constructor
zend_object_clone_obj_t clone_obj
ZEND_API zend_string * zend_strpprintf(size_t max_len, const char *format,...)
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
ZEND_API ZEND_COLD void zend_error(int type, const char *format,...)
#define ZEND_TSRMLS_CACHE_UPDATE()
#define INTERNAL_FUNCTION_PARAMETERS
#define ZEND_TSRMLS_CACHE_DEFINE()
#define INTERNAL_FUNCTION_PARAM_PASSTHRU
ZEND_API zend_result add_next_index_stringl(zval *arg, const char *str, size_t length)
ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *class_type)
ZEND_API ZEND_COLD void zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format,...)
ZEND_API void add_index_str(zval *arg, zend_ulong index, zend_string *str)
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type)
ZEND_API ZEND_COLD void zend_argument_must_not_be_empty_error(uint32_t arg_num)
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
ZEND_API zend_result add_next_index_string(zval *arg, const char *str)
ZEND_API zend_result zend_parse_parameters_ex(int flags, uint32_t num_args, const char *type_spec,...)
#define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args)
#define ZEND_PARSE_PARAMS_QUIET
#define ZEND_PARSE_PARAMETERS_END()
#define ZEND_DECLARE_MODULE_GLOBALS(module_name)
#define ZEND_GET_MODULE(name)
#define zend_parse_parameters_none()
#define ZEND_PARSE_PARAMETERS_END_EX(failure)
#define Z_PARAM_STR(dest)
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
#define ZEND_END_MODULE_GLOBALS(module_name)
#define Z_PARAM_ARRAY_HT_OR_STR(dest_ht, dest_str)
#define Z_PARAM_LONG(dest)
#define Z_PARAM_OBJECT_OF_CLASS(dest, _ce)
#define ZEND_BEGIN_MODULE_GLOBALS(module_name)
#define pefree(ptr, persistent)
#define pecalloc(nmemb, size, persistent)
strcmp(string $string1, string $string2)
zend_string_release_ex(func->internal_function.function_name, 0)
#define strcasecmp(s1, s2)
union _zend_function zend_function
ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht)
ZEND_API zval *ZEND_FASTCALL zend_hash_str_find(const HashTable *ht, const char *str, size_t len)
ZEND_API zend_result ZEND_FASTCALL zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos)
ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos)
ZEND_API zval *ZEND_FASTCALL zend_hash_get_current_data_ex(HashTable *ht, HashPosition *pos)
ZEND_API void ZEND_FASTCALL zend_hash_apply_with_argument(HashTable *ht, apply_func_arg_t apply_func, void *argument)
ZEND_API zval *ZEND_FASTCALL zend_hash_add_new(HashTable *ht, zend_string *key, zval *pData)
ZEND_API zend_result ZEND_FASTCALL zend_hash_del(HashTable *ht, zend_string *key)
#define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent)
#define ZEND_HASH_MAP_FOREACH_VAL(ht, _val)
#define ZEND_HASH_APPLY_REMOVE
#define ZEND_HASH_APPLY_KEEP
#define ZEND_HASH_FOREACH_END()
#define UNREGISTER_INI_ENTRIES()
#define REGISTER_INI_ENTRIES()
#define DISPLAY_INI_ENTRIES()
#define ZEND_INI_MH(name)
ZEND_API zend_resource * zend_register_persistent_resource(const char *key, size_t key_len, void *rsrc_pointer, int rsrc_type)
ZEND_API int zend_register_list_destructors_ex(rsrc_dtor_func_t ld, rsrc_dtor_func_t pld, const char *type_name, int module_number)
struct _zend_string zend_string
#define STANDARD_MODULE_HEADER
struct _zend_module_entry zend_module_entry
#define STANDARD_MODULE_PROPERTIES_EX
ZEND_API zend_result zend_std_cast_object_tostring(zend_object *readobj, zval *writeobj, int type)
ZEND_API int zend_objects_not_comparable(zval *o1, zval *o2)
ZEND_API const zend_object_handlers std_object_handlers
ZEND_API void ZEND_FASTCALL zend_object_std_init(zend_object *object, zend_class_entry *ce)
ZEND_API void zend_object_std_dtor(zend_object *object)
#define EXPECTED(condition)
#define zend_always_inline
#define XtOffsetOf(s_type, field)
#define UNEXPECTED(condition)
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
#define ZSTR_IS_INTERNED(s)
struct _zend_resource zend_resource
struct _zend_array HashTable
#define GC_MAKE_PERSISTENT_LOCAL(p)
ZEND_RESULT_CODE zend_result
struct _zend_object_handlers zend_object_handlers
ZEND_API void zval_ptr_dtor(zval *zval_ptr)
fbc internal_function handler(call, ret)