diff options
Diffstat (limited to 'ext/dba')
57 files changed, 0 insertions, 6336 deletions
diff --git a/ext/dba/CREDITS b/ext/dba/CREDITS deleted file mode 100644 index 370b3ea271..0000000000 --- a/ext/dba/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -DBA -Sascha Schumann, Marcus Boerger
\ No newline at end of file diff --git a/ext/dba/config.m4 b/ext/dba/config.m4 deleted file mode 100644 index 5594bfb725..0000000000 --- a/ext/dba/config.m4 +++ /dev/null @@ -1,432 +0,0 @@ -dnl -dnl $Id$ -dnl - -dnl Suppose we need FlatFile if no support or only CDB is used. - -AC_DEFUN(PHP_DBA_STD_BEGIN,[ - unset THIS_INCLUDE THIS_LIBS THIS_LFLAGS THIS_PREFIX THIS_RESULT -]) - -AC_DEFUN(PHP_TEMP_LDFLAGS,[ - old_LDFLAGS=$LDFLAGS - LDFLAGS="$1 $LDFLAGS" - $2 - LDFLAGS=$old_LDFLAGS -]) - -dnl Assign INCLUDE/LFLAGS from PREFIX -AC_DEFUN(PHP_DBA_STD_ASSIGN,[ - if test -n "$THIS_PREFIX" && test "$THIS_PREFIX" != "/usr"; then - THIS_LFLAGS=$THIS_PREFIX/lib - fi -]) - -dnl Standard check -AC_DEFUN(PHP_DBA_STD_CHECK,[ - THIS_RESULT="yes" - if test -z "$THIS_INCLUDE"; then - AC_MSG_ERROR(cannot find necessary header file(s)) - fi - if test -z "$THIS_LIBS"; then - AC_MSG_ERROR(cannot find necessary library) - fi -]) - -dnl Attach THIS_x to DBA_x -AC_DEFUN(PHP_DBA_STD_ATTACH,[ - PHP_ADD_LIBRARY_WITH_PATH($THIS_LIBS, $THIS_LFLAGS, DBA_SHARED_LIBADD) - unset THIS_INCLUDE THIS_LIBS THIS_LFLAGS THIS_PREFIX -]) - -dnl Print the result message -dnl parameters(name [, full name [, empty or error message]]) -AC_DEFUN(AC_DBA_STD_RESULT,[ - THIS_NAME=[]translit($1,a-z0-9-,A-Z0-9_) - if test -n "$2"; then - THIS_FULL_NAME="$2" - else - THIS_FULL_NAME="$THIS_NAME" - fi - AC_MSG_CHECKING(for $THIS_FULL_NAME support) - if test -n "$3"; then - AC_MSG_ERROR($3) - fi - if test "$THIS_RESULT" = "yes" -o "$THIS_RESULT" = "builtin"; then - HAVE_DBA=1 - eval HAVE_$THIS_NAME=1 - AC_MSG_RESULT($THIS_RESULT) - else - AC_MSG_RESULT(no) - fi - unset THIS_RESULT THIS_NAME THIS_FULL_NAME -]) - -PHP_ARG_ENABLE(dba,whether to enable DBA, -[ --enable-dba Build DBA with builtin modules]) - -AC_ARG_WITH(gdbm, -[ --with-gdbm[=DIR] DBA: Include GDBM support],[ - if test "$withval" != "no"; then - PHP_DBA_STD_BEGIN - for i in $withval /usr/local /usr; do - if test -f "$i/include/gdbm.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/gdbm.h - break - fi - done - - if test -n "$THIS_INCLUDE"; then - unset ac_cv_lib_gdbm_gdbm_open - PHP_TEMP_LDFLAGS(-L$THIS_PREFIX/lib,[ - AC_CHECK_LIB(gdbm, gdbm_open, [ - AC_DEFINE_UNQUOTED(GDBM_INCLUDE_FILE, "$THIS_INCLUDE", [ ]) - AC_DEFINE(DBA_GDBM, 1, [ ]) - THIS_LIBS=gdbm - ]) - ]) - fi - - PHP_DBA_STD_ASSIGN - PHP_DBA_STD_CHECK - PHP_DBA_STD_ATTACH - fi -]) -AC_DBA_STD_RESULT(gdbm) - -AC_ARG_WITH(ndbm, -[ --with-ndbm[=DIR] DBA: Include NDBM support],[ - if test "$withval" != "no"; then - PHP_DBA_STD_BEGIN - for i in $withval /usr/local /usr; do - if test -f "$i/include/ndbm.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/ndbm.h - break - elif test -f "$i/include/db1/ndbm.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/db1/ndbm.h - break - fi - done - - if test -n "$THIS_INCLUDE"; then - for LIB in ndbm db1 c; do - PHP_TEMP_LDFLAGS(-L$THIS_PREFIX/lib,[ - AC_CHECK_LIB($LIB, dbm_open, [ - AC_DEFINE_UNQUOTED(NDBM_INCLUDE_FILE, "$THIS_INCLUDE", [ ]) - AC_DEFINE(DBA_NDBM,1, [ ]) - THIS_LIBS=$LIB - break - ]) - ]) - done - fi - - PHP_DBA_STD_ASSIGN - PHP_DBA_STD_CHECK - PHP_DBA_STD_ATTACH - fi -]) -AC_DBA_STD_RESULT(ndbm) - -dnl Berkeley specific (library and version test) -dnl parameters(version, library list, function) -AC_DEFUN(PHP_DBA_DB_CHECK,[ - for LIB in $2; do - if test -f $THIS_PREFIX/lib/lib$LIB.a -o -f $THIS_PREFIX/lib/lib$LIB.$SHLIB_SUFFIX_NAME; then - PHP_TEMP_LDFLAGS(-L$THIS_PREFIX/lib,[ - AC_CHECK_LIB($LIB, $3, [ - AC_EGREP_CPP(yes,[ -#include "$THIS_INCLUDE" - yes -#endif - ],[ - THIS_LIBS=$LIB - break - ]) - ]) - ]) - fi - done - if test "$1" = "4"; then - AC_MSG_CHECKING(for db4 minor version and patch level) - AC_EGREP_CPP(yes,[ -#include "$THIS_INCLUDE" -#if DB_VERSION_MINOR != 1 || DB_VERSION_PATCH >= 25 - yes -#endif - ],[ - AC_MSG_RESULT(ok) - ],[ - AC_MSG_ERROR(Version 4.1 requires patch level 25) - ]) - fi - if test "$ext_shared" = "yes"; then - AC_MSG_CHECKING(if db can be used as shared extension) - AC_EGREP_CPP(yes,[ -#include "$THIS_INCLUDE" -#if DB_VERSION_MAJOR > 3 || (DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR > 2) - yes -#endif - ],[ - AC_MSG_RESULT(yes) - ],[ - AC_MSG_ERROR(At least version 3.3 is required) - ]) - fi - if test -n "$THIS_LIBS"; then - AC_DEFINE(DBA_DB$1, 1, [ ]) - if test -n "$THIS_INCLUDE"; then - AC_DEFINE_UNQUOTED(DB$1_INCLUDE_FILE, "$THIS_INCLUDE", [ ]) - fi - fi - PHP_DBA_STD_ASSIGN - PHP_DBA_STD_CHECK - PHP_DBA_STD_ATTACH -]) - -AC_ARG_WITH(db4, -[ --with-db4[=DIR] DBA: Include Berkeley DB4 support],[ - if test "$withval" != "no"; then - PHP_DBA_STD_BEGIN - for i in $withval /usr/local/BerkeleyDB.4.1 /usr/local/BerkeleyDB.4.0 /usr/local /usr; do - if test -f "$i/db4/db.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/db4/db.h - break - elif test -f "$i/include/db4/db.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/db4/db.h - break - elif test -f "$i/include/db/db4.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/db/db4.h - break - elif test -f "$i/include/db4.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/db4.h - break - elif test -f "$i/include/db.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/db.h - break - fi - done - PHP_DBA_DB_CHECK(4, db-4.1 db-4.0 db-4 db4 db, db_create) - fi -]) -AC_DBA_STD_RESULT(db4,Berkeley DB4) - -AC_ARG_WITH(db3, -[ --with-db3[=DIR] DBA: Include Berkeley DB3 support],[ - if test "$withval" != "no"; then - PHP_DBA_STD_BEGIN - if test "$HAVE_DB4" = "1"; then - AC_DBA_STD_RESULT(db3,Berkeley DB3,You cannot combine --with-db3 with --with-db4) - fi - for i in $withval /usr/local/BerkeleyDB.3.3 /usr/local/BerkeleyDB.3.2 /usr/local/BerkeleyDB.3.1 /usr/local/BerkeleyDB.3.0 /usr/local /usr; do - if test -f "$i/db3/db.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/db3/db.h - break - elif test -f "$i/include/db3/db.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/db3/db.h - break - elif test -f "$i/include/db/db3.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/db/db3.h - break - elif test -f "$i/include/db3.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/db3.h - break - elif test -f "$i/include/db.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/db.h - break - fi - done - PHP_DBA_DB_CHECK(3, db-3.3 db-3.2 db-3.1 db-3.0 db-3 db3 db, db_create) - fi - ]) -AC_DBA_STD_RESULT(db3,Berkeley DB3) - -AC_ARG_WITH(db2, -[ --with-db2[=DIR] DBA: Include Berkeley DB2 support],[ - if test "$withval" != "no"; then - PHP_DBA_STD_BEGIN - if test "$HAVE_DB3" = "1" -o "$HAVE_DB4" = "1"; then - AC_DBA_STD_RESULT(db2,Berkeley DB2,You cannot combine --with-db2 with --with-db3 or --with-db4) - fi - for i in $withval $withval/BerkeleyDB /usr/BerkeleyDB /usr/local /usr; do - if test -f "$i/db2/db.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/db2/db.h - break - elif test -f "$i/include/db2/db.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/db2/db.h - break - elif test -f "$i/include/db/db2.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/db/db2.h - break - elif test -f "$i/include/db2.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/db2.h - break - elif test -f "$i/include/db.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/db.h - break - fi - done - PHP_DBA_DB_CHECK(2, db-2 db2 db, db_appinit) - fi -]) -AC_DBA_STD_RESULT(db2,Berkeley DB2) - -AC_ARG_WITH(dbm, -[ --with-dbm[=DIR] DBA: Include DBM support],[ - if test "$withval" != "no"; then - PHP_DBA_STD_BEGIN - for i in $withval /usr/local /usr; do - if test -f "$i/include/dbm.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/dbm.h - break - elif test -f "$i/include/gdbm/dbm.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/gdbm/dbm.h - break - fi - done - - if test -n "$THIS_INCLUDE"; then - for LIB in dbm c gdbm; do - PHP_TEMP_LDFLAGS(-L$THIS_PREFIX/lib,[ - AC_CHECK_LIB($LIB, dbminit, [ - AC_MSG_CHECKING(for DBM using GDBM) - AC_DEFINE_UNQUOTED(DBM_INCLUDE_FILE, "$THIS_INCLUDE", [ ]) - if test "$LIB" = "gdbm"; then - AC_DEFINE_UNQUOTED(DBM_VERSION, "GDBM", [ ]) - AC_MSG_RESULT(yes) - else - AC_DEFINE_UNQUOTED(DBM_VERSION, "DBM", [ ]) - AC_MSG_RESULT(no) - fi - AC_DEFINE(DBA_DBM,1,[ ]) - THIS_LIBS=$LIB - break - ]) - ]) - done - fi - - PHP_DBA_STD_ASSIGN - PHP_DBA_STD_CHECK - PHP_DBA_STD_ATTACH - fi -]) -AC_DBA_STD_RESULT(dbm) - -AC_DEFUN(PHP_DBA_BUILTIN_CDB,[ - PHP_ADD_BUILD_DIR($ext_builddir/libcdb) - AC_DEFINE(DBA_CDB_BUILTIN, 1, [ ]) - AC_DEFINE(DBA_CDB_MAKE, 1, [ ]) - AC_DEFINE(DBA_CDB, 1, [ ]) - cdb_sources="libcdb/cdb.c libcdb/cdb_make.c libcdb/uint32.c" - THIS_RESULT="builtin" -]) - -AC_ARG_WITH(cdb, -[ --with-cdb[=DIR] DBA: Include CDB support],[ - if test "$withval" = "yes"; then - PHP_DBA_BUILTIN_CDB - elif test "$withval" != "no"; then - PHP_DBA_STD_BEGIN - for i in $withval /usr/local /usr; do - if test -f "$i/include/cdb.h"; then - THIS_PREFIX=$i - THIS_INCLUDE=$i/include/cdb.h - break - fi - done - - if test -n "$THIS_INCLUDE"; then - for LIB in cdb c; do - PHP_TEMP_LDFLAGS(-L$THIS_PREFIX/lib,[ - AC_CHECK_LIB($LIB, cdb_read, [ - AC_DEFINE_UNQUOTED(CDB_INCLUDE_FILE, "$THIS_INCLUDE", [ ]) - AC_DEFINE(DBA_CDB,1,[ ]) - THIS_LIBS=$LIB - break - ]) - ]) - done - fi - - PHP_DBA_STD_ASSIGN - PHP_DBA_STD_CHECK - PHP_DBA_STD_ATTACH - fi -],[ - if test "$PHP_DBA" != "no"; then - PHP_DBA_BUILTIN_CDB - fi -]) -AC_DBA_STD_RESULT(cdb) - -AC_DEFUN(PHP_DBA_BUILTIN_INI,[ - PHP_ADD_BUILD_DIR($ext_builddir/libini) - AC_DEFINE(DBA_INIFILE, 1, [ ]) - ini_sources="libinifile/inifile.c" - THIS_RESULT="builtin" -]) - -AC_ARG_WITH(inifile, -[ --with-inifile DBA: Include INI support],[ - if test "$withval" != "no"; then - PHP_DBA_BUILTIN_INI - fi -],[ - if test "$PHP_DBA" != "no"; then - PHP_DBA_BUILTIN_INI - fi -]) -AC_DBA_STD_RESULT(inifile,INI File) - -AC_DEFUN(PHP_DBA_BUILTIN_FLATFILE,[ - PHP_ADD_BUILD_DIR($ext_builddir/libflatfile) - AC_DEFINE(DBA_FLATFILE, 1, [ ]) - flat_sources="libflatfile/flatfile.c" - THIS_RESULT="builtin" -]) - -dnl -dnl FlatFile check must be the last one. -dnl -AC_ARG_WITH(flatfile, -[ --with-flatfile DBA: Include FlatFile support],[ - if test "$withval" != "no"; then - PHP_DBA_BUILTIN_FLATFILE - fi -],[ - if test "$PHP_DBA" != "no"; then - PHP_DBA_BUILTIN_FLATFILE - fi -]) -AC_DBA_STD_RESULT(FlatFile,FlatFile) - -AC_MSG_CHECKING(whether to enable DBA interface) -if test "$HAVE_DBA" = "1"; then - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_DBA, 1, [ ]) - PHP_NEW_EXTENSION(dba, dba.c dba_cdb.c dba_db2.c dba_dbm.c dba_gdbm.c dba_ndbm.c dba_db3.c dba_db4.c dba_flatfile.c dba_inifile.c $cdb_sources $flat_sources $ini_sources, $ext_shared) - PHP_SUBST(DBA_SHARED_LIBADD) -else - AC_MSG_RESULT(no) -fi diff --git a/ext/dba/dba.c b/ext/dba/dba.c deleted file mode 100644 index 76ab42b31b..0000000000 --- a/ext/dba/dba.c +++ /dev/null @@ -1,1004 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Sascha Schumann <sascha@schumann.cx> | - | Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#if HAVE_DBA - -#include "php_ini.h" -#include "ext/standard/flock_compat.h" -#include <stdio.h> -#include <fcntl.h> -#ifdef HAVE_SYS_FILE_H -#include <sys/file.h> -#endif - -#include "php_dba.h" -#include "ext/standard/info.h" -#include "ext/standard/php_string.h" - -#include "php_gdbm.h" -#include "php_ndbm.h" -#include "php_dbm.h" -#include "php_cdb.h" -#include "php_db2.h" -#include "php_db3.h" -#include "php_db4.h" -#include "php_flatfile.h" -#include "php_inifile.h" - -/* {{{ dba_functions[] - */ -function_entry dba_functions[] = { - PHP_FE(dba_open, NULL) - PHP_FALIAS(dba_popen, dba_open, NULL) - /* Disabled until 4.3.1, when persistent STDIO streams are implemented. */ - /* PHP_FE(dba_popen, NULL) */ - PHP_FE(dba_close, NULL) - PHP_FE(dba_delete, NULL) - PHP_FE(dba_exists, NULL) - PHP_FE(dba_fetch, NULL) - PHP_FE(dba_insert, NULL) - PHP_FE(dba_replace, NULL) - PHP_FE(dba_firstkey, NULL) - PHP_FE(dba_nextkey, NULL) - PHP_FE(dba_optimize, NULL) - PHP_FE(dba_sync, NULL) - PHP_FE(dba_handlers, NULL) - PHP_FE(dba_list, NULL) - {NULL, NULL, NULL} -}; -/* }}} */ - -PHP_MINIT_FUNCTION(dba); -PHP_MSHUTDOWN_FUNCTION(dba); -PHP_MINFO_FUNCTION(dba); - -zend_module_entry dba_module_entry = { - STANDARD_MODULE_HEADER, - "dba", - dba_functions, - PHP_MINIT(dba), - PHP_MSHUTDOWN(dba), - NULL, - NULL, - PHP_MINFO(dba), - NO_VERSION_YET, - STANDARD_MODULE_PROPERTIES -}; - -#ifdef COMPILE_DL_DBA -ZEND_GET_MODULE(dba) -#endif - -/* {{{ macromania */ - -#define DBA_ID_PARS \ - zval **id; \ - dba_info *info = NULL; \ - int ac = ZEND_NUM_ARGS() - -/* these are used to get the standard arguments */ - -#define DBA_GET1 \ - if(ac != 1 || zend_get_parameters_ex(ac, &id) != SUCCESS) { \ - WRONG_PARAM_COUNT; \ - } - -/* {{{ php_dba_myke_key */ -static size_t php_dba_make_key(zval **key, char **key_str, char **key_free TSRMLS_DC) -{ - if (Z_TYPE_PP(key) == IS_ARRAY) { - zval **group, **name; - HashPosition pos; - size_t len; - - if (zend_hash_num_elements(Z_ARRVAL_PP(key)) != 2) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Key does not have exactly two elements: (key, name)"); - return -1; - } - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(key), &pos); - zend_hash_get_current_data_ex(Z_ARRVAL_PP(key), (void **) &group, &pos); - zend_hash_move_forward_ex(Z_ARRVAL_PP(key), &pos); - zend_hash_get_current_data_ex(Z_ARRVAL_PP(key), (void **) &name, &pos); - convert_to_string_ex(group); - convert_to_string_ex(name); - if (Z_STRLEN_PP(group) == 0) { - *key_str = Z_STRVAL_PP(name); - *key_free = NULL; - return Z_STRLEN_PP(name); - } - len = spprintf(key_str, 0, "[%s]%s", Z_STRVAL_PP(group), Z_STRVAL_PP(name)); - *key_free = *key_str; - return len; - } else { - convert_to_string_ex(key); - *key_str = Z_STRVAL_PP(key); - *key_free = NULL; - return Z_STRLEN_PP(key); - } -} -/* }}} */ - -#define DBA_GET2 \ - zval **key; \ - char *key_str, *key_free; \ - size_t key_len; \ - if(ac != 2 || zend_get_parameters_ex(ac, &key, &id) != SUCCESS) { \ - WRONG_PARAM_COUNT; \ - } \ - if ((key_len = php_dba_make_key(key, &key_str, &key_free TSRMLS_CC) < 0)) {\ - RETURN_FALSE; \ - } - -#define DBA_GET2_3 \ - zval **key; \ - char *key_str, *key_free; \ - size_t key_len; \ - zval **tmp; \ - int skip = 0; \ - switch(ac) { \ - case 2: \ - if (zend_get_parameters_ex(ac, &key, &id) != SUCCESS) { \ - WRONG_PARAM_COUNT; \ - } \ - break; \ - case 3: \ - if (zend_get_parameters_ex(ac, &key, &tmp, &id) != SUCCESS) { \ - WRONG_PARAM_COUNT; \ - } \ - convert_to_long_ex(tmp); \ - skip = Z_LVAL_PP(tmp); \ - break; \ - default: \ - WRONG_PARAM_COUNT; \ - } \ - if ((key_len = php_dba_make_key(key, &key_str, &key_free TSRMLS_CC) < 0)) {\ - RETURN_FALSE; \ - } - -#define DBA_GET3 \ - zval **key, **val; \ - char *key_str, *key_free; \ - size_t key_len; \ - if(ac != 3 || zend_get_parameters_ex(ac, &key, &val, &id) != SUCCESS) { \ - WRONG_PARAM_COUNT; \ - } \ - convert_to_string_ex(val); \ - if ((key_len = php_dba_make_key(key, &key_str, &key_free TSRMLS_CC) < 0)) {\ - RETURN_FALSE; \ - } - -#define DBA_ID_GET \ - ZEND_FETCH_RESOURCE2(info, dba_info *, id, -1, "DBA identifier", le_db, le_pdb); - -#define DBA_ID_GET1 DBA_ID_PARS; DBA_GET1; DBA_ID_GET -#define DBA_ID_GET2 DBA_ID_PARS; DBA_GET2; DBA_ID_GET -#define DBA_ID_GET2_3 DBA_ID_PARS; DBA_GET2_3; DBA_ID_GET -#define DBA_ID_GET3 DBA_ID_PARS; DBA_GET3; DBA_ID_GET - -#define DBA_ID_DONE \ - if (key_free) efree(key_free) -/* a DBA handler must have specific routines */ - -#define DBA_NAMED_HND(alias, name, flags) \ -{\ - #alias, flags, dba_open_##name, dba_close_##name, dba_fetch_##name, dba_update_##name, \ - dba_exists_##name, dba_delete_##name, dba_firstkey_##name, dba_nextkey_##name, \ - dba_optimize_##name, dba_sync_##name, dba_info_##name \ -}, - -#define DBA_HND(name, flags) DBA_NAMED_HND(name, name, flags) - -/* check whether the user has write access */ -#define DBA_WRITE_CHECK \ - if(info->mode != DBA_WRITER && info->mode != DBA_TRUNC && info->mode != DBA_CREAT) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "You cannot perform a modification to a database without proper access"); \ - RETURN_FALSE; \ - } - -/* }}} */ - -/* {{{ globals */ - -static dba_handler handler[] = { -#if DBA_GDBM - DBA_HND(gdbm, DBA_LOCK_EXT) /* Locking done in library if set */ -#endif -#if DBA_DBM - DBA_HND(dbm, DBA_LOCK_ALL) /* No lock in lib */ -#endif -#if DBA_NDBM - DBA_HND(ndbm, DBA_LOCK_ALL) /* Could be done in library: filemode = 0644 + S_ENFMT */ -#endif -#if DBA_CDB - DBA_HND(cdb, DBA_STREAM_OPEN|DBA_LOCK_ALL) /* No lock in lib */ -#endif -#if DBA_CDB_BUILTIN - DBA_NAMED_HND(cdb_make, cdb, DBA_STREAM_OPEN|DBA_LOCK_ALL) /* No lock in lib */ -#endif -#if DBA_DB2 - DBA_HND(db2, DBA_LOCK_ALL) /* No lock in lib */ -#endif -#if DBA_DB3 - DBA_HND(db3, DBA_LOCK_ALL) /* No lock in lib */ -#endif -#if DBA_DB4 - DBA_HND(db4, DBA_LOCK_ALL) /* No lock in lib */ -#endif -#if DBA_INIFILE - DBA_HND(inifile, DBA_STREAM_OPEN|DBA_LOCK_ALL) /* No lock in lib */ -#endif -#if DBA_FLATFILE - DBA_HND(flatfile, DBA_STREAM_OPEN|DBA_LOCK_ALL) /* No lock in lib */ -#endif - { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } -}; - -#if DBA_FLATFILE -#define DBA_DEFAULT "flatfile" -#elif DBA_DB4 -#define DBA_DEFAULT "db4" -#elif DBA_DB3 -#define DBA_DEFAULT "db3" -#elif DBA_DB2 -#define DBA_DEFAULT "db2" -#elif DBA_GDBM -#define DBA_DEFAULT "gdbm" -#elif DBA_NBBM -#define DBA_DEFAULT "ndbm" -#elif DBA_DBM -#define DBA_DEFAULT "dbm" -#else -#define DBA_DEFAULT "" -#endif -/* cdb/cdb_make and ini are no option here */ - -ZEND_BEGIN_MODULE_GLOBALS(dba) - char *default_handler; - dba_handler *default_hptr; -ZEND_END_MODULE_GLOBALS(dba) - -ZEND_DECLARE_MODULE_GLOBALS(dba) - -#ifdef ZTS -#define DBA_G(v) TSRMG(dba_globals_id, zend_dba_globals *, v) -#else -#define DBA_G(v) (dba_globals.v) -#endif - -static int le_db; -static int le_pdb; - -/* {{{ dba_fetch_resource -PHPAPI void dba_fetch_resource(dba_info **pinfo, zval **id TSRMLS_DC) -{ - dba_info *info; - DBA_ID_FETCH - *pinfo = info; -} -*/ -/* }}} */ - -/* {{{ dba_get_handler -PHPAPI dba_handler *dba_get_handler(const char* handler_name) -{ - dba_handler *hptr; - for (hptr = handler; hptr->name && strcasecmp(hptr->name, handler_name); hptr++); - return hptr; -} -*/ -/* }}} */ - -/* {{{ dba_close - */ -static void dba_close(dba_info *info TSRMLS_DC) -{ - if (info->hnd) info->hnd->close(info TSRMLS_CC); - if (info->path) pefree(info->path, info->flags&DBA_PERSISTENT); - if (info->fp && info->fp!=info->lock.fp) php_stream_close(info->fp); - if (info->lock.fd) { - php_flock(info->lock.fd, LOCK_UN); - /*close(info->lock.fd);*/ - info->lock.fd = 0; - } - if (info->lock.fp) php_stream_close(info->lock.fp); - if (info->lock.name) pefree(info->lock.name, info->flags&DBA_PERSISTENT); - pefree(info, info->flags&DBA_PERSISTENT); -} -/* }}} */ - -/* {{{ dba_close_rsrc - */ -static void dba_close_rsrc(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - dba_info *info = (dba_info *)rsrc->ptr; - - dba_close(info TSRMLS_CC); -} -/* }}} */ - -/* {{{ PHP_INI - */ -ZEND_INI_MH(OnUpdateDefaultHandler) -{ - dba_handler *hptr; - - if (!strlen(new_value)) { - DBA_G(default_hptr) = NULL; - return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); - } - - for (hptr = handler; hptr->name && strcasecmp(hptr->name, new_value); hptr++); - - if (!hptr->name) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such handler: %s", new_value); - return FAILURE; - } - DBA_G(default_hptr) = hptr; - return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); -} - -PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("dba.default_handler", DBA_DEFAULT, PHP_INI_ALL, OnUpdateDefaultHandler, default_handler, zend_dba_globals, dba_globals) -PHP_INI_END() -/* }}} */ - -/* {{{ php_dba_init_globals - */ -static void php_dba_init_globals(zend_dba_globals *dba_globals) -{ - dba_globals->default_handler = ""; - dba_globals->default_hptr = NULL; -} -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION - */ -PHP_MINIT_FUNCTION(dba) -{ - ZEND_INIT_MODULE_GLOBALS(dba, php_dba_init_globals, NULL); - REGISTER_INI_ENTRIES(); - le_db = zend_register_list_destructors_ex(dba_close_rsrc, NULL, "dba", module_number); - le_pdb = zend_register_list_destructors_ex(NULL, dba_close_rsrc, "dba persistent", module_number); - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MSHUTDOWN_FUNCTION - */ -PHP_MSHUTDOWN_FUNCTION(dba) -{ - UNREGISTER_INI_ENTRIES(); - return SUCCESS; -} -/* }}} */ - -#include "ext/standard/php_smart_str.h" - -/* {{{ PHP_MINFO_FUNCTION - */ -PHP_MINFO_FUNCTION(dba) -{ - dba_handler *hptr; - smart_str handlers = {0}; - - for(hptr = handler; hptr->name; hptr++) { - smart_str_appends(&handlers, hptr->name); - smart_str_appendc(&handlers, ' '); - } - - php_info_print_table_start(); - php_info_print_table_row(2, "DBA support", "enabled"); - if (handlers.c) { - smart_str_0(&handlers); - php_info_print_table_row(2, "Supported handlers", handlers.c); - smart_str_free(&handlers); - } else { - php_info_print_table_row(2, "Supported handlers", "none"); - } - php_info_print_table_end(); -} -/* }}} */ - -/* {{{ php_dba_update - */ -static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode) -{ - char *v; - int len; - DBA_ID_GET3; - - DBA_WRITE_CHECK; - - if (PG(magic_quotes_runtime)) { - len = Z_STRLEN_PP(val); - v = estrndup(Z_STRVAL_PP(val), len); - php_stripslashes(v, &len TSRMLS_CC); - if(info->hnd->update(info, key_str, key_len, v, len, mode TSRMLS_CC) == SUCCESS) { - efree(v); - DBA_ID_DONE; - RETURN_TRUE; - } - efree(v); - } else { - if(info->hnd->update(info, key_str, key_len, VALLEN(val), mode TSRMLS_CC) == SUCCESS) - { - DBA_ID_DONE; - RETURN_TRUE; - } - } - DBA_ID_DONE; - RETURN_FALSE; -} -/* }}} */ - -#define FREENOW if(args) efree(args); if(key) efree(key) - -/* {{{ php_find_dbm - */ -dba_info *php_dba_find(const char* path TSRMLS_DC) -{ - list_entry *le; - dba_info *info; - int numitems, i; - - numitems = zend_hash_next_free_element(&EG(regular_list)); - for (i=1; i<numitems; i++) { - if (zend_hash_index_find(&EG(regular_list), i, (void **) &le)==FAILURE) { - continue; - } - if (Z_TYPE_P(le) == le_db || Z_TYPE_P(le) == le_pdb) { - info = (dba_info *)(le->ptr); - if (!strcmp(info->path, path)) { - return (dba_info *)(le->ptr); - } - } - } - - return NULL; -} -/* }}} */ - -/* {{{ php_dba_open - */ -static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) -{ - zval ***args = (zval ***) NULL; - int ac = ZEND_NUM_ARGS(); - dba_mode_t modenr; - dba_info *info, *other; - dba_handler *hptr; - char *key = NULL, *error = NULL; - int keylen = 0; - int i; - int lock_mode, lock_flag, lock_dbf = 0; - char *file_mode; - char mode[4], *pmode, *lock_file_mode = NULL; - - if(ac < 2) { - WRONG_PARAM_COUNT; - } - - /* we pass additional args to the respective handler */ - args = emalloc(ac * sizeof(zval *)); - if (zend_get_parameters_array_ex(ac, args) != SUCCESS) { - FREENOW; - WRONG_PARAM_COUNT; - } - - /* we only take string arguments */ - for (i = 0; i < ac; i++) { - convert_to_string_ex(args[i]); - keylen += Z_STRLEN_PP(args[i]); - } - - if (persistent) { - list_entry *le; - - /* calculate hash */ - key = emalloc(keylen); - keylen = 0; - - for(i = 0; i < ac; i++) { - memcpy(key+keylen, Z_STRVAL_PP(args[i]), Z_STRLEN_PP(args[i])); - keylen += Z_STRLEN_PP(args[i]); - } - - /* try to find if we already have this link in our persistent list */ - if (zend_hash_find(&EG(persistent_list), key, keylen+1, (void **) &le) == SUCCESS) { - FREENOW; - - if (Z_TYPE_P(le) != le_pdb) { - RETURN_FALSE; - } - - info = (dba_info *)le->ptr; - - ZEND_REGISTER_RESOURCE(return_value, info, le_pdb); - return; - } - } - - if (ac==2) { - hptr = DBA_G(default_hptr); - if (!hptr) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "No default handler selected"); - FREENOW; - RETURN_FALSE; - } - } else { - for (hptr = handler; hptr->name && strcasecmp(hptr->name, Z_STRVAL_PP(args[2])); hptr++); - } - - if (!hptr->name) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "No such handler: %s", Z_STRVAL_PP(args[2])); - FREENOW; - RETURN_FALSE; - } - - /* Check mode: [rwnc][fl]?t? - * r: Read - * w: Write - * n: Create/Truncate - * c: Create - * - * d: force lock on database file - * l: force lock on lck file - * -: ignore locking - * - * t: test open database, warning if locked - */ - strlcpy(mode, Z_STRVAL_PP(args[1]), sizeof(mode)); - pmode = &mode[0]; - if (pmode[0] && (pmode[1]=='d' || pmode[1]=='l' || pmode[1]=='-')) { /* force lock on db file or lck file or disable locking */ - switch (pmode[1]) { - case 'd': - lock_dbf = 1; - if ((hptr->flags & DBA_LOCK_ALL) == 0) { - lock_flag = (hptr->flags & DBA_LOCK_ALL); - break; - } - /* no break */ - case 'l': - lock_flag = DBA_LOCK_ALL; - if ((hptr->flags & DBA_LOCK_ALL) == 0) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_NOTICE, "Handler %s does locking internally", hptr->name); - } - break; - default: - case '-': - if ((hptr->flags & DBA_LOCK_ALL) == 0) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Locking cannot be disabled for handler %s", hptr->name); - FREENOW; - RETURN_FALSE; - } - lock_flag = 0; - break; - } - } else { - lock_flag = (hptr->flags&DBA_LOCK_ALL); - lock_dbf = 1; - } - switch (*pmode++) { - case 'r': - modenr = DBA_READER; - lock_mode = (lock_flag & DBA_LOCK_READER) ? LOCK_SH : 0; - file_mode = "r"; - break; - case 'w': - modenr = DBA_WRITER; - lock_mode = (lock_flag & DBA_LOCK_WRITER) ? LOCK_EX : 0; - file_mode = "r+b"; - break; - case 'n': - modenr = DBA_TRUNC; - lock_mode = (lock_flag & DBA_LOCK_TRUNC) ? LOCK_EX : 0; - file_mode = "w+b"; - break; - case 'c': - modenr = DBA_CREAT; - lock_mode = (lock_flag & DBA_LOCK_CREAT) ? LOCK_EX : 0; - file_mode = "a+b"; - break; - default: - modenr = 0; - lock_mode = 0; - file_mode = ""; - } - if (*pmode=='d' || *pmode=='l' || *pmode=='-') { - pmode++; /* done already - skip here */ - } - if (*pmode=='t') { - pmode++; - if (!lock_flag) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "You cannot combine modifiers - (no lock) and t (test lock)", hptr->name); - FREENOW; - RETURN_FALSE; - } - if (!lock_mode) { - if ((hptr->flags & DBA_LOCK_ALL) == 0) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Handler %s uses its own locking which doesn't support mode modifier t (test lock)", hptr->name); - FREENOW; - RETURN_FALSE; - } else { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Handler %s doesn't uses locking for this mode which makes modifier t (test lock) obsolete", hptr->name); - FREENOW; - RETURN_FALSE; - } - } else { - lock_mode |= LOCK_NB; /* test =: non blocking */ - } - } - if (*pmode || !modenr) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Illegal DBA mode"); - FREENOW; - RETURN_FALSE; - } - - info = pemalloc(sizeof(dba_info), persistent); - memset(info, 0, sizeof(dba_info)); - info->path = pestrdup(Z_STRVAL_PP(args[0]), persistent); - info->mode = modenr; - info->argc = ac - 3; - info->argv = args + 3; - info->flags = (hptr->flags & ~DBA_LOCK_ALL) | (lock_flag & DBA_LOCK_ALL) | (persistent ? DBA_PERSISTENT : 0); - info->lock.mode = lock_mode; - - /* if any open call is a locking call: - * check if we already habe a locking call open that should block this call - * the problem is some systems would allow read during write - */ - if (hptr->flags & DBA_LOCK_ALL) { - if ((other = php_dba_find(info->path TSRMLS_CC)) != NULL) { - if ( ( (lock_mode&LOCK_EX) && (other->lock.mode&(LOCK_EX|LOCK_SH)) ) - || ( (other->lock.mode&LOCK_EX) && (lock_mode&(LOCK_EX|LOCK_SH)) ) - ) { - error = "Unable to establish lock (database file already open)"; /* force failure exit */ - } - } - } - - if (!error && lock_mode) { - if (lock_dbf) { - info->lock.name = pestrdup(info->path, persistent); - lock_file_mode = file_mode; - } else { - spprintf(&info->lock.name, 0, "%s.lck", info->path); - if (!strcmp(file_mode, "r")) { - /* when in read only mode try to use existing .lck file first */ - /* do not log errors for .lck file while in read ony mode on .lck file */ - lock_file_mode = "rb"; - info->lock.fp = php_stream_open_wrapper(info->lock.name, lock_file_mode, STREAM_MUST_SEEK|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); - } - if (!info->lock.fp) { - /* when not in read mode or failed to open .lck file read only. now try again in create(write) mode and log errors */ - lock_file_mode = "a+b"; - } - } - if (!info->lock.fp) { - info->lock.fp = php_stream_open_wrapper(info->lock.name, lock_file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); - } - if (!info->lock.fp) { - dba_close(info TSRMLS_CC); - /* stream operation already wrote an error message */ - FREENOW; - RETURN_FALSE; - } - if (php_stream_cast(info->lock.fp, PHP_STREAM_AS_FD, (void*)&info->lock.fd, 1) == FAILURE) { - dba_close(info TSRMLS_CC); - /* stream operation already wrote an error message */ - FREENOW; - RETURN_FALSE; - } - if (php_flock(info->lock.fd, lock_mode)) { - error = "Unable to establish lock"; /* force failure exit */ - } - } - - /* centralised open stream for builtin */ - if (!error && (hptr->flags&DBA_STREAM_OPEN)==DBA_STREAM_OPEN) { - if (info->lock.fp && lock_dbf) { - info->fp = info->lock.fp; /* use the same stream for locking and database access */ - } else { - info->fp = php_stream_open_wrapper(info->path, file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); - } - if (!info->fp) { - dba_close(info TSRMLS_CC); - /* stream operation already wrote an error message */ - FREENOW; - RETURN_FALSE; - } - } - - if (error || hptr->open(info, &error TSRMLS_CC) != SUCCESS) { - dba_close(info TSRMLS_CC); - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Driver initialization failed for handler: %s%s%s", hptr->name, error?": ":"", error?error:""); - FREENOW; - RETURN_FALSE; - } - - info->hnd = hptr; - info->argc = 0; - info->argv = NULL; - - if (persistent) { - list_entry new_le; - - Z_TYPE(new_le) = le_pdb; - new_le.ptr = info; - if (zend_hash_update(&EG(persistent_list), key, keylen+1, &new_le, sizeof(list_entry), NULL) == FAILURE) { - FREENOW; - RETURN_FALSE; - } - } - - ZEND_REGISTER_RESOURCE(return_value, info, (persistent ? le_pdb : le_db)); - FREENOW; -} -/* }}} */ -#undef FREENOW - -/* {{{ proto int dba_popen(string path, string mode [, string handlername, string ...]) - Opens path using the specified handler in mode persistently */ -PHP_FUNCTION(dba_popen) -{ - php_dba_open(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ proto int dba_open(string path, string mode [, string handlername, string ...]) - Opens path using the specified handler in mode*/ -PHP_FUNCTION(dba_open) -{ - php_dba_open(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto void dba_close(resource handle) - Closes database */ -PHP_FUNCTION(dba_close) -{ - DBA_ID_GET1; - - zend_list_delete(Z_RESVAL_PP(id)); -} -/* }}} */ - -/* {{{ proto bool dba_exists(string key, int handle) - Checks, if the specified key exists */ -PHP_FUNCTION(dba_exists) -{ - DBA_ID_GET2; - - if(info->hnd->exists(info, key_str, key_len TSRMLS_CC) == SUCCESS) { - DBA_ID_DONE; - RETURN_TRUE; - } - DBA_ID_DONE; - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto string dba_fetch(string key, [int skip ,] int handle) - Fetches the data associated with key */ -PHP_FUNCTION(dba_fetch) -{ - char *val; - int len = 0; - DBA_ID_GET2_3; - - if (ac==3) { - if (!strcmp(info->hnd->name, "cdb")) { - if (skip < 0) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Handler %s accepts only skip values greater than or equal to zero, using skip=0", info->hnd->name); - skip = 0; - } - } else if (!strcmp(info->hnd->name, "inifile")) { - /* "-1" is compareable to 0 but allows a non restrictive - * access which is fater. For example 'inifile' uses this - * to allow faster access when the key was already found - * using firstkey/nextkey. However explicitly setting the - * value to 0 ensures the first value. - */ - if (skip < -1) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Handler %s accepts only skip value -1 and greater, using skip=0", info->hnd->name); - skip = 0; - } - } else { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Handler %s does not support optional skip parameter, the value will be ignored", info->hnd->name); - skip = 0; - } - } else { - skip = 0; - } - if((val = info->hnd->fetch(info, key_str, key_len, skip, &len TSRMLS_CC)) != NULL) { - if (val && PG(magic_quotes_runtime)) { - val = php_addslashes(val, len, &len, 1 TSRMLS_CC); - } - DBA_ID_DONE; - RETURN_STRINGL(val, len, 0); - } - DBA_ID_DONE; - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto string dba_firstkey(int handle) - Resets the internal key pointer and returns the first key */ -PHP_FUNCTION(dba_firstkey) -{ - char *fkey; - int len; - DBA_ID_GET1; - - fkey = info->hnd->firstkey(info, &len TSRMLS_CC); - if(fkey) - RETURN_STRINGL(fkey, len, 0); - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto string dba_nextkey(int handle) - Returns the next key */ -PHP_FUNCTION(dba_nextkey) -{ - char *nkey; - int len; - DBA_ID_GET1; - - nkey = info->hnd->nextkey(info, &len TSRMLS_CC); - if(nkey) - RETURN_STRINGL(nkey, len, 0); - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool dba_delete(string key, int handle) - Deletes the entry associated with key - If inifile: remove all other key lines */ -PHP_FUNCTION(dba_delete) -{ - DBA_ID_GET2; - - DBA_WRITE_CHECK; - - if(info->hnd->delete(info, key_str, key_len TSRMLS_CC) == SUCCESS) - { - DBA_ID_DONE; - RETURN_TRUE; - } - DBA_ID_DONE; - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool dba_insert(string key, string value, int handle) - If not inifile: Insert value as key, return false, if key exists already - If inifile: Add vakue as key (next instance of key) */ -PHP_FUNCTION(dba_insert) -{ - php_dba_update(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ proto bool dba_replace(string key, string value, int handle) - Inserts value as key, replaces key, if key exists already - If inifile: remove all other key lines */ -PHP_FUNCTION(dba_replace) -{ - php_dba_update(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto bool dba_optimize(int handle) - Optimizes (e.g. clean up, vacuum) database */ -PHP_FUNCTION(dba_optimize) -{ - DBA_ID_GET1; - - DBA_WRITE_CHECK; - if(info->hnd->optimize(info TSRMLS_CC) == SUCCESS) { - RETURN_TRUE; - } - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool dba_sync(int handle) - Synchronizes database */ -PHP_FUNCTION(dba_sync) -{ - DBA_ID_GET1; - - if(info->hnd->sync(info TSRMLS_CC) == SUCCESS) { - RETURN_TRUE; - } - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto array dba_handlers([bool full_info]) - List configured databases */ -PHP_FUNCTION(dba_handlers) -{ - dba_handler *hptr; - zend_bool full_info = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &full_info) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - RETURN_FALSE; - } - - array_init(return_value); - - for(hptr = handler; hptr->name; hptr++) { - if (full_info) { - add_assoc_string(return_value, hptr->name, hptr->info(hptr, NULL TSRMLS_CC), 0); - } else { - add_next_index_string(return_value, hptr->name, 1); - } - } -} -/* }}} */ - -/* {{{ proto array dba_list() - List configured databases */ -PHP_FUNCTION(dba_list) -{ - ulong numitems, i; - zend_rsrc_list_entry *le; - dba_info *info; - - if (ZEND_NUM_ARGS()!=0) { - ZEND_WRONG_PARAM_COUNT(); - RETURN_FALSE; - } - - array_init(return_value); - - numitems = zend_hash_next_free_element(&EG(regular_list)); - for (i=1; i<numitems; i++) { - if (zend_hash_index_find(&EG(regular_list), i, (void **) &le)==FAILURE) { - continue; - } - if (Z_TYPE_P(le) == le_db || Z_TYPE_P(le) == le_pdb) { - info = (dba_info *)(le->ptr); - add_index_string(return_value, i, info->path, 1); - } - } -} -/* }}} */ - -#endif /* HAVE_DBA */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/dba/dba.dsp b/ext/dba/dba.dsp deleted file mode 100644 index 063d4e3ba2..0000000000 --- a/ext/dba/dba.dsp +++ /dev/null @@ -1,197 +0,0 @@ -# Microsoft Developer Studio Project File - Name="dba" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=dba - Win32 Debug_TS Berkeley DB3
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "dba.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "dba.mak" CFG="dba - Win32 Debug_TS Berkeley DB3"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "dba - Win32 Release_TS Berkeley DB3" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "dba - Win32 Debug_TS Berkeley DB3" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "dba - Win32 Release_TS Berkeley DB3"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release_TS"
-# PROP BASE Intermediate_Dir "Release_TS"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D DBA_DB3=1 /D DB3_INCLUDE_FILE="db.h" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=0 /D DBA_DB3=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D DBA_FLATFILE=1 /D DBA_CDB=1 /D DBA_CDB_MAKE=1 /D DBA_CDB_BUILTIN=1 /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x407 /d "NDEBUG"
-# ADD RSC /l 0x407 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 php4ts.lib libdb31s.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_dba.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
-# ADD LINK32 php4ts.lib libdb31s.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_dba.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
-
-!ELSEIF "$(CFG)" == "dba - Win32 Debug_TS Berkeley DB3"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D "DBA_DB3" /D DB3_INCLUDE_FILE="db.h" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=1 /D "DBA_DB3" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D DBA_FLATFILE=1 /D DBA_CDB=1 /D DBA_CDB_MAKE=1 /D DBA_CDB_BUILTIN=1 /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x407 /d "_DEBUG"
-# ADD RSC /l 0x407 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 php4ts_debug.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_dba.dll" /pdbtype:sept /libpath:"..\..\Debug_TS"
-# ADD LINK32 php4ts_debug.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_dba.dll" /pdbtype:sept /libpath:"..\..\Debug_TS"
-
-!ENDIF
-
-# Begin Target
-
-# Name "dba - Win32 Release_TS Berkeley DB3"
-# Name "dba - Win32 Debug_TS Berkeley DB3"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\libcdb\cdb.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\libcdb\cdb_make.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_cdb.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_db2.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_db3.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_dbm.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_flatfile.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_gdbm.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\dba_ndbm.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\libflatfile\flatfile.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\libcdb\uint32.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\libcdb\cdb.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\libcdb\cdb_make.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\libflatfile\flatfile.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_cdb.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_db2.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_db3.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_dba.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_dbm.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_flatfile.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_gdbm.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_ndbm.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\libcdb\uint32.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/ext/dba/dba_cdb.c b/ext/dba/dba_cdb.c deleted file mode 100644 index ee9d53a74d..0000000000 --- a/ext/dba/dba_cdb.c +++ /dev/null @@ -1,350 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Sascha Schumann <sascha@schumann.cx> | - | Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#if DBA_CDB -#include "php_cdb.h" - -#include <sys/types.h> -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <fcntl.h> - -#if DBA_CDB_BUILTIN -# include "libcdb/cdb.h" -# include "libcdb/cdb_make.h" -# include "libcdb/uint32.h" -#else -# ifdef CDB_INCLUDE_FILE -# include CDB_INCLUDE_FILE -# endif -#endif - -#define CDB_INFO \ - dba_cdb *cdb = (dba_cdb *) info->dbf - -typedef struct { - struct cdb c; -#if DBA_CDB_BUILTIN - struct cdb_make m; - php_stream *file; - int make; -#else - int file; -#endif - uint32 eod; /* size of constant database */ - uint32 pos; /* current position for traversing */ -} dba_cdb; - -DBA_OPEN_FUNC(cdb) -{ -#if DBA_CDB_BUILTIN - php_stream* file = 0; - int make; -#else - int file = 0; -#endif - dba_cdb *cdb; - dba_info *pinfo = (dba_info *) info; - - switch (info->mode) { - case DBA_READER: -#if DBA_CDB_BUILTIN - make = 0; - file = info->fp; -#else - file = VCWD_OPEN(info->path, O_RDONLY); - if (file < 0) { - *error = "Unable to open file"; - return FAILURE; - } -#endif - break; -#if DBA_CDB_BUILTIN - case DBA_TRUNC: - case DBA_CREAT: - make = 1; - file = info->fp; - break; - case DBA_WRITER: - *error = "Update operations are not supported"; - return FAILURE; /* not supported */ -#endif - default: - *error = "Currently not supported"; - return FAILURE; - } - - cdb = pemalloc(sizeof(dba_cdb), info->flags&DBA_PERSISTENT); - memset(cdb, 0, sizeof(dba_cdb)); - -#if DBA_CDB_BUILTIN - if (make) { - cdb_make_start(&cdb->m, file TSRMLS_CC); - } else { - cdb_init(&cdb->c, file TSRMLS_CC); - } - cdb->make = make; -#else - cdb_init(&cdb->c, file); -#endif - cdb->file = file; - - pinfo->dbf = cdb; - return SUCCESS; -} - -DBA_CLOSE_FUNC(cdb) -{ - CDB_INFO; - - /* cdb_free does not close associated file */ -#if DBA_CDB_BUILTIN - if (cdb->make) { - cdb_make_finish(&cdb->m TSRMLS_CC); - } else { - cdb_free(&cdb->c TSRMLS_CC); - } -#else - cdb_free(&cdb->c); - close(cdb->file); -#endif - pefree(cdb, info->flags&DBA_PERSISTENT); -} - -#if DBA_CDB_BUILTIN -# define php_cdb_read(cdb, buf, len, pos) cdb_read(cdb, buf, len, pos TSRMLS_CC) -# define php_cdb_findnext(cdb, key, len) cdb_findnext(cdb, key, len TSRMLS_CC) -# define php_cdb_find(cdb, key, len) cdb_find(cdb, key, len TSRMLS_CC) -#else -# define php_cdb_read(cdb, buf, len, pos) cdb_read(cdb, buf, len, pos) -# define php_cdb_findnext(cdb, key, len) cdb_findnext(cdb, key, len) -# define php_cdb_find(cdb, key, len) cdb_find(cdb, key, len) -#endif - -DBA_FETCH_FUNC(cdb) -{ - CDB_INFO; - unsigned int len; - char *new_entry = NULL; - -#if DBA_CDB_BUILTIN - if (cdb->make) - return NULL; /* database was opened writeonly */ -#endif - if (php_cdb_find(&cdb->c, key, keylen) == 1) { - while(skip--) { - if (php_cdb_findnext(&cdb->c, key, keylen) != 1) { - return NULL; - } - } - len = cdb_datalen(&cdb->c); - new_entry = emalloc(len+1); - - if (php_cdb_read(&cdb->c, new_entry, len, cdb_datapos(&cdb->c)) == -1) { - efree(new_entry); - return NULL; - } - new_entry[len] = 0; - if (newlen) - *newlen = len; - } - - return new_entry; -} - -DBA_UPDATE_FUNC(cdb) -{ -#if DBA_CDB_BUILTIN - CDB_INFO; - - if (!cdb->make) - return FAILURE; /* database was opened readonly */ - if (!mode) - return FAILURE; /* cdb_make dosn't know replace */ - if (cdb_make_add(&cdb->m, key, keylen, val, vallen TSRMLS_CC) != -1) - return SUCCESS; -#endif - return FAILURE; -} - -DBA_EXISTS_FUNC(cdb) -{ - CDB_INFO; - -#if DBA_CDB_BUILTIN - if (cdb->make) - return FAILURE; /* database was opened writeonly */ -#endif - if (php_cdb_find(&cdb->c, key, keylen) == 1) - return SUCCESS; - return FAILURE; -} - -DBA_DELETE_FUNC(cdb) -{ - return FAILURE; /* cdb doesn't support delete */ -} - -/* {{{ cdb_file_read */ -#if DBA_CDB_BUILTIN -# define cdb_file_read(fildes, buf, size) php_stream_read(fildes, buf, size) -#else -# define cdb_file_read(fildes, buf, size) read(fildes, buf, size) -#endif -/* }}} */ - -#define CREAD(n) do { \ - if (cdb_file_read(cdb->file, buf, n) < n) return NULL; \ -} while (0) - -/* {{{ cdb_file_lseek - php_stream_seek does not return actual position */ -#if DBA_CDB_BUILTIN -int cdb_file_lseek(php_stream *fp, off_t offset, int whence TSRMLS_DC) { - php_stream_seek(fp, offset, whence); - return php_stream_tell(fp); -} -#else -int cdb_file_lseek(int fd, off_t offset, int whence TSRMLS_DC) { - return lseek(fd, offset, whence); -} -#endif -/* }}} */ - -#define CSEEK(n) do { \ - if (n >= cdb->eod) return NULL; \ - if (cdb_file_lseek(cdb->file, (off_t)n, SEEK_SET TSRMLS_CC) != (off_t) n) return NULL; \ -} while (0) - - -DBA_FIRSTKEY_FUNC(cdb) -{ - CDB_INFO; - uint32 klen, dlen; - char buf[8]; - char *key; - -#if DBA_CDB_BUILTIN - if (cdb->make) - return NULL; /* database was opened writeonly */ -#endif - - cdb->eod = -1; - CSEEK(0); - CREAD(4); - - /* Total length of file in bytes */ - uint32_unpack(buf, &cdb->eod); - - CSEEK(2048); - CREAD(8); - - /* The first four bytes contain the length of the key */ - uint32_unpack(buf, &klen); - uint32_unpack(buf + 4, &dlen); - - key = emalloc(klen + 1); - if (cdb_file_read(cdb->file, key, klen) < klen) { - efree(key); - key = NULL; - } else { - key[klen] = '\0'; - if (newlen) *newlen = klen; - } - - /* header + klenlen + dlenlen + klen + dlen */ - cdb->pos = 2048 + 4 + 4 + klen + dlen; - - return key; -} - -DBA_NEXTKEY_FUNC(cdb) -{ - CDB_INFO; - uint32 klen, dlen; - char buf[8]; - char *key; - -#if DBA_CDB_BUILTIN - if (cdb->make) - return NULL; /* database was opened writeonly */ -#endif - - CSEEK(cdb->pos); - CREAD(8); - uint32_unpack(buf, &klen); - uint32_unpack(buf + 4, &dlen); - - key = emalloc(klen + 1); - if (cdb_file_read(cdb->file, key, klen) < klen) { - efree(key); - key = NULL; - } else { - key[klen] = '\0'; - if (newlen) *newlen = klen; - } - - cdb->pos += 8 + klen + dlen; - - return key; -} - -DBA_OPTIMIZE_FUNC(cdb) -{ - return SUCCESS; -} - -DBA_SYNC_FUNC(cdb) -{ - /* this is read-only */ - return SUCCESS; -} - -DBA_INFO_FUNC(cdb) -{ -#if DBA_CDB_BUILTIN - if (!strcmp(hnd->name, "cdb")) { - return estrdup(cdb_version()); - } else { - return estrdup(cdb_make_version()); - } -#else - return estrdup("External"); -#endif -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/dba/dba_db2.c b/ext/dba/dba_db2.c deleted file mode 100644 index 9ef28a7a66..0000000000 --- a/ext/dba/dba_db2.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#if DBA_DB2 -#include "php_db2.h" -#include <sys/stat.h> - -#include <string.h> -#ifdef DB2_INCLUDE_FILE -#include DB2_INCLUDE_FILE -#endif - -#define DB2_DATA dba_db2_data *dba = info->dbf -#define DB2_GKEY \ - DBT gkey = {0}; \ - gkey.data = (char *) key; \ - gkey.size = keylen - -typedef struct { - DB *dbp; - DBC *cursor; -} dba_db2_data; - -DBA_OPEN_FUNC(db2) -{ - DB *dbp; - DBTYPE type; - int gmode = 0; - int filemode = 0644; - struct stat check_stat; - int s = VCWD_STAT(info->path, &check_stat); - - type = info->mode == DBA_READER ? DB_UNKNOWN : - info->mode == DBA_TRUNC ? DB_BTREE : - s ? DB_BTREE : DB_UNKNOWN; - - gmode = info->mode == DBA_READER ? DB_RDONLY : - (info->mode == DBA_CREAT && s) ? DB_CREATE : - (info->mode == DBA_CREAT && !s) ? 0 : - info->mode == DBA_WRITER ? 0 : - info->mode == DBA_TRUNC ? DB_CREATE | DB_TRUNCATE : -1; - - if (gmode == -1) { - return FAILURE;/* not possible */ - } - - if (info->argc > 0) { - convert_to_long_ex(info->argv[0]); - filemode = Z_LVAL_PP(info->argv[0]); - } - - if (db_open(info->path, type, gmode, filemode, NULL, NULL, &dbp)) { - return FAILURE; - } - - info->dbf = pemalloc(sizeof(dba_db2_data), info->flags&DBA_PERSISTENT); - memset(info->dbf, 0, sizeof(dba_db2_data)); - ((dba_db2_data *) info->dbf)->dbp = dbp; - return SUCCESS; -} - -DBA_CLOSE_FUNC(db2) -{ - DB2_DATA; - - if (dba->cursor) - dba->cursor->c_close(dba->cursor); - dba->dbp->close(dba->dbp, 0); - pefree(dba, info->flags&DBA_PERSISTENT); -} - -DBA_FETCH_FUNC(db2) -{ - DBT gval = {0}; - DB2_DATA; - DB2_GKEY; - - if (dba->dbp->get(dba->dbp, NULL, &gkey, &gval, 0)) { - return NULL; - } - - if (newlen) *newlen = gval.size; - return estrndup(gval.data, gval.size); -} - -DBA_UPDATE_FUNC(db2) -{ - DBT gval = {0}; - DB2_DATA; - DB2_GKEY; - - gval.data = (char *) val; - gval.size = vallen; - - if (dba->dbp->put(dba->dbp, NULL, &gkey, &gval, - mode == 1 ? DB_NOOVERWRITE : 0)) { - return FAILURE; - } - return SUCCESS; -} - -DBA_EXISTS_FUNC(db2) -{ - DBT gval = {0}; - DB2_DATA; - DB2_GKEY; - - if (dba->dbp->get(dba->dbp, NULL, &gkey, &gval, 0)) { - return FAILURE; - } - return SUCCESS; -} - -DBA_DELETE_FUNC(db2) -{ - DB2_DATA; - DB2_GKEY; - - return dba->dbp->del(dba->dbp, NULL, &gkey, 0) ? FAILURE : SUCCESS; -} - -DBA_FIRSTKEY_FUNC(db2) -{ - DB2_DATA; - - if (dba->cursor) { - dba->cursor->c_close(dba->cursor); - dba->cursor = NULL; - } - -#if (DB_VERSION_MAJOR > 2) || (DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR > 6) || (DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR == 6 && DB_VERSION_PATCH >= 4) - if (dba->dbp->cursor(dba->dbp, NULL, &dba->cursor, 0)) { -#else - if (dba->dbp->cursor(dba->dbp, NULL, &dba->cursor)) { -#endif - return NULL; - } - - /* we should introduce something like PARAM_PASSTHRU... */ - return dba_nextkey_db2(info, newlen TSRMLS_CC); -} - -DBA_NEXTKEY_FUNC(db2) -{ - DB2_DATA; - DBT gkey = {0}, gval = {0}; - - if (dba->cursor->c_get(dba->cursor, &gkey, &gval, DB_NEXT) - || !gkey.data) - return NULL; - - if (newlen) *newlen = gkey.size; - return estrndup(gkey.data, gkey.size); -} - -DBA_OPTIMIZE_FUNC(db2) -{ - return SUCCESS; -} - -DBA_SYNC_FUNC(db2) -{ - DB2_DATA; - - return dba->dbp->sync(dba->dbp, 0) ? FAILURE : SUCCESS; -} - -DBA_INFO_FUNC(db2) -{ - return estrdup(DB_VERSION_STRING); -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/dba/dba_db3.c b/ext/dba/dba_db3.c deleted file mode 100644 index 3d0e892219..0000000000 --- a/ext/dba/dba_db3.c +++ /dev/null @@ -1,234 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#if DBA_DB3 -#include "php_db3.h" -#include <sys/stat.h> - -#include <string.h> -#ifdef DB3_INCLUDE_FILE -#include DB3_INCLUDE_FILE -#else -#include <db.h> -#endif - -static void php_dba_db3_errcall_fcn(const char *errpfx, char *msg) -{ - TSRMLS_FETCH(); - - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s%s", errpfx?errpfx:"", msg); -} - -#define DB3_DATA dba_db3_data *dba = info->dbf -#define DB3_GKEY \ - DBT gkey; \ - memset(&gkey, 0, sizeof(gkey)); \ - gkey.data = (char *) key; gkey.size = keylen - -typedef struct { - DB *dbp; - DBC *cursor; -} dba_db3_data; - -DBA_OPEN_FUNC(db3) -{ - DB *dbp = NULL; - DBTYPE type; - int gmode = 0, err; - int filemode = 0644; - struct stat check_stat; - int s = VCWD_STAT(info->path, &check_stat); - - type = info->mode == DBA_READER ? DB_UNKNOWN : - info->mode == DBA_TRUNC ? DB_BTREE : - s? DB_BTREE : DB_UNKNOWN; - - gmode = info->mode == DBA_READER ? DB_RDONLY : - (info->mode == DBA_CREAT && s) ? DB_CREATE : - (info->mode == DBA_CREAT && !s) ? 0 : - info->mode == DBA_WRITER ? 0 : - info->mode == DBA_TRUNC ? DB_CREATE | DB_TRUNCATE : -1; - - if (gmode == -1) { - return FAILURE; /* not possible */ - } - - if (info->argc > 0) { - convert_to_long_ex(info->argv[0]); - filemode = Z_LVAL_PP(info->argv[0]); - } - -#ifdef DB_FCNTL_LOCKING - gmode |= DB_FCNTL_LOCKING; -#endif - - if ((err=db_create(&dbp, NULL, 0)) == 0) { - dbp->set_errcall(dbp, php_dba_db3_errcall_fcn); - if ((err=dbp->open(dbp, info->path, NULL, type, gmode, filemode)) == 0) { - dba_db3_data *data; - - data = pemalloc(sizeof(*data), info->flags&DBA_PERSISTENT); - data->dbp = dbp; - data->cursor = NULL; - info->dbf = data; - - return SUCCESS; - } else { - dbp->close(dbp, 0); - *error = db_strerror(err); - } - } else { - *error = db_strerror(err); - } - - return FAILURE; -} - -DBA_CLOSE_FUNC(db3) -{ - DB3_DATA; - - if (dba->cursor) dba->cursor->c_close(dba->cursor); - dba->dbp->close(dba->dbp, 0); - pefree(dba, info->flags&DBA_PERSISTENT); -} - -DBA_FETCH_FUNC(db3) -{ - DBT gval; - char *new = NULL; - DB3_DATA; - DB3_GKEY; - - memset(&gval, 0, sizeof(gval)); - if (!dba->dbp->get(dba->dbp, NULL, &gkey, &gval, 0)) { - if (newlen) *newlen = gval.size; - new = estrndup(gval.data, gval.size); - } - return new; -} - -DBA_UPDATE_FUNC(db3) -{ - DBT gval; - DB3_DATA; - DB3_GKEY; - - memset(&gval, 0, sizeof(gval)); - gval.data = (char *) val; - gval.size = vallen; - - if (!dba->dbp->put(dba->dbp, NULL, &gkey, &gval, - mode == 1 ? DB_NOOVERWRITE : 0)) { - return SUCCESS; - } - return FAILURE; -} - -DBA_EXISTS_FUNC(db3) -{ - DBT gval; - DB3_DATA; - DB3_GKEY; - - memset(&gval, 0, sizeof(gval)); - if (!dba->dbp->get(dba->dbp, NULL, &gkey, &gval, 0)) { - return SUCCESS; - } - return FAILURE; -} - -DBA_DELETE_FUNC(db3) -{ - DB3_DATA; - DB3_GKEY; - - return dba->dbp->del(dba->dbp, NULL, &gkey, 0) ? FAILURE : SUCCESS; -} - -DBA_FIRSTKEY_FUNC(db3) -{ - DB3_DATA; - - if (dba->cursor) { - dba->cursor->c_close(dba->cursor); - } - - dba->cursor = NULL; - if (dba->dbp->cursor(dba->dbp, NULL, &dba->cursor, 0) != 0) { - return NULL; - } - - /* we should introduce something like PARAM_PASSTHRU... */ - return dba_nextkey_db3(info, newlen TSRMLS_CC); -} - -DBA_NEXTKEY_FUNC(db3) -{ - DB3_DATA; - DBT gkey, gval; - char *nkey = NULL; - - memset(&gkey, 0, sizeof(gkey)); - memset(&gval, 0, sizeof(gval)); - - if (dba->cursor->c_get(dba->cursor, &gkey, &gval, DB_NEXT) == 0) { - if (gkey.data) { - nkey = estrndup(gkey.data, gkey.size); - if (newlen) *newlen = gkey.size; - } - } - - return nkey; -} - -DBA_OPTIMIZE_FUNC(db3) -{ - return SUCCESS; -} - -DBA_SYNC_FUNC(db3) -{ - DB3_DATA; - - return dba->dbp->sync(dba->dbp, 0) ? FAILURE : SUCCESS; -} - -DBA_INFO_FUNC(db3) -{ - return estrdup(DB_VERSION_STRING); -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/dba/dba_db4.c b/ext/dba/dba_db4.c deleted file mode 100644 index 0195d61400..0000000000 --- a/ext/dba/dba_db4.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#if DBA_DB4 -#include "php_db4.h" -#include <sys/stat.h> - -#include <string.h> -#ifdef DB4_INCLUDE_FILE -#include DB4_INCLUDE_FILE -#else -#include <db.h> -#endif - -static void php_dba_db4_errcall_fcn(const char *errpfx, char *msg) -{ - TSRMLS_FETCH(); - - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s%s", errpfx?errpfx:"", msg); -} - -#define DB4_DATA dba_db4_data *dba = info->dbf -#define DB4_GKEY \ - DBT gkey; \ - memset(&gkey, 0, sizeof(gkey)); \ - gkey.data = (char *) key; gkey.size = keylen - -typedef struct { - DB *dbp; - DBC *cursor; -} dba_db4_data; - -DBA_OPEN_FUNC(db4) -{ - DB *dbp = NULL; - DBTYPE type; - int gmode = 0, err; - int filemode = 0644; - struct stat check_stat; - int s = VCWD_STAT(info->path, &check_stat); - - type = info->mode == DBA_READER ? DB_UNKNOWN : - info->mode == DBA_TRUNC ? DB_BTREE : - s? DB_BTREE : DB_UNKNOWN; - - gmode = info->mode == DBA_READER ? DB_RDONLY : - (info->mode == DBA_CREAT && s) ? DB_CREATE : - (info->mode == DBA_CREAT && !s) ? 0 : - info->mode == DBA_WRITER ? 0 : - info->mode == DBA_TRUNC ? DB_CREATE | DB_TRUNCATE : -1; - - if (gmode == -1) { - return FAILURE; /* not possible */ - } - - if (info->argc > 0) { - convert_to_long_ex(info->argv[0]); - filemode = Z_LVAL_PP(info->argv[0]); - } - -#ifdef DB_FCNTL_LOCKING - gmode |= DB_FCNTL_LOCKING; -#endif - - if ((err=db_create(&dbp, NULL, 0)) == 0) { - dbp->set_errcall(dbp, php_dba_db4_errcall_fcn); - if ( -#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) - (err=dbp->open(dbp, 0, info->path, NULL, type, gmode, filemode)) == 0) { -#else - (err=dbp->open(dbp, info->path, NULL, type, gmode, filemode)) == 0) { -#endif - dba_db4_data *data; - - data = pemalloc(sizeof(*data), info->flags&DBA_PERSISTENT); - data->dbp = dbp; - data->cursor = NULL; - info->dbf = data; - - return SUCCESS; - } else { - dbp->close(dbp, 0); - *error = db_strerror(err); - } - } else { - *error = db_strerror(err); - } - - return FAILURE; -} - -DBA_CLOSE_FUNC(db4) -{ - DB4_DATA; - - if (dba->cursor) dba->cursor->c_close(dba->cursor); - dba->dbp->close(dba->dbp, 0); - pefree(dba, info->flags&DBA_PERSISTENT); -} - -DBA_FETCH_FUNC(db4) -{ - DBT gval; - char *new = NULL; - DB4_DATA; - DB4_GKEY; - - memset(&gval, 0, sizeof(gval)); - if (!dba->dbp->get(dba->dbp, NULL, &gkey, &gval, 0)) { - if (newlen) *newlen = gval.size; - new = estrndup(gval.data, gval.size); - } - return new; -} - -DBA_UPDATE_FUNC(db4) -{ - DBT gval; - DB4_DATA; - DB4_GKEY; - - memset(&gval, 0, sizeof(gval)); - gval.data = (char *) val; - gval.size = vallen; - - if (!dba->dbp->put(dba->dbp, NULL, &gkey, &gval, - mode == 1 ? DB_NOOVERWRITE : 0)) { - return SUCCESS; - } - return FAILURE; -} - -DBA_EXISTS_FUNC(db4) -{ - DBT gval; - DB4_DATA; - DB4_GKEY; - - memset(&gval, 0, sizeof(gval)); - if (!dba->dbp->get(dba->dbp, NULL, &gkey, &gval, 0)) { - return SUCCESS; - } - return FAILURE; -} - -DBA_DELETE_FUNC(db4) -{ - DB4_DATA; - DB4_GKEY; - - return dba->dbp->del(dba->dbp, NULL, &gkey, 0) ? FAILURE : SUCCESS; -} - -DBA_FIRSTKEY_FUNC(db4) -{ - DB4_DATA; - - if (dba->cursor) { - dba->cursor->c_close(dba->cursor); - } - - dba->cursor = NULL; - if (dba->dbp->cursor(dba->dbp, NULL, &dba->cursor, 0) != 0) { - return NULL; - } - - /* we should introduce something like PARAM_PASSTHRU... */ - return dba_nextkey_db4(info, newlen TSRMLS_CC); -} - -DBA_NEXTKEY_FUNC(db4) -{ - DB4_DATA; - DBT gkey, gval; - char *nkey = NULL; - - memset(&gkey, 0, sizeof(gkey)); - memset(&gval, 0, sizeof(gval)); - - if (dba->cursor->c_get(dba->cursor, &gkey, &gval, DB_NEXT) == 0) { - if (gkey.data) { - nkey = estrndup(gkey.data, gkey.size); - if (newlen) *newlen = gkey.size; - } - } - - return nkey; -} - -DBA_OPTIMIZE_FUNC(db4) -{ - return SUCCESS; -} - -DBA_SYNC_FUNC(db4) -{ - DB4_DATA; - - return dba->dbp->sync(dba->dbp, 0) ? FAILURE : SUCCESS; -} - -DBA_INFO_FUNC(db4) -{ - return estrdup(DB_VERSION_STRING); -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/dba/dba_dbm.c b/ext/dba/dba_dbm.c deleted file mode 100644 index 06010af589..0000000000 --- a/ext/dba/dba_dbm.c +++ /dev/null @@ -1,213 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#if DBA_DBM -#include "php_dbm.h" - -#ifdef DBM_INCLUDE_FILE -#include DBM_INCLUDE_FILE -#endif -#if DBA_GDBM -#include "php_gdbm.h" -#endif - -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -#define DBM_DATA dba_dbm_data *dba = info->dbf -#define DBM_GKEY datum gkey; gkey.dptr = (char *) key; gkey.dsize = keylen - -#define TRUNC_IT(extension, mode) \ - snprintf(buf, MAXPATHLEN, "%s" extension, info->path); \ - buf[MAXPATHLEN-1] = '\0'; \ - if((fd = VCWD_OPEN_MODE(buf, O_CREAT | mode | O_WRONLY, filemode)) == -1) \ - return FAILURE; \ - close(fd); - - -typedef struct { - datum nextkey; -} dba_dbm_data; - -DBA_OPEN_FUNC(dbm) -{ - int fd; - int filemode = 0644; - - if(info->argc > 0) { - convert_to_long_ex(info->argv[0]); - filemode = Z_LVAL_PP(info->argv[0]); - } - - if(info->mode == DBA_TRUNC) { - char buf[MAXPATHLEN]; - - /* dbm/ndbm original */ - TRUNC_IT(".pag", O_TRUNC); - TRUNC_IT(".dir", O_TRUNC); - } - - if(info->mode == DBA_CREAT) { - char buf[MAXPATHLEN]; - - TRUNC_IT(".pag", 0); - TRUNC_IT(".dir", 0); - } - - if(dbminit((char *) info->path) == -1) { - return FAILURE; - } - - info->dbf = pemalloc(sizeof(dba_dbm_data), info->flags&DBA_PERSISTENT); - memset(info->dbf, 0, sizeof(dba_dbm_data)); - return SUCCESS; -} - -DBA_CLOSE_FUNC(dbm) -{ - pefree(info->dbf, info->flags&DBA_PERSISTENT); - dbmclose(); -} - -DBA_FETCH_FUNC(dbm) -{ - datum gval; - char *new = NULL; - - DBM_GKEY; - gval = fetch(gkey); - if(gval.dptr) { - if(newlen) *newlen = gval.dsize; - new = estrndup(gval.dptr, gval.dsize); - } - return new; -} - -DBA_UPDATE_FUNC(dbm) -{ - datum gval; - - DBM_GKEY; - - if (mode == 1) { /* insert */ - gval = fetch(gkey); - if(gval.dptr) { - return FAILURE; - } - } - - gval.dptr = (char *) val; - gval.dsize = vallen; - - return (store(gkey, gval) == -1 ? FAILURE : SUCCESS); -} - -DBA_EXISTS_FUNC(dbm) -{ - datum gval; - DBM_GKEY; - - gval = fetch(gkey); - if(gval.dptr) { - return SUCCESS; - } - return FAILURE; -} - -DBA_DELETE_FUNC(dbm) -{ - DBM_GKEY; - return(delete(gkey) == -1 ? FAILURE : SUCCESS); -} - -DBA_FIRSTKEY_FUNC(dbm) -{ - DBM_DATA; - datum gkey; - char *key = NULL; - - gkey = firstkey(); - if(gkey.dptr) { - if(newlen) *newlen = gkey.dsize; - key = estrndup(gkey.dptr, gkey.dsize); - dba->nextkey = gkey; - } else - dba->nextkey.dptr = NULL; - return key; -} - -DBA_NEXTKEY_FUNC(dbm) -{ - DBM_DATA; - datum gkey; - char *nkey = NULL; - - if(!dba->nextkey.dptr) return NULL; - - gkey = nextkey(dba->nextkey); - if(gkey.dptr) { - if(newlen) *newlen = gkey.dsize; - nkey = estrndup(gkey.dptr, gkey.dsize); - dba->nextkey = gkey; - } else - dba->nextkey.dptr = NULL; - return nkey; -} - -DBA_OPTIMIZE_FUNC(dbm) -{ - /* dummy */ - return SUCCESS; -} - -DBA_SYNC_FUNC(dbm) -{ - return SUCCESS; -} - -DBA_INFO_FUNC(dbm) -{ -#if DBA_GDBM - if (!strcmp(DBM_VERSION, "GDBM")) - { - return dba_info_gdbm(hnd, info TSRMLS_CC); - } -#endif - return estrdup(DBM_VERSION); -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/dba/dba_flatfile.c b/ext/dba/dba_flatfile.c deleted file mode 100644 index dd9d77c89d..0000000000 --- a/ext/dba/dba_flatfile.c +++ /dev/null @@ -1,188 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#if DBA_FLATFILE -#include "php_flatfile.h" - -#include "libflatfile/flatfile.h" - -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -#define FLATFILE_DATA flatfile *dba = info->dbf -#define FLATFILE_GKEY datum gkey; gkey.dptr = (char *) key; gkey.dsize = keylen - -DBA_OPEN_FUNC(flatfile) -{ - info->dbf = pemalloc(sizeof(flatfile), info->flags&DBA_PERSISTENT); - memset(info->dbf, 0, sizeof(flatfile)); - - ((flatfile*)info->dbf)->fp = info->fp; - - return SUCCESS; -} - -DBA_CLOSE_FUNC(flatfile) -{ - FLATFILE_DATA; - - if (dba->nextkey.dptr) { - efree(dba->nextkey.dptr); - } - pefree(dba, info->flags&DBA_PERSISTENT); -} - -DBA_FETCH_FUNC(flatfile) -{ - datum gval; - char *new = NULL; - - FLATFILE_DATA; - FLATFILE_GKEY; - - gval = flatfile_fetch(dba, gkey TSRMLS_CC); - if (gval.dptr) { - if (newlen) { - *newlen = gval.dsize; - } - new = estrndup(gval.dptr, gval.dsize); - efree(gval.dptr); - } - return new; -} - -DBA_UPDATE_FUNC(flatfile) -{ - datum gval; - - FLATFILE_DATA; - FLATFILE_GKEY; - gval.dptr = (char *) val; - gval.dsize = vallen; - - switch(flatfile_store(dba, gkey, gval, mode==1 ? FLATFILE_INSERT : FLATFILE_REPLACE TSRMLS_CC)) { - case -1: - php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Operation not possible"); - return FAILURE; - default: - case 0: - return SUCCESS; - case 1: - php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Key already exists"); - return SUCCESS; - } -} - -DBA_EXISTS_FUNC(flatfile) -{ - datum gval; - FLATFILE_DATA; - FLATFILE_GKEY; - - gval = flatfile_fetch(dba, gkey TSRMLS_CC); - if (gval.dptr) { - efree(gval.dptr); - return SUCCESS; - } - return FAILURE; -} - -DBA_DELETE_FUNC(flatfile) -{ - FLATFILE_DATA; - FLATFILE_GKEY; - return(flatfile_delete(dba, gkey TSRMLS_CC) == -1 ? FAILURE : SUCCESS); -} - -DBA_FIRSTKEY_FUNC(flatfile) -{ - FLATFILE_DATA; - - if (dba->nextkey.dptr) { - efree(dba->nextkey.dptr); - } - dba->nextkey = flatfile_firstkey(dba TSRMLS_CC); - if (dba->nextkey.dptr) { - if (newlen) { - *newlen = dba->nextkey.dsize; - } - return estrndup(dba->nextkey.dptr, dba->nextkey.dsize); - } - return NULL; -} - -DBA_NEXTKEY_FUNC(flatfile) -{ - FLATFILE_DATA; - - if (!dba->nextkey.dptr) { - return NULL; - } - - if (dba->nextkey.dptr) { - efree(dba->nextkey.dptr); - } - dba->nextkey = flatfile_nextkey(dba TSRMLS_CC); - if (dba->nextkey.dptr) { - if (newlen) { - *newlen = dba->nextkey.dsize; - } - return estrndup(dba->nextkey.dptr, dba->nextkey.dsize); - } - return NULL; -} - -DBA_OPTIMIZE_FUNC(flatfile) -{ - /* dummy */ - return SUCCESS; -} - -DBA_SYNC_FUNC(flatfile) -{ - /* dummy */ - return SUCCESS; -} - -DBA_INFO_FUNC(flatfile) -{ - return estrdup(flatfile_version()); -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/dba/dba_gdbm.c b/ext/dba/dba_gdbm.c deleted file mode 100644 index b3b8abdc73..0000000000 --- a/ext/dba/dba_gdbm.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#if DBA_GDBM -#include "php_gdbm.h" - -#ifdef GDBM_INCLUDE_FILE -#include GDBM_INCLUDE_FILE -#endif - -#define GDBM_DATA dba_gdbm_data *dba = info->dbf -#define GDBM_GKEY datum gkey; gkey.dptr = (char *) key; gkey.dsize = keylen - -typedef struct { - GDBM_FILE dbf; - datum nextkey; -} dba_gdbm_data; - -DBA_OPEN_FUNC(gdbm) -{ - GDBM_FILE dbf; - int gmode = 0; - int filemode = 0644; - - gmode = info->mode == DBA_READER ? GDBM_READER : - info->mode == DBA_WRITER ? GDBM_WRITER : - info->mode == DBA_CREAT ? GDBM_WRCREAT : - info->mode == DBA_TRUNC ? GDBM_NEWDB : -1; - - if(gmode == -1) - return FAILURE; /* not possible */ - - if(info->argc > 0) { - convert_to_long_ex(info->argv[0]); - filemode = Z_LVAL_PP(info->argv[0]); - } - - dbf = gdbm_open(info->path, 0, gmode, filemode, NULL); - - if(dbf) { - info->dbf = pemalloc(sizeof(dba_gdbm_data), info->flags&DBA_PERSISTENT); - memset(info->dbf, 0, sizeof(dba_gdbm_data)); - ((dba_gdbm_data *) info->dbf)->dbf = dbf; - return SUCCESS; - } - *error = gdbm_strerror(gdbm_errno); - return FAILURE; -} - -DBA_CLOSE_FUNC(gdbm) -{ - GDBM_DATA; - - if(dba->nextkey.dptr) free(dba->nextkey.dptr); - gdbm_close(dba->dbf); - pefree(dba, info->flags&DBA_PERSISTENT); -} - -DBA_FETCH_FUNC(gdbm) -{ - GDBM_DATA; - datum gval; - char *new = NULL; - - GDBM_GKEY; - gval = gdbm_fetch(dba->dbf, gkey); - if(gval.dptr) { - if(newlen) *newlen = gval.dsize; - new = estrndup(gval.dptr, gval.dsize); - free(gval.dptr); - } - return new; -} - -DBA_UPDATE_FUNC(gdbm) -{ - datum gval; - GDBM_DATA; - - GDBM_GKEY; - gval.dptr = (char *) val; - gval.dsize = vallen; - - if(gdbm_store(dba->dbf, gkey, gval, - mode == 1 ? GDBM_INSERT : GDBM_REPLACE) == 0) - return SUCCESS; - php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "%s", gdbm_strerror(gdbm_errno)); - return FAILURE; -} - -DBA_EXISTS_FUNC(gdbm) -{ - GDBM_DATA; - GDBM_GKEY; - - return gdbm_exists(dba->dbf, gkey) ? SUCCESS : FAILURE; -} - -DBA_DELETE_FUNC(gdbm) -{ - GDBM_DATA; - GDBM_GKEY; - - return gdbm_delete(dba->dbf, gkey) == -1 ? FAILURE : SUCCESS; -} - -DBA_FIRSTKEY_FUNC(gdbm) -{ - GDBM_DATA; - datum gkey; - char *key = NULL; - - if(dba->nextkey.dptr) { - free(dba->nextkey.dptr); - } - - gkey = gdbm_firstkey(dba->dbf); - if(gkey.dptr) { - key = estrndup(gkey.dptr, gkey.dsize); - if(newlen) *newlen = gkey.dsize; - dba->nextkey = gkey; - } else { - dba->nextkey.dptr = NULL; - } - return key; -} - -DBA_NEXTKEY_FUNC(gdbm) -{ - GDBM_DATA; - char *nkey = NULL; - datum gkey; - - if(!dba->nextkey.dptr) return NULL; - - gkey = gdbm_nextkey(dba->dbf, dba->nextkey); - free(dba->nextkey.dptr); - if(gkey.dptr) { - nkey = estrndup(gkey.dptr, gkey.dsize); - if(newlen) *newlen = gkey.dsize; - dba->nextkey = gkey; - } else { - dba->nextkey.dptr = NULL; - } - return nkey; -} - -DBA_OPTIMIZE_FUNC(gdbm) -{ - GDBM_DATA; - gdbm_reorganize(dba->dbf); - return SUCCESS; -} - -DBA_SYNC_FUNC(gdbm) -{ - GDBM_DATA; - - gdbm_sync(dba->dbf); - return SUCCESS; -} - -DBA_INFO_FUNC(gdbm) -{ - return estrdup(gdbm_version); -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/dba/dba_inifile.c b/ext/dba/dba_inifile.c deleted file mode 100644 index 2a12179e78..0000000000 --- a/ext/dba/dba_inifile.c +++ /dev/null @@ -1,186 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#if DBA_INIFILE -#include "php_inifile.h" - -#include "libinifile/inifile.h" - -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -#define INIFILE_DATA \ - inifile *dba = info->dbf - -#define INIFILE_GKEY \ - key_type ini_key = inifile_key_split((char*)key) /* keylen not needed here */ - -#define INIFILE_DONE \ - inifile_key_free(&ini_key) - -DBA_OPEN_FUNC(inifile) -{ - info->dbf = inifile_alloc(info->fp, info->mode == DBA_READER, info->flags&DBA_PERSISTENT TSRMLS_CC); - - return info->dbf ? SUCCESS : FAILURE; -} - -DBA_CLOSE_FUNC(inifile) -{ - INIFILE_DATA; - - inifile_free(dba, info->flags&DBA_PERSISTENT); -} - -DBA_FETCH_FUNC(inifile) -{ - val_type ini_val; - - INIFILE_DATA; - INIFILE_GKEY; - - ini_val = inifile_fetch(dba, &ini_key, skip TSRMLS_CC); - *newlen = ini_val.value ? strlen(ini_val.value) : 0; - INIFILE_DONE; - return ini_val.value; -} - -DBA_UPDATE_FUNC(inifile) -{ - val_type ini_val; - int res; - - INIFILE_DATA; - INIFILE_GKEY; - - ini_val.value = val; - - if (mode == 1) { - res = inifile_append(dba, &ini_key, &ini_val TSRMLS_CC); - } else { - res = inifile_replace(dba, &ini_key, &ini_val TSRMLS_CC); - } - INIFILE_DONE; - switch(res) { - case -1: - php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Operation not possible"); - return FAILURE; - default: - case 0: - return SUCCESS; - case 1: - php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Key already exists"); - return SUCCESS; - } -} - -DBA_EXISTS_FUNC(inifile) -{ - val_type ini_val; - - INIFILE_DATA; - INIFILE_GKEY; - - ini_val = inifile_fetch(dba, &ini_key, 0 TSRMLS_CC); - INIFILE_DONE; - if (ini_val.value) { - inifile_val_free(&ini_val); - return SUCCESS; - } - return FAILURE; -} - -DBA_DELETE_FUNC(inifile) -{ - INIFILE_DATA; - INIFILE_GKEY; - int res = inifile_delete(dba, &ini_key TSRMLS_CC); - - INIFILE_DONE; - return (res == -1 ? FAILURE : SUCCESS); -} - -DBA_FIRSTKEY_FUNC(inifile) -{ - INIFILE_DATA; - - if (inifile_firstkey(dba TSRMLS_CC)) { - char *result = inifile_key_string(&dba->curr.key); - *newlen = strlen(result); - return result; - } else { - return NULL; - } -} - -DBA_NEXTKEY_FUNC(inifile) -{ - INIFILE_DATA; - - if (!dba->curr.key.group && !dba->curr.key.name) { - return NULL; - } - - if (inifile_nextkey(dba TSRMLS_CC)) { - char *result = inifile_key_string(&dba->curr.key); - *newlen = strlen(result); - return result; - } else { - return NULL; - } -} - -DBA_OPTIMIZE_FUNC(inifile) -{ - /* dummy */ - return SUCCESS; -} - -DBA_SYNC_FUNC(inifile) -{ - /* dummy */ - return SUCCESS; -} - -DBA_INFO_FUNC(inifile) -{ - return estrdup(inifile_version()); -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/dba/dba_ndbm.c b/ext/dba/dba_ndbm.c deleted file mode 100644 index 95cc34e625..0000000000 --- a/ext/dba/dba_ndbm.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#if DBA_NDBM -#include "php_ndbm.h" - -#include <fcntl.h> -#ifdef NDBM_INCLUDE_FILE -#include NDBM_INCLUDE_FILE -#endif - -#define NDBM_GKEY datum gkey; gkey.dptr = (char *) key; gkey.dsize = keylen - -DBA_OPEN_FUNC(ndbm) -{ - DBM *dbf; - int gmode = 0; - int filemode = 0644; - dba_info *pinfo = (dba_info *) info; - - switch(info->mode) { - case DBA_READER: - gmode = O_RDONLY; - break; - case DBA_WRITER: - gmode = O_RDWR; - break; - case DBA_CREAT: - gmode = O_RDWR | O_CREAT; - break; - case DBA_TRUNC: - gmode = O_RDWR | O_CREAT | O_TRUNC; - break; - default: - return FAILURE; /* not possible */ - } - - if(info->argc > 0) { - convert_to_long_ex(info->argv[0]); - filemode = Z_LVAL_PP(info->argv[0]); - } - - dbf = dbm_open(info->path, gmode, filemode); - - pinfo->dbf = dbf; - return SUCCESS; -} - -DBA_CLOSE_FUNC(ndbm) -{ - dbm_close(info->dbf); -} - -DBA_FETCH_FUNC(ndbm) -{ - datum gval; - char *new = NULL; - - NDBM_GKEY; - gval = dbm_fetch(info->dbf, gkey); - if(gval.dptr) { - if(newlen) *newlen = gval.dsize; - new = estrndup(gval.dptr, gval.dsize); - } - return new; -} - -DBA_UPDATE_FUNC(ndbm) -{ - datum gval; - - NDBM_GKEY; - gval.dptr = (char *) val; - gval.dsize = vallen; - - if(!dbm_store(info->dbf, gkey, gval, mode == 1 ? DBM_INSERT : DBM_REPLACE)) - return SUCCESS; - return FAILURE; -} - -DBA_EXISTS_FUNC(ndbm) -{ - datum gval; - NDBM_GKEY; - gval = dbm_fetch(info->dbf, gkey); - if(gval.dptr) { - return SUCCESS; - } - return FAILURE; -} - -DBA_DELETE_FUNC(ndbm) -{ - NDBM_GKEY; - return(dbm_delete(info->dbf, gkey) == -1 ? FAILURE : SUCCESS); -} - -DBA_FIRSTKEY_FUNC(ndbm) -{ - datum gkey; - char *key = NULL; - - gkey = dbm_firstkey(info->dbf); - if(gkey.dptr) { - if(newlen) *newlen = gkey.dsize; - key = estrndup(gkey.dptr, gkey.dsize); - } - return key; -} - -DBA_NEXTKEY_FUNC(ndbm) -{ - datum gkey; - char *nkey = NULL; - - gkey = dbm_nextkey(info->dbf); - if(gkey.dptr) { - if(newlen) *newlen = gkey.dsize; - nkey = estrndup(gkey.dptr, gkey.dsize); - } - return nkey; -} - -DBA_OPTIMIZE_FUNC(ndbm) -{ - return SUCCESS; -} - -DBA_SYNC_FUNC(ndbm) -{ - return SUCCESS; -} - -DBA_INFO_FUNC(ndbm) -{ - return estrdup("NDBM"); -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/dba/install_cdb.sh b/ext/dba/install_cdb.sh deleted file mode 100755 index ce5f3cc856..0000000000 --- a/ext/dba/install_cdb.sh +++ /dev/null @@ -1,53 +0,0 @@ -#! /bin/sh - -# You can use this script if you want to use an external cdb lib. If you -# compile php using --with-cdb the internal functions will be used and no -# external library is used so that this script is not necessary. -# -# cdb-0.75 lacks support for installing header files and creating a -# library which programs can link against. This shell script fills -# the gap. -# -# $Id: install_cdb.sh,v 1.2 2002-11-04 17:53:04 helly Exp $ - -if test -r "cdb.a" && test -r "auto-str.c" && test -r "byte.a"; then - : -else - echo "Please execute this script in the cdb-0.75 source directory after 'make'" - exit 1 -fi - -prefix=$1 - -if test -z "$prefix"; then - prefix=/usr/local -fi - -echo "Using prefix $prefix" - -if mkdir -p "$prefix/include" "$prefix/lib"; then - : -else - echo "Creating directories failed. Please become superuser." - exit 1 -fi - -mkdir -p tmp || exit 1 -cd tmp -ar x ../cdb.a -ar x ../byte.a -ar x ../unix.a -ar x ../byte.a -ar x ../buffer.a -cp ../error.o . - -# not really portable -ar r "$prefix/lib/libcdb.a" * -ranlib "$prefix/lib/libcdb.a" -cd .. - -rm -rf tmp - -cp cdb.h uint32.h "$prefix/include" - -echo "done" diff --git a/ext/dba/libcdb/cdb.c b/ext/dba/libcdb/cdb.c deleted file mode 100644 index 16aaca037a..0000000000 --- a/ext/dba/libcdb/cdb.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* incorporated from D.J.Bernstein's cdb-0.75 (http://cr.yp.to/cdb.html)*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#include <sys/types.h> -#include <sys/stat.h> -#ifndef PHP_WIN32 -#include <sys/mman.h> -#endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <string.h> -#include <errno.h> -#include "cdb.h" - -#ifndef EPROTO -# define EPROTO -15 /* cdb 0.75's default for PROTOless systems */ -#endif - -/* {{{ cdb_match */ -static int cdb_match(struct cdb *c, char *key, unsigned int len, uint32 pos TSRMLS_DC) -{ - char buf[32]; - unsigned int n; - - while (len > 0) { - n = sizeof(buf); - if (n > len) - n = len; - if (cdb_read(c, buf, n, pos TSRMLS_CC) == -1) - return -1; - if (memcmp(buf, key, n)) - return 0; - pos += n; - key += n; - len -= n; - } - return 1; -} -/* }}} */ - -/* {{{ cdb_hash */ -uint32 cdb_hash(char *buf, unsigned int len) -{ - uint32 h; - - h = CDB_HASHSTART; - while (len--) { - h = ( h + (h << 5)) ^ (*buf++); - } - return h; -} -/* }}} */ - -/* {{{ cdb_free */ -void cdb_free(struct cdb *c TSRMLS_DC) -{ -} -/* }}} */ - -/* {{{ cdb_findstart */ -void cdb_findstart(struct cdb *c TSRMLS_DC) -{ - c->loop = 0; -} -/* }}} */ - -/* {{{ cdb_init */ -void cdb_init(struct cdb *c, php_stream *fp TSRMLS_DC) -{ - cdb_free(c TSRMLS_CC); - cdb_findstart(c TSRMLS_CC); - c->fp = fp; -} -/* }}} */ - -/* {{{ cdb_read */ -int cdb_read(struct cdb *c, char *buf, unsigned int len, uint32 pos TSRMLS_DC) -{ - if (php_stream_seek(c->fp, pos, SEEK_SET) == -1) { - errno = EPROTO; - return -1; - } - while (len > 0) { - int r; - do { - r = php_stream_read(c->fp, buf, len); - } while ((r == -1) && (errno == EINTR)); - if (r == -1) - return -1; - if (r == 0) { - errno = EPROTO; - return -1; - } - buf += r; - len -= r; - } - return 0; -} -/* }}} */ - -/* {{{ cdb_findnext */ -int cdb_findnext(struct cdb *c, char *key, unsigned int len TSRMLS_DC) -{ - char buf[8]; - uint32 pos; - uint32 u; - - if (!c->loop) { - u = cdb_hash(key, len); - if (cdb_read(c, buf, 8, (u << 3) & 2047 TSRMLS_CC) == -1) - return -1; - uint32_unpack(buf + 4,&c->hslots); - if (!c->hslots) - return 0; - uint32_unpack(buf, &c->hpos); - c->khash = u; - u >>= 8; - u %= c->hslots; - u <<= 3; - c->kpos = c->hpos + u; - } - - while (c->loop < c->hslots) { - if (cdb_read(c, buf, 8, c->kpos TSRMLS_CC) == -1) - return -1; - uint32_unpack(buf + 4, &pos); - if (!pos) - return 0; - c->loop += 1; - c->kpos += 8; - if (c->kpos == c->hpos + (c->hslots << 3)) - c->kpos = c->hpos; - uint32_unpack(buf, &u); - if (u == c->khash) { - if (cdb_read(c, buf, 8, pos TSRMLS_CC) == -1) - return -1; - uint32_unpack(buf, &u); - if (u == len) - switch(cdb_match(c, key, len, pos + 8 TSRMLS_CC)) { - case -1: - return -1; - case 1: - uint32_unpack(buf + 4, &c->dlen); - c->dpos = pos + 8 + len; - return 1; - } - } - } - - return 0; -} -/* }}} */ - -/* {{{ cdb_find */ -int cdb_find(struct cdb *c, char *key, unsigned int len TSRMLS_DC) -{ - cdb_findstart(c TSRMLS_CC); - return cdb_findnext(c, key, len TSRMLS_CC); -} -/* }}} */ - -/* {{{ cdb_version */ -char *cdb_version() -{ - return "0.75, $Revision$"; -} -/* }}} */ diff --git a/ext/dba/libcdb/cdb.h b/ext/dba/libcdb/cdb.h deleted file mode 100644 index 6a3b08db34..0000000000 --- a/ext/dba/libcdb/cdb.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* incorporated from D.J.Bernstein's cdb-0.75 (http://cr.yp.to/cdb.html)*/ - -#ifndef CDB_H -#define CDB_H - -#include "uint32.h" - -#define CDB_HASHSTART 5381 - -struct cdb { - php_stream *fp; - uint32 loop; /* number of hash slots searched under this key */ - uint32 khash; /* initialized if loop is nonzero */ - uint32 kpos; /* initialized if loop is nonzero */ - uint32 hpos; /* initialized if loop is nonzero */ - uint32 hslots; /* initialized if loop is nonzero */ - uint32 dpos; /* initialized if cdb_findnext() returns 1 */ - uint32 dlen; /* initialized if cdb_findnext() returns 1 */ -}; - -uint32 cdb_hash(char *, unsigned int); - -void cdb_free(struct cdb * TSRMLS_DC); -void cdb_init(struct cdb *, php_stream *fp TSRMLS_DC); - -int cdb_read(struct cdb *, char *, unsigned int, uint32 TSRMLS_DC); - -void cdb_findstart(struct cdb * TSRMLS_DC); -int cdb_findnext(struct cdb *, char *, unsigned int TSRMLS_DC); -int cdb_find(struct cdb *, char *, unsigned int TSRMLS_DC); - -#define cdb_datapos(c) ((c)->dpos) -#define cdb_datalen(c) ((c)->dlen) - -char *cdb_version(); - -#endif diff --git a/ext/dba/libcdb/cdb_make.c b/ext/dba/libcdb/cdb_make.c deleted file mode 100644 index 1c3402e908..0000000000 --- a/ext/dba/libcdb/cdb_make.c +++ /dev/null @@ -1,246 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* incorporated from D.J.Bernstein's cdb-0.75 (http://cr.yp.to/cdb.html)*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#include <sys/types.h> -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <stdlib.h> -#include <stdio.h> -#include <errno.h> -#include "cdb.h" -#include "cdb_make.h" -#include "uint32.h" - -/* {{{ cdb_make_write */ -static int cdb_make_write(struct cdb_make *c, char *buf, uint32 sz TSRMLS_DC) { - return php_stream_write(c->fp, buf, sz) == sz ? 0 : -1; -} - -/* {{{ cdb_posplus */ -static int cdb_posplus(struct cdb_make *c, uint32 len) -{ - uint32 newpos = c->pos + len; - if (newpos < len) { - errno = ENOMEM; - return -1; - } - c->pos = newpos; - return 0; -} -/* }}} */ - -/* {{{ cdb_make_start */ -int cdb_make_start(struct cdb_make *c, php_stream * f TSRMLS_DC) -{ - c->head = 0; - c->split = 0; - c->hash = 0; - c->numentries = 0; - c->fp = f; - c->pos = sizeof(c->final); - if (php_stream_seek(f, c->pos, SEEK_SET) == -1) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Fseek failed"); - return -1; - } - return php_stream_tell(c->fp); -} -/* }}} */ - -/* {{{ cdb_make_addend */ -int cdb_make_addend(struct cdb_make *c, unsigned int keylen, unsigned int datalen, uint32 h TSRMLS_DC) -{ - struct cdb_hplist *head; - - head = c->head; - if (!head || (head->num >= CDB_HPLIST)) { - head = (struct cdb_hplist *) - emalloc(sizeof(struct cdb_hplist)); - if (!head) - return -1; - head->num = 0; - head->next = c->head; - c->head = head; - } - head->hp[head->num].h = h; - head->hp[head->num].p = c->pos; - ++head->num; - ++c->numentries; - if (cdb_posplus(c,8) == -1) - return -1; - if (cdb_posplus(c, keylen) == -1) - return -1; - if (cdb_posplus(c, datalen) == -1) - return -1; - return 0; -} -/* }}} */ - -/* {{{ cdb_make_addbegin */ -int cdb_make_addbegin(struct cdb_make *c, unsigned int keylen, unsigned int datalen TSRMLS_DC) -{ - char buf[8]; - - if (keylen > 0xffffffff) { - errno = ENOMEM; - return -1; - } - if (datalen > 0xffffffff) { - errno = ENOMEM; - return -1; - } - - uint32_pack(buf, keylen); - uint32_pack(buf + 4, datalen); - if (cdb_make_write(c, buf, 8 TSRMLS_CC) != 0) - return -1; - return 0; -} - -/* {{{ cdb_make_add */ -int cdb_make_add(struct cdb_make *c,char *key,unsigned int keylen,char *data,unsigned int datalen TSRMLS_DC) -{ - if (cdb_make_addbegin(c, keylen, datalen TSRMLS_CC) == -1) - return -1; - if (cdb_make_write(c, key, keylen TSRMLS_CC) != 0) - return -1; - if (cdb_make_write(c, data, datalen TSRMLS_CC) != 0) - return -1; - return cdb_make_addend(c, keylen, datalen, cdb_hash(key, keylen) TSRMLS_CC); -} -/* }}} */ - -/* {{{ cdb_make_finish */ -int cdb_make_finish(struct cdb_make *c TSRMLS_DC) -{ - char buf[8]; - int i; - uint32 len; - uint32 u; - uint32 memsize; - uint32 count; - uint32 where; - struct cdb_hplist *x; - struct cdb_hp *hp; - - for (i = 0;i < 256;++i) - c->count[i] = 0; - - for (x = c->head; x; x = x->next) { - i = x->num; - while (i--) - ++c->count[255 & x->hp[i].h]; - } - - memsize = 1; - for (i = 0;i < 256;++i) { - u = c->count[i] * 2; - if (u > memsize) - memsize = u; - } - - memsize += c->numentries; /* no overflow possible up to now */ - u = (uint32) 0 - (uint32) 1; - u /= sizeof(struct cdb_hp); - if (memsize > u) { - errno = ENOMEM; - return -1; - } - - c->split = (struct cdb_hp *) - emalloc(memsize * sizeof(struct cdb_hp)); - if (!c->split) - return -1; - - c->hash = c->split + c->numentries; - - u = 0; - for (i = 0;i < 256;++i) { - u += c->count[i]; /* bounded by numentries, so no overflow */ - c->start[i] = u; - } - - for (x = c->head; x; x = x->next) { - i = x->num; - while (i--) - c->split[--c->start[255 & x->hp[i].h]] = x->hp[i]; - } - - for (i = 0;i < 256;++i) { - count = c->count[i]; - - len = count + count; /* no overflow possible */ - uint32_pack(c->final + 8 * i,c->pos); - uint32_pack(c->final + 8 * i + 4,len); - - for (u = 0;u < len;++u) - c->hash[u].h = c->hash[u].p = 0; - - hp = c->split + c->start[i]; - for (u = 0;u < count;++u) { - where = (hp->h >> 8) % len; - while (c->hash[where].p) - if (++where == len) - where = 0; - c->hash[where] = *hp++; - } - - for (u = 0;u < len;++u) { - uint32_pack(buf, c->hash[u].h); - uint32_pack(buf + 4, c->hash[u].p); - if (cdb_make_write(c, buf, 8 TSRMLS_CC) != 0) - return -1; - if (cdb_posplus(c, 8) == -1) - return -1; - } - } - - if (c->split) - efree(c->split); - - for (x = c->head; x; c->head = x) { - x = x->next; - efree(c->head); - } - - if (php_stream_flush(c->fp) != 0) - return -1; - php_stream_rewind(c->fp); - if (php_stream_tell(c->fp) != 0) - return -1; - if (cdb_make_write(c, c->final, sizeof(c->final) TSRMLS_CC) != 0) - return -1; - return php_stream_flush(c->fp); -} -/* }}} */ - -/* {{{ cdb_make_version */ -char *cdb_make_version() -{ - return "0.75, $Revision$"; -} diff --git a/ext/dba/libcdb/cdb_make.h b/ext/dba/libcdb/cdb_make.h deleted file mode 100644 index ea3f40d314..0000000000 --- a/ext/dba/libcdb/cdb_make.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* incorporated from D.J.Bernstein's cdb-0.75 (http://cr.yp.to/cdb.html)*/ - -#ifndef CDB_MAKE_H -#define CDB_MAKE_H - -#include <stdio.h> -#include "uint32.h" - -#define CDB_HPLIST 1000 - -struct cdb_hp { - uint32 h; - uint32 p; -}; - -struct cdb_hplist { - struct cdb_hp hp[CDB_HPLIST]; - struct cdb_hplist *next; - int num; -} ; - -struct cdb_make { - /* char bspace[8192]; */ - char final[2048]; - uint32 count[256]; - uint32 start[256]; - struct cdb_hplist *head; - struct cdb_hp *split; /* includes space for hash */ - struct cdb_hp *hash; - uint32 numentries; - /* buffer b; */ - uint32 pos; - /* int fd; */ - php_stream * fp; -}; - -int cdb_make_start(struct cdb_make *, php_stream * TSRMLS_DC); -int cdb_make_addbegin(struct cdb_make *, unsigned int, unsigned int TSRMLS_DC); -int cdb_make_addend(struct cdb_make *, unsigned int, unsigned int, uint32 TSRMLS_DC); -int cdb_make_add(struct cdb_make *, char *, unsigned int, char *, unsigned int TSRMLS_DC); -int cdb_make_finish(struct cdb_make * TSRMLS_DC); -char *cdb_make_version(); - -#endif diff --git a/ext/dba/libcdb/uint32.c b/ext/dba/libcdb/uint32.c deleted file mode 100644 index 73b3067a30..0000000000 --- a/ext/dba/libcdb/uint32.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* incorporated from D.J.Bernstein's cdb-0.75 (http://cr.yp.to/cdb.html)*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" - -#include "uint32.h" - -/* {{{ uint32_pack */ -void uint32_pack(char *out, uint32 in) -{ - out[0] = in&0xff; in>>=8; - out[1] = in&0xff; in>>=8; - out[2] = in&0xff; in>>=8; - out[3] = in&0xff; -} -/* }}} */ - -/* {{{ uint32_unpack */ -void uint32_unpack(const char *in, uint32 *out) -{ - *out = (((uint32)(unsigned char)in[3])<<24) | - (((uint32)(unsigned char)in[2])<<16) | - (((uint32)(unsigned char)in[1])<<8) | - (((uint32)(unsigned char)in[0])); -} -/* }}} */ diff --git a/ext/dba/libcdb/uint32.h b/ext/dba/libcdb/uint32.h deleted file mode 100644 index 6783620ed3..0000000000 --- a/ext/dba/libcdb/uint32.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* incorporated from D.J.Bernstein's cdb-0.75 (http://cr.yp.to/cdb.html)*/ - -#ifndef UINT32_H -#define UINT32_H - -#if SIZEOF_INT == 4 -/* Most 32-bit and 64-bit systems have 32-bit ints */ -typedef unsigned int uint32; -#elif SIZEOF_LONG == 4 -/* 16-bit systems? */ -typedef unsigned long uint32; -#else -#error Need type which holds 32 bits -#endif - -void uint32_pack(char *out, uint32 in); -void uint32_unpack(const char *in, uint32 *out); - -#endif diff --git a/ext/dba/libflatfile/flatfile.c b/ext/dba/libflatfile/flatfile.c deleted file mode 100644 index 44ef3d53a3..0000000000 --- a/ext/dba/libflatfile/flatfile.c +++ /dev/null @@ -1,321 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - | based on ext/db/db.c by: | - | Rasmus Lerdorf <rasmus@php.net> | - | Jim Winstead <jimw@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" -#include "php_globals.h" -#include "safe_mode.h" - -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#if HAVE_UNISTD_H -#include <unistd.h> -#endif - -#include "flatfile.h" - -#define FLATFILE_BLOCK_SIZE 1024 - -/* - * ret = -1 means that database was opened for read-only - * ret = 0 success - * ret = 1 key already exists - nothing done - */ - -/* {{{ flatfile_store - */ -int flatfile_store(flatfile *dba, datum key_datum, datum value_datum, int mode TSRMLS_DC) { - if (mode == FLATFILE_INSERT) { - if (flatfile_findkey(dba, key_datum TSRMLS_CC)) { - return 1; - } - php_stream_seek(dba->fp, 0L, SEEK_END); - php_stream_printf(dba->fp TSRMLS_CC, "%d\n", key_datum.dsize); - php_stream_flush(dba->fp); - if (php_stream_write(dba->fp, key_datum.dptr, key_datum.dsize) < key_datum.dsize) { - return -1; - } - php_stream_printf(dba->fp TSRMLS_CC, "%d\n", value_datum.dsize); - php_stream_flush(dba->fp); - if (php_stream_write(dba->fp, value_datum.dptr, value_datum.dsize) < value_datum.dsize) { - return -1; - } - } else { /* FLATFILE_REPLACE */ - flatfile_delete(dba, key_datum TSRMLS_CC); - php_stream_printf(dba->fp TSRMLS_CC, "%d\n", key_datum.dsize); - php_stream_flush(dba->fp); - if (php_stream_write(dba->fp, key_datum.dptr, key_datum.dsize) < key_datum.dsize) { - return -1; - } - php_stream_printf(dba->fp TSRMLS_CC, "%d\n", value_datum.dsize); - if (php_stream_write(dba->fp, value_datum.dptr, value_datum.dsize) < value_datum.dsize) { - return -1; - } - } - - php_stream_flush(dba->fp); - return 0; -} -/* }}} */ - -/* {{{ flatfile_fetch - */ -datum flatfile_fetch(flatfile *dba, datum key_datum TSRMLS_DC) { - datum value_datum = {NULL, 0}; - char buf[16]; - - if (flatfile_findkey(dba, key_datum TSRMLS_CC)) { - if (php_stream_gets(dba->fp, buf, sizeof(buf))) { - value_datum.dsize = atoi(buf); - value_datum.dptr = emalloc(value_datum.dsize+1); - value_datum.dsize = php_stream_read(dba->fp, value_datum.dptr, value_datum.dsize); - } else { - value_datum.dptr = NULL; - value_datum.dsize = 0; - } - } - return value_datum; -} -/* }}} */ - -/* {{{ flatfile_delete - */ -int flatfile_delete(flatfile *dba, datum key_datum TSRMLS_DC) { - char *key = key_datum.dptr; - size_t size = key_datum.dsize; - size_t buf_size = FLATFILE_BLOCK_SIZE; - char *buf = emalloc(buf_size); - size_t num; - size_t pos; - - php_stream_rewind(dba->fp); - while(!php_stream_eof(dba->fp)) { - /* read in the length of the key name */ - if (!php_stream_gets(dba->fp, buf, 15)) { - break; - } - num = atoi(buf); - if (num >= buf_size) { - buf_size = num + FLATFILE_BLOCK_SIZE; - buf = erealloc(buf, buf_size); - } - pos = php_stream_tell(dba->fp); - - /* read in the key name */ - num = php_stream_read(dba->fp, buf, num); - if (num < 0) { - break; - } - - if (size == num && !memcmp(buf, key, size)) { - php_stream_seek(dba->fp, pos, SEEK_SET); - php_stream_putc(dba->fp, 0); - php_stream_flush(dba->fp); - php_stream_seek(dba->fp, 0L, SEEK_END); - efree(buf); - return SUCCESS; - } - - /* read in the length of the value */ - if (!php_stream_gets(dba->fp, buf, 15)) { - break; - } - num = atoi(buf); - if (num >= buf_size) { - buf_size = num + FLATFILE_BLOCK_SIZE; - buf = erealloc(buf, buf_size); - } - /* read in the value */ - num = php_stream_read(dba->fp, buf, num); - if (num < 0) { - break; - } - } - efree(buf); - return FAILURE; -} -/* }}} */ - -/* {{{ flatfile_findkey - */ -int flatfile_findkey(flatfile *dba, datum key_datum TSRMLS_DC) { - size_t buf_size = FLATFILE_BLOCK_SIZE; - char *buf = emalloc(buf_size); - size_t num; - int ret=0; - void *key = key_datum.dptr; - size_t size = key_datum.dsize; - - php_stream_rewind(dba->fp); - while (!php_stream_eof(dba->fp)) { - if (!php_stream_gets(dba->fp, buf, 15)) { - break; - } - num = atoi(buf); - if (num >= buf_size) { - buf_size = num + FLATFILE_BLOCK_SIZE; - buf = erealloc(buf, buf_size); - } - num = php_stream_read(dba->fp, buf, num); - if (num < 0) { - break; - } - if (size == num) { - if (!memcmp(buf, key, size)) { - ret = 1; - break; - } - } - if (!php_stream_gets(dba->fp, buf, 15)) { - break; - } - num = atoi(buf); - if (num >= buf_size) { - buf_size = num + FLATFILE_BLOCK_SIZE; - buf = erealloc(buf, buf_size); - } - num = php_stream_read(dba->fp, buf, num); - if (num < 0) { - break; - } - } - efree(buf); - return ret; -} -/* }}} */ - -/* {{{ flatfile_firstkey - */ -datum flatfile_firstkey(flatfile *dba TSRMLS_DC) { - datum res; - size_t num; - size_t buf_size = FLATFILE_BLOCK_SIZE; - char *buf = emalloc(buf_size); - - php_stream_rewind(dba->fp); - while(!php_stream_eof(dba->fp)) { - if (!php_stream_gets(dba->fp, buf, 15)) { - break; - } - num = atoi(buf); - if (num >= buf_size) { - buf_size = num + FLATFILE_BLOCK_SIZE; - buf = erealloc(buf, buf_size); - } - num = php_stream_read(dba->fp, buf, num); - if (num < 0) { - break; - } - if (*(buf) != 0) { - dba->CurrentFlatFilePos = php_stream_tell(dba->fp); - res.dptr = buf; - res.dsize = num; - return res; - } - if (!php_stream_gets(dba->fp, buf, 15)) { - break; - } - num = atoi(buf); - if (num >= buf_size) { - buf_size = num + FLATFILE_BLOCK_SIZE; - buf = erealloc(buf, buf_size); - } - num = php_stream_read(dba->fp, buf, num); - if (num < 0) { - break; - } - } - efree(buf); - res.dptr = NULL; - res.dsize = 0; - return res; -} -/* }}} */ - -/* {{{ flatfile_nextkey - */ -datum flatfile_nextkey(flatfile *dba TSRMLS_DC) { - datum res; - size_t num; - size_t buf_size = FLATFILE_BLOCK_SIZE; - char *buf = emalloc(buf_size); - - php_stream_seek(dba->fp, dba->CurrentFlatFilePos, SEEK_SET); - while(!php_stream_eof(dba->fp)) { - if (!php_stream_gets(dba->fp, buf, 15)) { - break; - } - num = atoi(buf); - if (num >= buf_size) { - buf_size = num + FLATFILE_BLOCK_SIZE; - buf = erealloc(buf, buf_size); - } - num = php_stream_read(dba->fp, buf, num); - if (num < 0) { - break; - } - if (!php_stream_gets(dba->fp, buf, 15)) { - break; - } - num = atoi(buf); - if (num >= buf_size) { - buf_size = num + FLATFILE_BLOCK_SIZE; - buf = erealloc(buf, buf_size); - } - num = php_stream_read(dba->fp, buf, num); - if (num < 0) { - break; - } - if (*(buf)!=0) { - dba->CurrentFlatFilePos = php_stream_tell(dba->fp); - res.dptr = buf; - res.dsize = num; - return res; - } - } - efree(buf); - res.dptr = NULL; - res.dsize = 0; - return res; -} -/* }}} */ - -/* {{{ flatfile_version */ -char *flatfile_version() -{ - return "1.0, $Revision$"; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/dba/libflatfile/flatfile.h b/ext/dba/libflatfile/flatfile.h deleted file mode 100644 index 74e1179e35..0000000000 --- a/ext/dba/libflatfile/flatfile.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef PHP_LIB_FLATFILE_H -#define PHP_LIB_FLATFILE_H - -typedef struct { - char *dptr; - size_t dsize; -} datum; - -typedef struct { - char *lockfn; - int lockfd; - php_stream *fp; - size_t CurrentFlatFilePos; - datum nextkey; -} flatfile; - -#define FLATFILE_INSERT 1 -#define FLATFILE_REPLACE 0 - -int flatfile_store(flatfile *dba, datum key_datum, datum value_datum, int mode TSRMLS_DC); -datum flatfile_fetch(flatfile *dba, datum key_datum TSRMLS_DC); -int flatfile_delete(flatfile *dba, datum key_datum TSRMLS_DC); -int flatfile_findkey(flatfile *dba, datum key_datum TSRMLS_DC); -datum flatfile_firstkey(flatfile *dba TSRMLS_DC); -datum flatfile_nextkey(flatfile *dba TSRMLS_DC); -char *flatfile_version(); - -#endif diff --git a/ext/dba/libinifile/inifile.c b/ext/dba/libinifile/inifile.c deleted file mode 100644 index 6e3d94dc4a..0000000000 --- a/ext/dba/libinifile/inifile.c +++ /dev/null @@ -1,598 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" -#include "php_globals.h" -#include "safe_mode.h" -#include "php_network.h" - -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#if HAVE_UNISTD_H -#include <unistd.h> -#endif - -#include "inifile.h" - -/* ret = -1 means that database was opened for read-only - * ret = 0 success - * ret = 1 key already exists - nothing done - */ - -/* {{{ inifile_version */ -char *inifile_version() -{ - return "1.0, $Revision$"; -} -/* }}} */ - -/* {{{ inifile_free_key */ -void inifile_key_free(key_type *key) -{ - if (key->group) { - efree(key->group); - } - if (key->name) { - efree(key->name); - } - memset(key, 0, sizeof(key_type)); -} -/* }}} */ - -/* {{{ inifile_free_val */ -void inifile_val_free(val_type *val) -{ - if (val->value) { - efree(val->value); - } - memset(val, 0, sizeof(val_type)); -} -/* }}} */ - -/* {{{ inifile_free_val */ -void inifile_line_free(line_type *ln) -{ - inifile_key_free(&ln->key); - inifile_val_free(&ln->val); - ln->pos = 0; -} -/* }}} */ - -/* {{{ inifile_alloc */ -inifile * inifile_alloc(php_stream *fp, int readonly, int persistent TSRMLS_DC) -{ - inifile *dba; - int fd = 0; - - if (!readonly) { - if (!php_stream_truncate_supported(fp)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't truncate this stream"); - return NULL; - } - if (SUCCESS != php_stream_cast(fp, PHP_STREAM_AS_FD, (void*)&fd, 1)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not cast stream"); - return NULL; - } - } - dba = pemalloc(sizeof(inifile), persistent); - memset(dba, 0, sizeof(inifile)); - dba->fp = fp; - dba->fd = fd; - dba->readonly = readonly; - return dba; -} -/* }}} */ - -/* {{{ inifile_free */ -void inifile_free(inifile *dba, int persistent) -{ - if (dba) { - inifile_line_free(&dba->curr); - inifile_line_free(&dba->next); - pefree(dba, persistent); - } -} -/* }}} */ - -/* {{{ inifile_key_split */ -key_type inifile_key_split(const char *group_name) -{ - key_type key; - char *name; - - if (group_name[0] == '[' && (name = strchr(group_name, ']')) != NULL) { - key.group = estrndup(group_name+1, name - (group_name + 1)); - key.name = estrdup(name+1); - } else { - key.group = estrdup(""); - key.name = estrdup(group_name); - } - return key; -} -/* }}} */ - -/* {{{ inifile_key_string */ -char * inifile_key_string(const key_type *key) -{ - if (key->group && *key->group) { - char *result; - spprintf(&result, 0, "[%s]%s", key->group, key->name ? key->name : ""); - return result; - } else if (key->name) { - return estrdup(key->name); - } else { - return NULL; - } -} -/* }}} */ - -/* {{{ etrim */ -static char *etrim(const char *str) -{ - char *val; - size_t l; - - if (!str) { - return NULL; - } - val = (char*)str; - while (strchr(" \t\r\n", *val)) { - val++; - } - l = strlen(val); - while (l && (strchr(" \t\r\n", val[l-1]))) { - l--; - } - return estrndup(val, l); -} -/* }}} */ - -/* {{{ inifile_findkey - */ -static int inifile_read(inifile *dba, line_type *ln TSRMLS_DC) { - char *fline; - char *pos; - - inifile_val_free(&ln->val); - while ((fline = php_stream_gets(dba->fp, NULL, 0)) != NULL) { - if (fline) { - if (fline[0] == '[') { - /* A value name cannot start with '[' - * So either we find a ']' or we found an error - */ - pos = strchr(fline+1, ']'); - if (pos) { - *pos = '\0'; - inifile_key_free(&ln->key); - ln->key.group = etrim(fline+1); - ln->key.name = estrdup(""); - ln->pos = php_stream_tell(dba->fp); - efree(fline); - return 1; - } else { - efree(fline); - continue; - } - } else { - pos = strchr(fline, '='); - if (pos) { - *pos = '\0'; - /* keep group or make empty if not existent */ - if (!ln->key.group) { - ln->key.group = estrdup(""); - } - if (ln->key.name) { - efree(ln->key.name); - } - ln->key.name = etrim(fline); - ln->val.value = etrim(pos+1); - ln->pos = php_stream_tell(dba->fp); - efree(fline); - return 1; - } else { - /* simply ignore lines without '=' - * those should be comments - */ - efree(fline); - continue; - } - } - } - } - inifile_line_free(ln); - return 0; -} -/* }}} */ - -/* {{{ inifile_key_cmp */ -/* 0 = EQUAL - * 1 = GROUP-EQUAL,NAME-DIFFERENT - * 2 = DIFFERENT - */ -static int inifile_key_cmp(const key_type *k1, const key_type *k2 TSRMLS_DC) -{ - assert(k1->group && k1->name && k2->group && k2->name); - - if (!strcasecmp(k1->group, k2->group)) { - if (!strcasecmp(k1->name, k2->name)) { - return 0; - } else { - return 1; - } - } else { - return 2; - } -} -/* }}} */ - -/* {{{ inifile_fetch - */ -val_type inifile_fetch(inifile *dba, const key_type *key, int skip TSRMLS_DC) { - line_type ln = {{NULL,NULL},{NULL}}; - val_type val; - int res, grp_eq = 0; - - if (skip == -1 && dba->next.key.group && dba->next.key.name && !inifile_key_cmp(&dba->next.key, key TSRMLS_CC)) { - /* we got position already from last fetch */ - php_stream_seek(dba->fp, dba->next.pos, SEEK_SET); - } else { - /* specific instance or not same key -> restart search */ - /* the slow way: restart and seacrch */ - php_stream_rewind(dba->fp); - inifile_line_free(&dba->next); - } - if (skip == -1) { - skip = 0; - } - while(inifile_read(dba, &ln TSRMLS_CC)) { - if (!(res=inifile_key_cmp(&ln.key, key TSRMLS_CC))) { - if (!skip) { - val.value = estrdup(ln.val.value ? ln.val.value : ""); - /* allow faster access by updating key read into next */ - inifile_line_free(&dba->next); - dba->next = ln; - dba->next.pos = php_stream_tell(dba->fp); - return val; - } - skip--; - } else if (res == 1) { - grp_eq = 1; - } else if (grp_eq) { - /* we are leaving group now: that means we cannot find the key */ - break; - } - } - inifile_line_free(&ln); - dba->next.pos = php_stream_tell(dba->fp); - return ln.val; -} -/* }}} */ - -/* {{{ inifile_firstkey - */ -int inifile_firstkey(inifile *dba TSRMLS_DC) { - inifile_line_free(&dba->curr); - dba->curr.pos = 0; - return inifile_nextkey(dba TSRMLS_CC); -} -/* }}} */ - -/* {{{ inifile_nextkey - */ -int inifile_nextkey(inifile *dba TSRMLS_DC) { - line_type ln = {{NULL,NULL},{NULL}}; - - /*inifile_line_free(&dba->next); ??? */ - php_stream_seek(dba->fp, dba->curr.pos, SEEK_SET); - ln.key.group = estrdup(dba->curr.key.group ? dba->curr.key.group : ""); - inifile_read(dba, &ln TSRMLS_CC); - inifile_line_free(&dba->curr); - dba->curr = ln; - return ln.key.group || ln.key.name; -} -/* }}} */ - -/* {{{ inifile_truncate - */ -static int inifile_truncate(inifile *dba, size_t size TSRMLS_DC) -{ - int res; - - if ((res=php_stream_truncate_set_size(dba->fp, size)) != 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error in ftruncate: %d", res); - return FAILURE; - } - php_stream_seek(dba->fp, size, SEEK_SET); - return SUCCESS; -} -/* }}} */ - -/* {{{ inifile_find_group - * if found pos_grp_start points to "[group_name]" - */ -static int inifile_find_group(inifile *dba, const key_type *key, size_t *pos_grp_start TSRMLS_DC) -{ - int ret = FAILURE; - - php_stream_flush(dba->fp); - php_stream_seek(dba->fp, 0, SEEK_SET); - inifile_line_free(&dba->curr); - inifile_line_free(&dba->next); - - if (key->group && strlen(key->group)) { - int res; - line_type ln = {{NULL,NULL},{NULL}}; - - res = 1; - while(inifile_read(dba, &ln TSRMLS_CC)) { - if ((res=inifile_key_cmp(&ln.key, key TSRMLS_CC)) < 2) { - ret = SUCCESS; - break; - } - *pos_grp_start = php_stream_tell(dba->fp); - } - inifile_line_free(&ln); - } else { - *pos_grp_start = 0; - ret = SUCCESS; - } - if (ret == FAILURE) { - *pos_grp_start = php_stream_tell(dba->fp); - } - return ret; -} -/* }}} */ - -/* {{{ inifile_next_group - * only valid after a call to inifile_find_group - * if any next group is found pos_grp_start points to "[group_name]" or whitespace before that - */ -static int inifile_next_group(inifile *dba, const key_type *key, size_t *pos_grp_start TSRMLS_DC) -{ - int ret = FAILURE; - line_type ln = {{NULL,NULL},{NULL}}; - - *pos_grp_start = php_stream_tell(dba->fp); - ln.key.group = estrdup(key->group); - while(inifile_read(dba, &ln TSRMLS_CC)) { - if (inifile_key_cmp(&ln.key, key TSRMLS_CC) == 2) { - ret = SUCCESS; - break; - } - *pos_grp_start = php_stream_tell(dba->fp); - } - inifile_line_free(&ln); - return ret; -} -/* }}} */ - -/* {{{ inifile_copy_to - */ -static int inifile_copy_to(inifile *dba, size_t pos_start, size_t pos_end, inifile **ini_copy TSRMLS_DC) -{ - php_stream *fp; - - if (pos_start == pos_end) { - *ini_copy = NULL; - return SUCCESS; - } - if ((fp = php_stream_temp_create(0, 64 * 1024)) == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not create temporary stream"); - *ini_copy = NULL; - return FAILURE; - } - - if ((*ini_copy = inifile_alloc(fp, 1, 0 TSRMLS_CC)) == NULL) { - /* writes error */ - return FAILURE; - } - php_stream_seek(dba->fp, pos_start, SEEK_SET); - if (!php_stream_copy_to_stream(dba->fp, fp, pos_end - pos_start)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy group [%d - %d] to temporary stream", pos_start, pos_end); - return FAILURE; - } - return SUCCESS; -} -/* }}} */ - -/* {{{ inifile_filter - * copy from to dba while ignoring key name (group must equal) - */ -static int inifile_filter(inifile *dba, inifile *from, const key_type *key TSRMLS_DC) -{ - size_t pos_start = 0, pos_next = 0, pos_curr; - int ret = SUCCESS; - line_type ln = {{NULL,NULL},{NULL}}; - - php_stream_seek(from->fp, 0, SEEK_SET); - php_stream_seek(dba->fp, 0, SEEK_END); - while(inifile_read(from, &ln TSRMLS_CC)) { - switch(inifile_key_cmp(&ln.key, key TSRMLS_CC)) { - case 0: - pos_curr = php_stream_tell(from->fp); - if (pos_start != pos_next) { - php_stream_seek(from->fp, pos_start, SEEK_SET); - if (!php_stream_copy_to_stream(from->fp, dba->fp, pos_next - pos_start)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy [%d - %d] from temporary stream", pos_next, pos_start); - ret = FAILURE; - } - php_stream_seek(from->fp, pos_curr, SEEK_SET); - } - pos_next = pos_start = pos_curr; - break; - case 1: - pos_next = php_stream_tell(from->fp); - break; - case 2: - /* the function is meant to process only entries from same group */ - assert(0); - break; - } - } - if (pos_start != pos_next) { - php_stream_seek(from->fp, pos_start, SEEK_SET); - if (!php_stream_copy_to_stream(from->fp, dba->fp, pos_next - pos_start)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy [%d - %d] from temporary stream", pos_next, pos_start); - ret = FAILURE; - } - } - inifile_line_free(&ln); - return SUCCESS; -} -/* }}} */ - -/* {{{ inifile_delete_replace_append - */ -static int inifile_delete_replace_append(inifile *dba, const key_type *key, const val_type *value, int append TSRMLS_DC) -{ - size_t pos_grp_start, pos_grp_next; - inifile *ini_tmp = NULL; - php_stream *fp_tmp = NULL; - int ret; - - /* 1) Search group start - * 2) Search next group - * 3) If not append: Copy group to ini_tmp - * 4) Open temp_stream and copy remainder - * 5) Truncate stream - * 6) If not append AND key.name given: Filtered copy back from ini_tmp - * to stream. Otherwise the user wanted to delete the group. - * 7) Append value if given - * 8) Append temporary stream - */ - - assert(!append || (key->name && value)); /* missuse */ - - /* 1 - 3 */ - inifile_find_group(dba, key, &pos_grp_start TSRMLS_CC); - inifile_next_group(dba, key, &pos_grp_next TSRMLS_CC); - if (append) { - ret = SUCCESS; - } else { - ret = inifile_copy_to(dba, pos_grp_start, pos_grp_next, &ini_tmp TSRMLS_CC); - } - - /* 4 */ - if (ret == SUCCESS) { - fp_tmp = php_stream_temp_create(0, 64 * 1024); - if (!fp_tmp) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not create temporary stream"); - ret = FAILURE; - } else { - php_stream_seek(dba->fp, 0, SEEK_END); - if (pos_grp_next != php_stream_tell(dba->fp)) { - php_stream_seek(dba->fp, pos_grp_next, SEEK_SET); - if (!php_stream_copy_to_stream(dba->fp, fp_tmp, PHP_STREAM_COPY_ALL)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not copy remainder to temporary stream"); - ret = FAILURE; - } - } - } - } - - /* 5 */ - if (ret == SUCCESS) { - ret = inifile_truncate(dba, append ? pos_grp_next : pos_grp_start TSRMLS_CC); /* writes error on fail */ - } - - if (ret == SUCCESS) { - if (key->name && strlen(key->name)) { - /* 6 */ - if (!append && ini_tmp) { - ret = inifile_filter(dba, ini_tmp, key TSRMLS_CC); - } - - /* 7 */ - /* important: do not query ret==SUCCESS again: inifile_filter might fail but - * however next operation must be done. - */ - if (value) { - if (pos_grp_start == pos_grp_next && key->group && strlen(key->group)) { - php_stream_printf(dba->fp TSRMLS_CC, "[%s]\n", key->group); - } - php_stream_printf(dba->fp TSRMLS_CC, "%s=%s\n", key->name, value->value ? value->value : ""); - } - } - - /* 8 */ - /* important: do not query ret==SUCCESS again: inifile_filter might fail but - * however next operation must be done. - */ - if (fp_tmp && php_stream_tell(fp_tmp)) { - php_stream_seek(fp_tmp, 0, SEEK_SET); - php_stream_seek(dba->fp, 0, SEEK_END); - if (!php_stream_copy_to_stream(fp_tmp, dba->fp, PHP_STREAM_COPY_ALL)) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not copy from temporary stream - ini file truncated"); - ret = FAILURE; - } - } - } - - if (ini_tmp) { - php_stream_close(ini_tmp->fp); - inifile_free(ini_tmp, 0); - } - if (fp_tmp) { - php_stream_close(fp_tmp); - } - php_stream_flush(dba->fp); - php_stream_seek(dba->fp, 0, SEEK_SET); - - return ret; -} -/* }}} */ - -/* {{{ inifile_delete - */ -int inifile_delete(inifile *dba, const key_type *key TSRMLS_DC) -{ - return inifile_delete_replace_append(dba, key, NULL, 0 TSRMLS_CC); -} -/* }}} */ - -/* {{{ inifile_relace - */ -int inifile_replace(inifile *dba, const key_type *key, const val_type *value TSRMLS_DC) -{ - return inifile_delete_replace_append(dba, key, value, 0 TSRMLS_CC); -} -/* }}} */ - -/* {{{ inifile_append - */ -int inifile_append(inifile *dba, const key_type *key, const val_type *value TSRMLS_DC) -{ - return inifile_delete_replace_append(dba, key, value, 1 TSRMLS_CC); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/dba/libinifile/inifile.h b/ext/dba/libinifile/inifile.h deleted file mode 100644 index f0c17c369c..0000000000 --- a/ext/dba/libinifile/inifile.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef PHP_LIB_INIFILE_H -#define PHP_LIB_INIFILE_H - -typedef struct { - char *group; - char *name; -} key_type; - -typedef struct { - char *value; -} val_type; - -typedef struct { - key_type key; - val_type val; - size_t pos; -} line_type; - -typedef struct { - char *lockfn; - int lockfd; - php_stream *fp; - int fd; - int readonly; - line_type curr; - line_type next; -} inifile; - -val_type inifile_fetch(inifile *dba, const key_type *key, int skip TSRMLS_DC); -int inifile_firstkey(inifile *dba TSRMLS_DC); -int inifile_nextkey(inifile *dba TSRMLS_DC); -int inifile_delete(inifile *dba, const key_type *key TSRMLS_DC); -int inifile_replace(inifile *dba, const key_type *key, const val_type *val TSRMLS_DC); -int inifile_append(inifile *dba, const key_type *key, const val_type *val TSRMLS_DC); -char *inifile_version(); - -key_type inifile_key_split(const char *group_name); -char * inifile_key_string(const key_type *key); - -void inifile_key_free(key_type *key); -void inifile_val_free(val_type *val); -void inifile_line_free(line_type *ln); - -inifile * inifile_alloc(php_stream *fp, int readonly, int persistent TSRMLS_DC); -void inifile_free(inifile *dba, int persistent); - -#endif diff --git a/ext/dba/php_cdb.h b/ext/dba/php_cdb.h deleted file mode 100644 index a046f0796b..0000000000 --- a/ext/dba/php_cdb.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef PHP_CDB_H -#define PHP_CDB_H - -#if DBA_CDB - -#include "php_dba.h" - -DBA_FUNCS(cdb); - -#endif - -#endif diff --git a/ext/dba/php_db2.h b/ext/dba/php_db2.h deleted file mode 100644 index 2a95223a85..0000000000 --- a/ext/dba/php_db2.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef PHP_DB2_H -#define PHP_DB2_H - -#if DBA_DB2 - -#include "php_dba.h" - -DBA_FUNCS(db2); - -#endif - -#endif diff --git a/ext/dba/php_db3.h b/ext/dba/php_db3.h deleted file mode 100644 index 58bb0b62a0..0000000000 --- a/ext/dba/php_db3.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef PHP_DB3_H -#define PHP_DB3_H - -#if DBA_DB3 - -#include "php_dba.h" - -DBA_FUNCS(db3); - -#endif - -#endif diff --git a/ext/dba/php_db4.h b/ext/dba/php_db4.h deleted file mode 100644 index fa814c3f5e..0000000000 --- a/ext/dba/php_db4.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef PHP_DB4_H -#define PHP_DB4_H - -#if DBA_DB4 - -#include "php_dba.h" - -DBA_FUNCS(db4); - -#endif - -#endif diff --git a/ext/dba/php_dba.h b/ext/dba/php_dba.h deleted file mode 100644 index 18ace81984..0000000000 --- a/ext/dba/php_dba.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 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 | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef PHP_DBA_H -#define PHP_DBA_H - -#if HAVE_DBA - -typedef enum { - /* do not allow 0 here */ - DBA_READER = 1, - DBA_WRITER, - DBA_TRUNC, - DBA_CREAT -} dba_mode_t; - -typedef struct dba_lock { - php_stream *fp; - int fd; - char *name; - int mode; /* LOCK_EX,LOCK_SH */ -} dba_lock; - -typedef struct dba_info { - /* public */ - void *dbf; /* ptr to private data or whatever */ - char *path; - dba_mode_t mode; - php_stream *fp; /* this is the database stream for builtin handlers */ - /* arg[cv] are only available when the dba_open handler is called! */ - int argc; - zval ***argv; - /* private */ - int flags; /* whether and how dba did locking and other flags*/ - struct dba_handler *hnd; - dba_lock lock; -} dba_info; - -#define DBA_LOCK_READER (0x0001) -#define DBA_LOCK_WRITER (0x0002) -#define DBA_LOCK_CREAT (0x0004) -#define DBA_LOCK_TRUNC (0x0008) - -#define DBA_LOCK_EXT (0) -#define DBA_LOCK_ALL (DBA_LOCK_READER|DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC) -#define DBA_LOCK_WCT (DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC) - -#define DBA_STREAM_OPEN (0x0010) -#define DBA_PERSISTENT (0x0020) - -extern zend_module_entry dba_module_entry; -#define dba_module_ptr &dba_module_entry - -typedef struct dba_handler { - char *name; /* handler name */ - int flags; /* whether and how dba does locking and other flags*/ - int (*open)(dba_info *, char **error TSRMLS_DC); - void (*close)(dba_info * TSRMLS_DC); - char* (*fetch)(dba_info *, char *, int, int, int * TSRMLS_DC); - int (*update)(dba_info *, char *, int, char *, int, int TSRMLS_DC); - int (*exists)(dba_info *, char *, int TSRMLS_DC); - int (*delete)(dba_info *, char *, int TSRMLS_DC); - char* (*firstkey)(dba_info *, int * TSRMLS_DC); - char* (*nextkey)(dba_info *, int * TSRMLS_DC); - int (*optimize)(dba_info * TSRMLS_DC); - int (*sync)(dba_info * TSRMLS_DC); - char* (*info)(struct dba_handler *hnd, dba_info * TSRMLS_DC); - /* dba_info==NULL: Handler info, dba_info!=NULL: Database info */ -} dba_handler; - -/* common prototypes which must be supplied by modules */ - -#define DBA_OPEN_FUNC(x) \ - int dba_open_##x(dba_info *info, char **error TSRMLS_DC) -#define DBA_CLOSE_FUNC(x) \ - void dba_close_##x(dba_info *info TSRMLS_DC) -#define DBA_FETCH_FUNC(x) \ - char *dba_fetch_##x(dba_info *info, char *key, int keylen, int skip, int *newlen TSRMLS_DC) -#define DBA_UPDATE_FUNC(x) \ - int dba_update_##x(dba_info *info, char *key, int keylen, char *val, int vallen, int mode TSRMLS_DC) -#define DBA_EXISTS_FUNC(x) \ - int dba_exists_##x(dba_info *info, char *key, int keylen TSRMLS_DC) -#define DBA_DELETE_FUNC(x) \ - int dba_delete_##x(dba_info *info, char *key, int keylen TSRMLS_DC) -#define DBA_FIRSTKEY_FUNC(x) \ - char *dba_firstkey_##x(dba_info *info, int *newlen TSRMLS_DC) -#define DBA_NEXTKEY_FUNC(x) \ - char *dba_nextkey_##x(dba_info *info, int *newlen TSRMLS_DC) -#define DBA_OPTIMIZE_FUNC(x) \ - int dba_optimize_##x(dba_info *info TSRMLS_DC) -#define DBA_SYNC_FUNC(x) \ - int dba_sync_##x(dba_info *info TSRMLS_DC) -#define DBA_INFO_FUNC(x) \ - char *dba_info_##x(dba_handler *hnd, dba_info *info TSRMLS_DC) - -#define DBA_FUNCS(x) \ - DBA_OPEN_FUNC(x); \ - DBA_CLOSE_FUNC(x); \ - DBA_FETCH_FUNC(x); \ - DBA_UPDATE_FUNC(x); \ - DBA_DELETE_FUNC(x); \ - DBA_EXISTS_FUNC(x); \ - DBA_FIRSTKEY_FUNC(x); \ - DBA_NEXTKEY_FUNC(x); \ - DBA_OPTIMIZE_FUNC(x); \ - DBA_SYNC_FUNC(x); \ - DBA_INFO_FUNC(x) - -#define VALLEN(p) Z_STRVAL_PP(p), Z_STRLEN_PP(p) - -PHP_FUNCTION(dba_open); -PHP_FUNCTION(dba_popen); -PHP_FUNCTION(dba_close); -PHP_FUNCTION(dba_firstkey); -PHP_FUNCTION(dba_nextkey); -PHP_FUNCTION(dba_replace); -PHP_FUNCTION(dba_insert); -PHP_FUNCTION(dba_delete); -PHP_FUNCTION(dba_exists); -PHP_FUNCTION(dba_fetch); -PHP_FUNCTION(dba_optimize); -PHP_FUNCTION(dba_sync); -PHP_FUNCTION(dba_handlers); -PHP_FUNCTION(dba_list); - -#else -#define dba_module_ptr NULL -#endif - -#define phpext_dba_ptr dba_module_ptr - -#endif diff --git a/ext/dba/php_dbm.h b/ext/dba/php_dbm.h deleted file mode 100644 index 4c963d18ed..0000000000 --- a/ext/dba/php_dbm.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef PHP_DBM_H -#define PHP_DBM_H - -#if DBA_DBM - -#include "php_dba.h" - -DBA_FUNCS(dbm); - -#endif - -#endif diff --git a/ext/dba/php_flatfile.h b/ext/dba/php_flatfile.h deleted file mode 100644 index afa9f6d5d3..0000000000 --- a/ext/dba/php_flatfile.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef PHP_FLATFILE_H -#define PHP_FLATFILE_H - -#if DBA_FLATFILE - -#include "php_dba.h" - -DBA_FUNCS(flatfile); - -#endif - -#endif diff --git a/ext/dba/php_gdbm.h b/ext/dba/php_gdbm.h deleted file mode 100644 index 3068404cfe..0000000000 --- a/ext/dba/php_gdbm.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef PHP_GDBM_H -#define PHP_GDBM_H - -#if DBA_GDBM - -#include "php_dba.h" - -DBA_FUNCS(gdbm); - -#endif - -#endif diff --git a/ext/dba/php_inifile.h b/ext/dba/php_inifile.h deleted file mode 100644 index 69444df3c6..0000000000 --- a/ext/dba/php_inifile.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef PHP_INIFILE_H -#define PHP_INIFILE_H - -#if DBA_INIFILE - -#include "php_dba.h" - -DBA_FUNCS(inifile); - -#endif - -#endif diff --git a/ext/dba/php_ndbm.h b/ext/dba/php_ndbm.h deleted file mode 100644 index b1ebf15af3..0000000000 --- a/ext/dba/php_ndbm.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef PHP_NDBM_H -#define PHP_NDBM_H - -#if DBA_NDBM - -#include "php_dba.h" - -DBA_FUNCS(ndbm); - -#endif - -#endif diff --git a/ext/dba/tests/dba001.phpt b/ext/dba/tests/dba001.phpt deleted file mode 100644 index 3d617fb2c2..0000000000 --- a/ext/dba/tests/dba001.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -DBA File Creation Test ---SKIPIF-- -<?php - require_once('skipif.inc'); - die("info $HND handler used"); -?> ---FILE-- -<?php - require_once('test.inc'); - echo "database handler: $handler\n"; - if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { - echo "database file created\n"; - dba_close($db_file); - } else { - echo "$db_file does not exist\n"; - } -?> ---EXPECTF-- -database handler: %s -database file created
\ No newline at end of file diff --git a/ext/dba/tests/dba002.phpt b/ext/dba/tests/dba002.phpt deleted file mode 100644 index 3f862e38c5..0000000000 --- a/ext/dba/tests/dba002.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -DBA Insert/Fetch Test ---SKIPIF-- -<?php - require_once('skipif.inc'); - die("info $HND handler used"); -?> ---FILE-- -<?php - require_once('test.inc'); - echo "database handler: $handler\n"; - if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { - dba_insert("key1", "This is a test insert", $db_file); - echo dba_fetch("key1", $db_file); - dba_close($db_file); - } else { - echo "Error creating database\n"; - } -?> ---EXPECTF-- -database handler: %s -This is a test insert diff --git a/ext/dba/tests/dba003.phpt b/ext/dba/tests/dba003.phpt deleted file mode 100644 index 617ae91891..0000000000 --- a/ext/dba/tests/dba003.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -DBA Insert/Replace/Fetch Test ---SKIPIF-- -<?php - require_once('skipif.inc'); - die("info $HND handler used"); -?> ---FILE-- -<?php - require_once('test.inc'); - echo "database handler: $handler\n"; - if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { - dba_insert("key1", "This is a test insert", $db_file); - dba_replace("key1", "This is the replacement text", $db_file); - $a = dba_fetch("key1", $db_file); - dba_close($db_file); - echo $a; - } else { - echo "Error creating database\n"; - } -?> ---EXPECTF-- -database handler: %s -This is the replacement text diff --git a/ext/dba/tests/dba004.phpt b/ext/dba/tests/dba004.phpt deleted file mode 100644 index 3b1f29c7dd..0000000000 --- a/ext/dba/tests/dba004.phpt +++ /dev/null @@ -1,28 +0,0 @@ ---TEST-- -DBA Multiple Insert/Fetch Test ---SKIPIF-- -<?php - require_once('skipif.inc'); - die("info $HND handler used"); -?> ---FILE-- -<?php - require_once('test.inc'); - echo "database handler: $handler\n"; - if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { - dba_insert("key1", "Content String 1", $db_file); - dba_insert("key2", "Content String 2", $db_file); - dba_insert("key3", "Third Content String", $db_file); - dba_insert("key4", "Another Content String", $db_file); - dba_insert("key5", "The last content string", $db_file); - $a = dba_fetch("key4", $db_file); - $b = dba_fetch("key2", $db_file); - dba_close($db_file); - echo "$a $b"; - } else { - echo "Error creating database\n"; - } -?> ---EXPECTF-- -database handler: %s -Another Content String Content String 2 diff --git a/ext/dba/tests/dba005.phpt b/ext/dba/tests/dba005.phpt deleted file mode 100644 index 5a933c48f9..0000000000 --- a/ext/dba/tests/dba005.phpt +++ /dev/null @@ -1,35 +0,0 @@ ---TEST-- -DBA FirstKey/NextKey Loop Test With 5 Items ---SKIPIF-- -<?php - require_once('skipif.inc'); - die("info $HND handler used"); -?> ---FILE-- -<?php - require_once('test.inc'); - echo "database handler: $handler\n"; - if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { - dba_insert("key1", "Content String 1", $db_file); - dba_insert("key2", "Content String 2", $db_file); - dba_insert("key3", "Third Content String", $db_file); - dba_insert("key4", "Another Content String", $db_file); - dba_insert("key5", "The last content string", $db_file); - $a = dba_firstkey($db_file); - $i=0; - while($a) { - $a = dba_nextkey($db_file); - $i++; - } - echo $i; - for ($i=1; $i<6; $i++) { - echo dba_exists("key$i", $db_file) ? "Y" : "N"; - } - dba_close($db_file); - } else { - echo "Error creating database\n"; - } -?> ---EXPECTF-- -database handler: %s -5YYYYY diff --git a/ext/dba/tests/dba006.phpt b/ext/dba/tests/dba006.phpt deleted file mode 100644 index efa36a5d07..0000000000 --- a/ext/dba/tests/dba006.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -DBA FirstKey/NextKey with 2 deletes ---SKIPIF-- -<?php - require_once('skipif.inc'); - die("info $HND handler used"); -?> ---FILE-- -<?php - require_once('test.inc'); - echo "database handler: $handler\n"; - if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { - dba_insert("key1", "Content String 1", $db_file); - dba_insert("key2", "Content String 2", $db_file); - dba_insert("key3", "Third Content String", $db_file); - dba_insert("key4", "Another Content String", $db_file); - dba_insert("key5", "The last content string", $db_file); - dba_delete("key3", $db_file); - dba_delete("key1", $db_file); - $a = dba_firstkey($db_file); - $i=0; - while($a) { - $a = dba_nextkey($db_file); - $i++; - } - echo $i; - for ($i=1; $i<6; $i++) { - echo dba_exists("key$i", $db_file) ? "Y" : "N"; - } - dba_close($db_file); - } else { - echo "Error creating database\n"; - } -?> ---EXPECTF-- -database handler: %s -3NYNYY
\ No newline at end of file diff --git a/ext/dba/tests/dba007.phpt b/ext/dba/tests/dba007.phpt deleted file mode 100644 index 0add3809aa..0000000000 --- a/ext/dba/tests/dba007.phpt +++ /dev/null @@ -1,45 +0,0 @@ ---TEST-- -DBA Multiple File Creation Test ---SKIPIF-- -<?php - require_once('skipif.inc'); - if (!function_exists('dba_list')) die('skip dba_list() not available'); - die("info $HND handler used"); -?> ---FILE-- -<?php - require_once('test.inc'); - echo "database handler: $handler\n"; - $db_file1 = dirname(__FILE__).'/test1.dbm'; - $db_file2 = dirname(__FILE__).'/test2.dbm'; - if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { - echo "database file created\n"; - } else { - echo "$db_file does not exist\n"; - } - if (($db_file1=dba_open($db_file1, "n", $handler))!==FALSE) { - echo "database file created\n"; - } else { - echo "$db_file does not exist\n"; - } - if (($db_file2=dba_open($db_file2, "n", $handler))!==FALSE) { - echo "database file created\n"; - } else { - echo "$db_file does not exist\n"; - } - var_dump(dba_list()); - dba_close($db_file); -?> ---EXPECTF-- -database handler: %s -database file created -database file created -database file created -array(3) { - [%d]=> - string(%d) "%sext/dba/tests/test0.dbm" - [%d]=> - string(%d) "%sext/dba/tests/test1.dbm" - [%d]=> - string(%d) "%sext/dba/tests/test2.dbm" -}
\ No newline at end of file diff --git a/ext/dba/tests/dba008.phpt b/ext/dba/tests/dba008.phpt deleted file mode 100644 index 84a47ba083..0000000000 --- a/ext/dba/tests/dba008.phpt +++ /dev/null @@ -1,32 +0,0 @@ ---TEST-- -DBA magic_quotes_runtime Test ---SKIPIF-- -<?php - require_once('skipif.inc'); - die("info $HND handler used"); -?> ---FILE-- -<?php - require_once('test.inc'); - echo "database handler: $handler\n"; - if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { - ini_set('magic_quotes_runtime', 0); - dba_insert("key1", '"', $db_file); - var_dump(dba_fetch("key1", $db_file)); - ini_set('magic_quotes_runtime', 1); - var_dump(dba_fetch("key1", $db_file)); - dba_replace("key1", '\"', $db_file); - var_dump(dba_fetch("key1", $db_file)); - ini_set('magic_quotes_runtime', 0); - var_dump(dba_fetch("key1", $db_file)); - dba_close($db_file); - } else { - echo "Error creating database\n"; - } -?> ---EXPECTF-- -database handler: %s -string(1) """ -string(2) "\"" -string(2) "\"" -string(1) """ diff --git a/ext/dba/tests/dba_cdb.phpt b/ext/dba/tests/dba_cdb.phpt deleted file mode 100644 index 9a881706ee..0000000000 --- a/ext/dba/tests/dba_cdb.phpt +++ /dev/null @@ -1,30 +0,0 @@ ---TEST-- -DBA CDB handler test ---SKIPIF-- -<?php - require_once('skipif.inc'); - if (!in_array('cdb', dba_handlers())) die('skip CDB handler not available'); - die('info CDB does not support replace or delete'); -?> ---FILE-- -<?php - require_once('test.inc'); - $handler = 'cdb'; - require_once('dba_handler.inc'); -?> ---EXPECT-- -database handler: cdb -5YYYYY -Content String 2 -array(5) { - ["key1"]=> - string(16) "Content String 1" - ["key2"]=> - string(16) "Content String 2" - ["key3"]=> - string(20) "Third Content String" - ["key4"]=> - string(22) "Another Content String" - ["key5"]=> - string(23) "The last content string" -} diff --git a/ext/dba/tests/dba_cdb_make.phpt b/ext/dba/tests/dba_cdb_make.phpt deleted file mode 100644 index 40a417860c..0000000000 --- a/ext/dba/tests/dba_cdb_make.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -DBA CDB_MAKE handler test ---INI-- -magic_quotes_runtime=1 ---SKIPIF-- -<?php - require_once('skipif.inc'); - if (!in_array('cdb_make', dba_handlers())) die('skip CDB_MAKE handler not available'); -?> ---FILE-- -<?php - require_once('test.inc'); - $handler = 'cdb_make'; - echo "database handler: $handler\n"; - // print md5 checksum of test.cdb which is generated by cdb_make program - var_dump(md5(implode('',file(dirname(__FILE__).'/test.cdb')))); - if (($db_make=dba_open($db_file, "n", $handler))!==FALSE) { - dba_insert("1", "1", $db_make); - dba_insert("2", "2", $db_make); - dba_insert("1", "3", $db_make); - dba_insert("2", "1", $db_make); - dba_insert("3", "3", $db_make); - dba_insert("1", "2", $db_make); - dba_insert("4", "4", $db_make); -// dba_replace cdb_make doesn't know replace - dba_close($db_make); - // write md5 checksum of generated database file - var_dump(md5(implode('',file($db_file)))); - // no need to test created database: this is done by dba_cdb_read.phpt - } else { - echo "Error creating database\n"; - } -?> ---EXPECT-- -database handler: cdb_make -string(32) "723d19f39c1b15b3b455dd64323148d1" -string(32) "723d19f39c1b15b3b455dd64323148d1"
\ No newline at end of file diff --git a/ext/dba/tests/dba_cdb_read.phpt b/ext/dba/tests/dba_cdb_read.phpt deleted file mode 100644 index 573a58cee3..0000000000 --- a/ext/dba/tests/dba_cdb_read.phpt +++ /dev/null @@ -1,65 +0,0 @@ ---TEST-- -DBA CDB handler test (read only) ---SKIPIF-- -<?php - if (!extension_loaded('dba')) die('skip dba extension not available'); - if (!in_array('cdb', dba_handlers())) die('skip CDB handler not available'); -?> ---FILE-- -<?php - echo "database handler: cdb\n"; - $handler = 'cdb'; - $db_file = dirname(__FILE__).'/test.cdb'; - if (($db_file=dba_open($db_file, "r", $handler))!==FALSE) { - // read key sequence - $a = dba_firstkey($db_file); - $count= 0; - $keys = $a; - while($a) { - $a = dba_nextkey($db_file); - $keys .= $a; - $count++; - } - // display number of entries and key existance - echo $count; - for ($i=1; $i<8; $i++) { - echo dba_exists($i, $db_file) ? "Y" : "N"; - } - echo "\n="; - echo dba_fetch(1, $db_file); - echo dba_fetch(2, $db_file); - echo dba_fetch(3, $db_file); - echo dba_fetch(4, $db_file); - echo "\n#"; - echo dba_fetch(1, $db_file); - echo dba_fetch(1, $db_file); - echo dba_fetch(2, $db_file); - echo dba_fetch(2, $db_file); - echo "\n?".$keys; - // with skip = 0 dba_fetch must fetch the first result - echo "\n#"; - $skip = array(); - for ($i=0; $i < strlen($keys); $i++) { - $key = substr($keys, $i, 1); - $skip[$key] = 0; - echo dba_fetch($key, $db_file); - } - echo "\n="; - for ($i=0; $i < strlen($keys); $i++) { - $key = substr($keys, $i, 1); - echo dba_fetch($key, $skip[$key], $db_file); - $skip[$key]++; - } - dba_close($db_file); - } else { - echo "Error creating database\n"; - } -?> ---EXPECT-- -database handler: cdb -7YYYYNNN -=1234 -#1122 -?1212314 -#1212314 -=1231324
\ No newline at end of file diff --git a/ext/dba/tests/dba_db2.phpt b/ext/dba/tests/dba_db2.phpt deleted file mode 100644 index 154ea32111..0000000000 --- a/ext/dba/tests/dba_db2.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -DBA DB2 handler test ---SKIPIF-- -<?php - require_once('skipif.inc'); - if (!in_array('db2', dba_handlers())) die('skip DB2 handler not available'); -?> ---FILE-- -<?php - require_once('test.inc'); - $handler = 'db2'; - require_once('dba_handler.inc'); -?> ---EXPECT-- -database handler: db2 -3NYNYY -Content String 2 -Content 2 replaced -Read during write: not allowed -Content 2 replaced 2nd time -The 6th value -array(3) { - ["key number 6"]=> - string(13) "The 6th value" - ["key2"]=> - string(27) "Content 2 replaced 2nd time" - ["key5"]=> - string(23) "The last content string" -}
\ No newline at end of file diff --git a/ext/dba/tests/dba_db3.phpt b/ext/dba/tests/dba_db3.phpt deleted file mode 100644 index e63b2da3e1..0000000000 --- a/ext/dba/tests/dba_db3.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -DBA DB3 handler test ---SKIPIF-- -<?php - require_once('skipif.inc'); - if (!in_array('db3', dba_handlers())) die('skip DB3 handler not available'); -?> ---FILE-- -<?php - require_once('test.inc'); - $handler = 'db3'; - require_once('dba_handler.inc'); -?> ---EXPECT-- -database handler: db3 -3NYNYY -Content String 2 -Content 2 replaced -Read during write: not allowed -Content 2 replaced 2nd time -The 6th value -array(3) { - ["key number 6"]=> - string(13) "The 6th value" - ["key2"]=> - string(27) "Content 2 replaced 2nd time" - ["key5"]=> - string(23) "The last content string" -}
\ No newline at end of file diff --git a/ext/dba/tests/dba_db4.phpt b/ext/dba/tests/dba_db4.phpt deleted file mode 100644 index 1f94e0d3ac..0000000000 --- a/ext/dba/tests/dba_db4.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -DBA DB4 handler test ---SKIPIF-- -<?php - require_once('skipif.inc'); - if (!in_array('db4', dba_handlers())) die('skip DB4 handler not available'); -?> ---FILE-- -<?php - require_once('test.inc'); - $handler = 'db4'; - require_once('dba_handler.inc'); -?> ---EXPECT-- -database handler: db4 -3NYNYY -Content String 2 -Content 2 replaced -Read during write: not allowed -Content 2 replaced 2nd time -The 6th value -array(3) { - ["key number 6"]=> - string(13) "The 6th value" - ["key2"]=> - string(27) "Content 2 replaced 2nd time" - ["key5"]=> - string(23) "The last content string" -} diff --git a/ext/dba/tests/dba_dbm.phpt b/ext/dba/tests/dba_dbm.phpt deleted file mode 100644 index 937d31d0d8..0000000000 --- a/ext/dba/tests/dba_dbm.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -DBA DBM handler test ---SKIPIF-- -<?php - require_once('skipif.inc'); - if (!in_array('dbm', dba_handlers())) die('skip DBM handler not available'); -?> ---FILE-- -<?php - require_once('test.inc'); - $handler = 'dbm'; - require_once('dba_handler.inc'); -?> ---EXPECT-- -database handler: dbm -3NYNYY -Content String 2 -Content 2 replaced -Read during write: not allowed -Content 2 replaced 2nd time -The 6th value -array(3) { - ["key number 6"]=> - string(13) "The 6th value" - ["key2"]=> - string(27) "Content 2 replaced 2nd time" - ["key5"]=> - string(23) "The last content string" -} diff --git a/ext/dba/tests/dba_flatfile.phpt b/ext/dba/tests/dba_flatfile.phpt deleted file mode 100644 index 42477dfd3c..0000000000 --- a/ext/dba/tests/dba_flatfile.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -DBA FlatFile handler test ---SKIPIF-- -<?php - require_once('skipif.inc'); - if (!in_array('flatfile', dba_handlers())) die('skip FlatFile handler not available'); -?> ---FILE-- -<?php - require_once('test.inc'); - $handler = 'flatfile'; - require_once('dba_handler.inc'); -?> ---EXPECT-- -database handler: flatfile -3NYNYY -Content String 2 -Content 2 replaced -Read during write: not allowed -Content 2 replaced 2nd time -The 6th value -array(3) { - ["key number 6"]=> - string(13) "The 6th value" - ["key2"]=> - string(27) "Content 2 replaced 2nd time" - ["key5"]=> - string(23) "The last content string" -}
\ No newline at end of file diff --git a/ext/dba/tests/dba_gdbm.phpt b/ext/dba/tests/dba_gdbm.phpt deleted file mode 100644 index c7eb5f9978..0000000000 --- a/ext/dba/tests/dba_gdbm.phpt +++ /dev/null @@ -1,32 +0,0 @@ ---TEST-- -DBA GDBM handler test ---SKIPIF-- -<?php - require_once('skipif.inc'); - if (!in_array('gdbm', dba_handlers())) die('skip GDBM handler not available'); -?> ---FILE-- -<?php - require_once('test.inc'); - $handler = 'gdbm'; - $lock_flag = ''; // lock in library - require_once('dba_handler.inc'); - - // Read during write is system dependant. Important is that there is no deadlock -?> ---EXPECTF-- -database handler: gdbm -3NYNYY -Content String 2 -Content 2 replaced -Read during write:%sallowed -Content 2 replaced 2nd time -The 6th value -array(3) { - ["key number 6"]=> - string(13) "The 6th value" - ["key2"]=> - string(27) "Content 2 replaced 2nd time" - ["key5"]=> - string(23) "The last content string" -}
\ No newline at end of file diff --git a/ext/dba/tests/dba_handler.inc b/ext/dba/tests/dba_handler.inc deleted file mode 100644 index b2e73d6237..0000000000 --- a/ext/dba/tests/dba_handler.inc +++ /dev/null @@ -1,75 +0,0 @@ -<?php - echo "database handler: $handler\n"; - if (($db_file = dba_open($db_filename, 'n'.$lock_flag, $handler))!==FALSE) { - dba_insert("key1", "Content String 1", $db_file); - dba_insert("key2", "Content String 2", $db_file); - dba_insert("key3", "Third Content String", $db_file); - dba_insert("key4", "Another Content String", $db_file); - dba_insert("key5", "The last content string", $db_file); - if ($handler != 'cdb') { - dba_delete("key3", $db_file); - dba_delete("key1", $db_file); - } else { - dba_close($db_file); - if (($db_file = dba_open($db_filename, 'r'.$lock_flag, $handler))===FALSE) { - echo "Error reopening database\n"; - } - } - $a = dba_firstkey($db_file); - $i=0; - while($a) { - $a = dba_nextkey($db_file); - $i++; - } - echo $i; - for ($i=1; $i<6; $i++) { - echo dba_exists("key$i", $db_file) ? "Y" : "N"; - } - echo "\n"; - echo dba_fetch("key2", $db_file)."\n"; - if ($handler != 'cdb') { - dba_replace("key2", "Content 2 replaced", $db_file); - echo dba_fetch("key2", $db_file)."\n"; - } - dba_close($db_file); - } else { - echo "Error creating database\n"; - } - if ($handler != 'cdb') { - $db_writer = dba_open($db_filename, 'w'.$lock_flag, $handler); - if (($dba_reader = @dba_open($db_filename, 'r'.$lock_flag.($lock_flag ? 't' : ''), $handler))===false) { - echo "Read during write: not allowed\n"; - } else { - echo "Read during write: allowed\n"; - } - if ($db_writer!==FALSE) { - dba_insert("key number 6", "The 6th value", $db_writer); - @dba_insert("key number 6", "The 6th value inserted again would be an error", $db_writer); - dba_replace("key2", "Content 2 replaced 2nd time", $db_writer); - dba_delete("key4", $db_writer); - echo dba_fetch("key2", $db_writer)."\n"; - echo dba_fetch("key number 6", $db_writer)."\n"; - dba_close($db_writer); // when the writer is open at least db3 would fail because of buffered io. - } else { - die("Error reopening database\n"); - } - } - if (($db_file = dba_open($db_filename, 'r'.$lock_flag, $handler))!==FALSE) { - $key = dba_firstkey($db_file); - $res = array(); - while($key) { - $res[$key] = dba_fetch($key, $db_file); - $key = dba_nextkey($db_file); - } - ksort($res); - var_dump($res); - dba_close($db_file); - } else { - echo "Error reading database\n"; - } - if (!empty($dba_reader)) { - dba_close($dba_reader); - } - if (($db_file = dba_popen($db_filename, 'r'.($handler!='gdbm'?'-':''), $handler))!==FALSE) { - } -?>
\ No newline at end of file diff --git a/ext/dba/tests/dba_inifile.phpt b/ext/dba/tests/dba_inifile.phpt deleted file mode 100644 index 5ccccbe238..0000000000 --- a/ext/dba/tests/dba_inifile.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -DBA INIFILE handler test ---SKIPIF-- -<?php - require_once('skipif.inc'); - if (!in_array('inifile', dba_handlers())) die('skip INIFILE handler not available'); -?> ---FILE-- -<?php - require_once('test.inc'); - $handler = 'inifile'; - require_once('dba_handler.inc'); -?> ---EXPECT-- -database handler: inifile -3NYNYY -Content String 2 -Content 2 replaced -Read during write: not allowed -Content 2 replaced 2nd time -The 6th value -array(3) { - ["key number 6"]=> - string(13) "The 6th value" - ["key2"]=> - string(27) "Content 2 replaced 2nd time" - ["key5"]=> - string(23) "The last content string" -}
\ No newline at end of file diff --git a/ext/dba/tests/dba_ndbm.phpt b/ext/dba/tests/dba_ndbm.phpt deleted file mode 100644 index fd37b7bad2..0000000000 --- a/ext/dba/tests/dba_ndbm.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -DBA NDBM handler test ---SKIPIF-- -<?php - require_once('skipif.inc'); - if (!in_array('ndbm', dba_handlers())) die('skip NDBM handler not available'); -?> ---FILE-- -<?php - require_once('test.inc'); - $handler = 'ndbm'; - require_once('dba_handler.inc'); -?> ---EXPECT-- -database handler: ndbm -3NYNYY -Content String 2 -Content 2 replaced -Read during write: not allowed -Content 2 replaced 2nd time -The 6th value -array(3) { - ["key number 6"]=> - string(13) "The 6th value" - ["key2"]=> - string(27) "Content 2 replaced 2nd time" - ["key5"]=> - string(23) "The last content string" -}
\ No newline at end of file diff --git a/ext/dba/tests/skipif.inc b/ext/dba/tests/skipif.inc deleted file mode 100644 index 141c907111..0000000000 --- a/ext/dba/tests/skipif.inc +++ /dev/null @@ -1,20 +0,0 @@ -<?php - if (!extension_loaded('dba')) die('skip dba extension not available'); - if (!function_exists('dba_handlers')) die ('skip dba_handlers() not available'); - if (!sizeof(dba_handlers())) die('skip no handlers installed'); - $handler = dba_handlers(); - if (in_array('flatfile', $handler)) { - $handler = 'flatfile'; - } elseif ($handler[0]=='cdb') { // CDB currently supports only reading - if (count($handler)==1) { - die('skip CDB currently supports only reading'); - } - if ($handler[1]=='cdb_make' && count($handler)==2) { - die('skip CDB currently supports only reading and creating'); - } - $handler = $handler[1]; - } else { - $handler = $handler[0]; - } - $HND = strtoupper($handler); -?> diff --git a/ext/dba/tests/test.cdb b/ext/dba/tests/test.cdb Binary files differdeleted file mode 100644 index 21529c6280..0000000000 --- a/ext/dba/tests/test.cdb +++ /dev/null diff --git a/ext/dba/tests/test.inc b/ext/dba/tests/test.inc deleted file mode 100644 index 402096dbe9..0000000000 --- a/ext/dba/tests/test.inc +++ /dev/null @@ -1,17 +0,0 @@ -<?php - $db_filename = $db_file = dirname(__FILE__).'/test0.dbm'; - $handler = dba_handlers(); - if (in_array('flatfile', $handler)) { - $handler = 'flatfile'; - } elseif ($handler[0]=='cdb') { // CDB currently supports only reading - if (count($handler)==1) { - die('CDB currently supports only reading '); - } - $handler = $handler[1]; - } else { - $handler = $handler[0]; - } - $lock_flag = 'l'; - @unlink($db_filename); - @unlink($db_filename.'.lck'); -?> |