diff options
author | Marcus Boerger <helly@php.net> | 2003-12-18 20:25:21 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2003-12-18 20:25:21 +0000 |
commit | c69fb4133da140ff9eba8842dd479492bec8dfbe (patch) | |
tree | cf35c605f1bec8196426be3d0d514416729bb6f2 /ext/dba | |
parent | 0283b50316ed8fa20cb7df1f03459108a8e97943 (diff) | |
download | php-git-c69fb4133da140ff9eba8842dd479492bec8dfbe.tar.gz |
dded qdbm handler (http://qdbm.sourceforge.net).
Diffstat (limited to 'ext/dba')
-rw-r--r-- | ext/dba/config.m4 | 40 | ||||
-rw-r--r-- | ext/dba/dba.c | 6 | ||||
-rwxr-xr-x | ext/dba/dba_qdbm.c | 192 | ||||
-rwxr-xr-x | ext/dba/tests/dba_qdbm.phpt | 34 |
4 files changed, 271 insertions, 1 deletions
diff --git a/ext/dba/config.m4 b/ext/dba/config.m4 index 4d4fddfdf9..a5baeb2212 100644 --- a/ext/dba/config.m4 +++ b/ext/dba/config.m4 @@ -65,10 +65,45 @@ AC_DEFUN(AC_DBA_STD_RESULT,[ PHP_ARG_ENABLE(dba,whether to enable DBA, [ --enable-dba Build DBA with builtin modules]) +AC_ARG_WITH(qdbm, +[ --with-qdbm[=DIR] DBA: Include QDBM support],[ + if test "$withval" != "no"; then + PHP_DBA_STD_BEGIN + for i in $withval /usr/local /usr; do + if test -f "$i/include/depot.h"; then + THIS_PREFIX=$i + THIS_INCLUDE=$i/include/depot.h + break + fi + done + + if test -n "$THIS_INCLUDE"; then + for LIB in qdbm; do + PHP_CHECK_LIBRARY($LIB, dpopen, [ + AC_DEFINE_UNQUOTED(QDBM_INCLUDE_FILE, "$THIS_INCLUDE", [ ]) + AC_DEFINE(DBA_QDBM, 1, [ ]) + THIS_LIBS=$LIB + ], [], [-L$THIS_PREFIX/lib]) + if test -n "$THIS_LIBS"; then + break + fi + done + fi + + PHP_DBA_STD_ASSIGN + PHP_DBA_STD_CHECK + PHP_DBA_STD_ATTACH + fi +]) +AC_DBA_STD_RESULT(qdbm) + AC_ARG_WITH(gdbm, [ --with-gdbm[=DIR] DBA: Include GDBM support],[ if test "$withval" != "no"; then PHP_DBA_STD_BEGIN + if test "$HAVE_QDBM" = "1"; then + AC_DBA_STD_RESULT(gdbm,gdbm,You cannot combine --with-gdbm with --with-qdbm) + fi for i in $withval /usr/local /usr; do if test -f "$i/include/gdbm.h"; then THIS_PREFIX=$i @@ -300,6 +335,9 @@ AC_ARG_WITH(dbm, [ --with-dbm[=DIR] DBA: Include DBM support],[ if test "$withval" != "no"; then PHP_DBA_STD_BEGIN + if test "$HAVE_QDBM" = "1"; then + AC_DBA_STD_RESULT(dbm,dbm,You cannot combine --with-dbm with --with-qdbm) + fi for i in $withval /usr/local /usr; do if test -f "$i/include/dbm.h"; then THIS_PREFIX=$i @@ -429,7 +467,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 $cdb_sources $flat_sources $ini_sources, $ext_shared) + 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_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 3a02dacf4f..1ce4fcbf54 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -48,6 +48,7 @@ #include "php_db4.h" #include "php_flatfile.h" #include "php_inifile.h" +#include "php_qdbm.h" /* {{{ dba_functions[] */ @@ -253,6 +254,9 @@ static dba_handler handler[] = { #if DBA_FLATFILE DBA_HND(flatfile, DBA_STREAM_OPEN|DBA_LOCK_ALL|DBA_NO_APPEND) /* No lock in lib */ #endif +#if DBA_QDBM + DBA_HND(qdbm, DBA_LOCK_EXT) +#endif { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } }; @@ -270,6 +274,8 @@ static dba_handler handler[] = { #define DBA_DEFAULT "ndbm" #elif DBA_DBM #define DBA_DEFAULT "dbm" +#elif DBA_QDBM +#define DBA_DEFAULT "qdbm" #else #define DBA_DEFAULT "" #endif diff --git a/ext/dba/dba_qdbm.c b/ext/dba/dba_qdbm.c new file mode 100755 index 0000000000..1306125100 --- /dev/null +++ b/ext/dba/dba_qdbm.c @@ -0,0 +1,192 @@ +/* + +----------------------------------------------------------------------+ + | 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: Marcin Gibula <mg@iceni.pl> | + +----------------------------------------------------------------------+ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php.h" + +#if DBA_QDBM +#include "php_qdbm.h" + +#ifdef QDBM_INCLUDE_FILE +#include QDBM_INCLUDE_FILE +#endif + +#define QDBM_DATA dba_qdbm_data *dba = info->dbf + +typedef struct { + DEPOT *dbf; +} dba_qdbm_data; + +DBA_OPEN_FUNC(qdbm) +{ + DEPOT *dbf; + + switch(info->mode) { + case DBA_READER: + dbf = dpopen(info->path, DP_OREADER, 0); + break; + case DBA_WRITER: + dbf = dpopen(info->path, DP_OWRITER, 0); + break; + case DBA_CREAT: + dbf = dpopen(info->path, DP_OWRITER | DP_OCREAT, 0); + break; + case DBA_TRUNC: + dbf = dpopen(info->path, DP_OWRITER | DP_OCREAT | DP_OTRUNC, 0); + break; + default: + return FAILURE; + } + + if (dbf) { + info->dbf = pemalloc(sizeof(dba_qdbm_data), info->flags & DBA_PERSISTENT); + memset(info->dbf, 0, sizeof(dba_qdbm_data)); + ((dba_qdbm_data *) info->dbf)->dbf = dbf; + return SUCCESS; + } + + *error = (char *) dperrmsg(dpecode); + return FAILURE; +} + +DBA_CLOSE_FUNC(qdbm) +{ + QDBM_DATA; + + dpclose(dba->dbf); + pefree(dba, info->flags & DBA_PERSISTENT); +} + +DBA_FETCH_FUNC(qdbm) +{ + QDBM_DATA; + char *value, *new = NULL; + int value_size; + + value = dpget(dba->dbf, key, keylen, 0, -1, &value_size); + if (value) { + if (newlen) *newlen = value_size; + new = estrndup(value, value_size); + free(value); + } + + return new; +} + +DBA_UPDATE_FUNC(qdbm) +{ + QDBM_DATA; + int result; + + result = dpput(dba->dbf, key, keylen, val, vallen, mode == 1 ? DP_DKEEP : DP_DOVER); + if (result) + return SUCCESS; + + php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "%s", dperrmsg(dpecode)); + return FAILURE; +} + +DBA_EXISTS_FUNC(qdbm) +{ + QDBM_DATA; + char *value; + + value = dpget(dba->dbf, key, keylen, 0, -1, NULL); + if (value) { + free(value); + return SUCCESS; + } + + return FAILURE; +} + +DBA_DELETE_FUNC(qdbm) +{ + QDBM_DATA; + + return dpout(dba->dbf, key, keylen) ? SUCCESS : FAILURE; +} + +DBA_FIRSTKEY_FUNC(qdbm) +{ + QDBM_DATA; + int value_size; + char *value, *new = NULL; + + dpiterinit(dba->dbf); + + value = dpiternext(dba->dbf, &value_size); + if (value) { + if (newlen) *newlen = value_size; + new = estrndup(value, value_size); + free(value); + } + + return new; +} + +DBA_NEXTKEY_FUNC(qdbm) +{ + QDBM_DATA; + int value_size; + char *value, *new = NULL; + + value = dpiternext(dba->dbf, &value_size); + if (value) { + if (newlen) *newlen = value_size; + new = estrndup(value, value_size); + free(value); + } + + return new; +} + +DBA_OPTIMIZE_FUNC(qdbm) +{ + QDBM_DATA; + + dpoptimize(dba->dbf, 0); + return SUCCESS; +} + +DBA_SYNC_FUNC(qdbm) +{ + QDBM_DATA; + + dpsync(dba->dbf); + return SUCCESS; +} + +DBA_INFO_FUNC(qdbm) +{ + return estrdup(dpversion); +} + +#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/tests/dba_qdbm.phpt b/ext/dba/tests/dba_qdbm.phpt new file mode 100755 index 0000000000..a7c9ab69e1 --- /dev/null +++ b/ext/dba/tests/dba_qdbm.phpt @@ -0,0 +1,34 @@ +--TEST-- +DBA QDBM handler test +--SKIPIF-- +<?php + $handler = 'qdbm'; + require_once('skipif.inc'); +?> +--FILE-- +<?php + $handler = 'qdbm'; + require_once('test.inc'); + $lock_flag = ''; // lock in library + require_once('dba_handler.inc'); +?> +===DONE=== +--EXPECTF-- +database handler: qdbm +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" +} + +Warning: dba_popen(%stest0.dbm,r-): Locking cannot be disabled for handler qdbm in %sdba_handler.inc on line %d +===DONE=== |