diff options
author | Marcus Boerger <helly@php.net> | 2005-02-25 23:51:53 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2005-02-25 23:51:53 +0000 |
commit | 9ffeb12c4cdb930cc7563589ef954a0c3588f672 (patch) | |
tree | 3172f23cb3f3fbb96a30e02e0d96587654267fa2 /ext/dba | |
parent | 28dbc778d830d89fef27e17965ff6684a0d3f924 (diff) | |
download | php-git-9ffeb12c4cdb930cc7563589ef954a0c3588f672.tar.gz |
- Add support for db1 through emulation
# Most probably db4 requires a slightly different detection since functions
# are macros which most probably doesn't work with current configure check.
Diffstat (limited to 'ext/dba')
-rw-r--r-- | ext/dba/config.m4 | 65 | ||||
-rw-r--r-- | ext/dba/dba.c | 6 | ||||
-rwxr-xr-x | ext/dba/dba_db1.c | 205 | ||||
-rwxr-xr-x | ext/dba/php_db1.h | 12 | ||||
-rwxr-xr-x | ext/dba/tests/dba_db1.phpt | 46 |
5 files changed, 333 insertions, 1 deletions
diff --git a/ext/dba/config.m4 b/ext/dba/config.m4 index 7b64cb4eb5..11726766cc 100644 --- a/ext/dba/config.m4 +++ b/ext/dba/config.m4 @@ -226,6 +226,9 @@ AC_DEFUN([PHP_DBA_DB_CHECK],[ AC_DEFINE_UNQUOTED(DB$1_INCLUDE_FILE, "$THIS_INCLUDE", [ ]) fi fi + DB$1_LIBS=$THIS_LIBS + DB$1_PREFIX=$THIS_PREFIX + DB$1_INCLUDE=$THIS_INCLUDE PHP_DBA_STD_ASSIGN PHP_DBA_STD_CHECK PHP_DBA_STD_ATTACH @@ -333,6 +336,66 @@ AC_ARG_WITH(db2, ]) AC_DBA_STD_RESULT(db2,Berkeley DB2) +AC_ARG_WITH(db1, +[ --with-db1[=DIR] DBA: Include Berkeley DB1 support/emulation],[ + if test "$withval" != "no"; then + PHP_DBA_STD_BEGIN + AC_MSG_CHECKING(for DB1 in library) + if test "$HAVE_DB4" = "1"; then + THIS_VERSION=4 + THIS_LIBS=$DB4_LIBS + THIS_PREFIX=$DB4_PREFIX + elif test "$HAVE_DB3" = "1"; then + THIS_LIBS=$DB3_LIBS + THIS_PREFIX=$DB3_PREFIX + elif test "$HAVE_DB2" = "1"; then + THIS_VERSION=2 + THIS_LIBS=$DB2_LIBS + THIS_PREFIX=$DB2_PREFIX + fi + if test "$HAVE_DB4" = "1" -o "$HAVE_DB3" = "1" -o "$HAVE_DB2" = "1"; then + AC_DEFINE_UNQUOTED(DB1_VERSION, "Berkeley DB 1.85 emulation in DB$THIS_VERSION", [ ]) + for i in db$THIS_VERSION/db_185.h include/db$THIS_VERSION/db_185.h include/db/db_185.h; do + if test -f "$THIS_PREFIX/$i"; then + THIS_INCLUDE=$THIS_PREFIX/$i + break + fi + done + else + AC_DEFINE_UNQUOTED(DB1_VERSION, "Unknown DB1", [ ]) + for i in $withval /usr/local /usr; do + if test -f "$i/db1/db.h"; then + THIS_PREFIX=$i + THIS_INCLUDE=$i/db1/db.h + break + elif test -f "$i/include/db1/db.h"; then + THIS_PREFIX=$i + THIS_INCLUDE=$i/include/db1/db.h + break + elif test -f "$i/include/db.h"; then + THIS_PREFIX=$i + THIS_INCLUDE=$i/include/db.h + break + fi + done + THIS_LIBS=db + fi + AC_MSG_RESULT($THIS_LIBS) + AC_MSG_CHECKING(for DB1 in header) + AC_MSG_RESULT($THIS_INCLUDE) + if test -n "$THIS_INCLUDE"; then + PHP_CHECK_LIBRARY($THIS_LIBS, dbopen, [ + AC_DEFINE_UNQUOTED(DB1_INCLUDE_FILE, "$THIS_INCLUDE", [ ]) + AC_DEFINE(DBA_DB1, 1, [ ]) + ]) + fi + PHP_DBA_STD_ASSIGN + PHP_DBA_STD_CHECK + PHP_DBA_STD_ATTACH + fi +]) +AC_DBA_STD_RESULT(db1,DB1) + AC_ARG_WITH(dbm, [ --with-dbm[=DIR] DBA: Include DBM support],[ if test "$withval" != "no"; then @@ -469,7 +532,7 @@ 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 dba_qdbm.c $cdb_sources $flat_sources $ini_sources, $ext_shared) + PHP_NEW_EXTENSION(dba, dba.c dba_cdb.c dba_dbm.c dba_gdbm.c dba_ndbm.c dba_db1.c dba_db2.c dba_db3.c dba_db4.c dba_flatfile.c dba_inifile.c dba_qdbm.c $cdb_sources $flat_sources $ini_sources, $ext_shared) PHP_ADD_BUILD_DIR($ext_builddir/libinifile) PHP_ADD_BUILD_DIR($ext_builddir/libcdb) PHP_ADD_BUILD_DIR($ext_builddir/libflatfile) diff --git a/ext/dba/dba.c b/ext/dba/dba.c index d5a8c6e1fc..9e24670268 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -43,6 +43,7 @@ #include "php_ndbm.h" #include "php_dbm.h" #include "php_cdb.h" +#include "php_db1.h" #include "php_db2.h" #include "php_db3.h" #include "php_db4.h" @@ -239,6 +240,9 @@ static dba_handler handler[] = { #if DBA_CDB_BUILTIN DBA_NAMED_HND(cdb_make, cdb, DBA_STREAM_OPEN|DBA_LOCK_ALL) /* No lock in lib */ #endif +#if DBA_DB1 + DBA_HND(db1, DBA_LOCK_ALL) /* No lock in lib */ +#endif #if DBA_DB2 DBA_HND(db2, DBA_LOCK_ALL) /* No lock in lib */ #endif @@ -268,6 +272,8 @@ static dba_handler handler[] = { #define DBA_DEFAULT "db3" #elif DBA_DB2 #define DBA_DEFAULT "db2" +#elif DBA_DB1 +#define DBA_DEFAULT "db1" #elif DBA_GDBM #define DBA_DEFAULT "gdbm" #elif DBA_NBBM diff --git a/ext/dba/dba_db1.c b/ext/dba/dba_db1.c new file mode 100755 index 0000000000..d81cfb6fc2 --- /dev/null +++ b/ext/dba/dba_db1.c @@ -0,0 +1,205 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2004 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.0 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_0.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: Shen Cheng-Da <cdsheen@gmail.com> | + +----------------------------------------------------------------------+ + */ + +/* $Id$ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php.h" + +#if DBA_DB1 +#include "php_db1.h" + +#ifdef DB1_INCLUDE_FILE +#include DB1_INCLUDE_FILE +#endif + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#define DB1_DATA dba_db1_data *dba = info->dbf +#define DB1_GKEY DBT gkey; gkey.data = (char *) key; gkey.size = keylen + +typedef struct { + DB *dbp; +} dba_db1_data; + +DBA_OPEN_FUNC(db1) +{ + dba_db1_data *dba; + DB *db; + + int gmode; + int filemode = 0644; + + if (info->argc > 0) { + convert_to_long_ex(info->argv[0]); + filemode = Z_LVAL_PP(info->argv[0]); + } + + gmode = 0; + 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 */ + } + + db = dbopen((char *)info->path, gmode, filemode, DB_HASH, NULL); + + if (db == NULL) { + return FAILURE; + } + + dba = pemalloc(sizeof(*dba), info->flags&DBA_PERSISTENT); + dba->dbp = db; + + info->dbf = dba; + + return SUCCESS; +} + +DBA_CLOSE_FUNC(db1) +{ + DB1_DATA; + dba->dbp->close(dba->dbp); + pefree(info->dbf, info->flags&DBA_PERSISTENT); +} + +DBA_FETCH_FUNC(db1) +{ + DBT gval; + DB1_DATA; + DB1_GKEY; + + char *new = NULL; + + memset(&gval, 0, sizeof(gval)); + if (dba->dbp->get(dba->dbp, &gkey, &gval, 0) == RET_SUCCESS) { + if (newlen) *newlen = gval.size; + new = estrndup(gval.data, gval.size); + } + return new; +} + +DBA_UPDATE_FUNC(db1) +{ + DBT gval; + DB1_DATA; + DB1_GKEY; + + gval.data = (char *) val; + gval.size = vallen; + + return dba->dbp->put(dba->dbp, &gkey, &gval, mode == 1 ? R_NOOVERWRITE : 0) != RET_SUCCESS ? FAILURE : SUCCESS; +} + +DBA_EXISTS_FUNC(db1) +{ + DBT gval; + DB1_DATA; + DB1_GKEY; + + return dba->dbp->get(dba->dbp, &gkey, &gval, 0) != RET_SUCCESS ? FAILURE : SUCCESS; +} + +DBA_DELETE_FUNC(db1) +{ + DB1_DATA; + DB1_GKEY; + + return dba->dbp->del(dba->dbp, &gkey, 0) != RET_SUCCESS ? FAILURE : SUCCESS; +} + +DBA_FIRSTKEY_FUNC(db1) +{ + DBT gkey; + DBT gval; + DB1_DATA; + + char *key = NULL; + + memset(&gkey, 0, sizeof(gkey)); + memset(&gval, 0, sizeof(gval)); + + if (dba->dbp->seq(dba->dbp, &gkey, &gval, R_FIRST) == RET_SUCCESS) { + if (newlen) *newlen = gkey.size; + key = estrndup(gkey.data, gkey.size); + } + + return key; +} + +DBA_NEXTKEY_FUNC(db1) +{ + DBT gkey; + DBT gval; + DB1_DATA; + + char *key = NULL; + + memset(&gkey, 0, sizeof(gkey)); + memset(&gval, 0, sizeof(gval)); + + if (dba->dbp->seq(dba->dbp, &gkey, &gval, R_NEXT) == RET_SUCCESS) { + if (newlen) *newlen = gkey.size; + key = estrndup(gkey.data, gkey.size); + } + return key; +} + +DBA_OPTIMIZE_FUNC(db1) +{ + /* dummy */ + return SUCCESS; +} + +DBA_SYNC_FUNC(db1) +{ + return SUCCESS; +} + +DBA_INFO_FUNC(db1) +{ + return estrdup(DB1_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/php_db1.h b/ext/dba/php_db1.h new file mode 100755 index 0000000000..c0bb5f08b4 --- /dev/null +++ b/ext/dba/php_db1.h @@ -0,0 +1,12 @@ +#ifndef PHP_DB1_H +#define PHP_DB1_H + +#if DBA_DB1 + +#include "php_dba.h" + +DBA_FUNCS(db1); + +#endif + +#endif diff --git a/ext/dba/tests/dba_db1.phpt b/ext/dba/tests/dba_db1.phpt new file mode 100755 index 0000000000..983954b50b --- /dev/null +++ b/ext/dba/tests/dba_db1.phpt @@ -0,0 +1,46 @@ +--TEST-- +DBA DB1 handler test +--SKIPIF-- +<?php + $handler = 'db1'; + require_once('skipif.inc'); +?> +--FILE-- +<?php + $handler = 'db1'; + require_once('test.inc'); + require_once('dba_handler.inc'); +?> +===DONE=== +--EXPECT-- +database handler: db1 +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-LOCK-- +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" +} +===DONE=== |