diff options
author | Ondřej Surý <ondrej@sury.org> | 2012-02-01 21:25:15 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2012-02-01 21:25:15 +0100 |
commit | 96fb2ff5760132a915766f1d9ec7c63001feacd8 (patch) | |
tree | 160904a89a8f3522fa4e47632db101b045e7814a /ext/dba | |
parent | 8f1428d29ef91d74b4d272af171675f2971eb15b (diff) | |
download | php-96fb2ff5760132a915766f1d9ec7c63001feacd8.tar.gz |
Imported Upstream version 5.4.0~rc6upstream/5.4.0_rc6
Diffstat (limited to 'ext/dba')
-rw-r--r-- | ext/dba/config.m4 | 37 | ||||
-rw-r--r-- | ext/dba/dba.c | 32 | ||||
-rw-r--r-- | ext/dba/dba_db4.c | 2 | ||||
-rw-r--r-- | ext/dba/dba_tcadb.c | 221 | ||||
-rw-r--r-- | ext/dba/libflatfile/flatfile.c | 1 | ||||
-rw-r--r-- | ext/dba/libinifile/inifile.c | 5 | ||||
-rw-r--r-- | ext/dba/php_tcadb.h | 41 | ||||
-rw-r--r-- | ext/dba/tests/dba_cdb_make.phpt | 3 | ||||
-rw-r--r-- | ext/dba/tests/dba_tcadb.phpt | 50 |
9 files changed, 363 insertions, 29 deletions
diff --git a/ext/dba/config.m4 b/ext/dba/config.m4 index d6a4ac9a6..53ea9cf65 100644 --- a/ext/dba/config.m4 +++ b/ext/dba/config.m4 @@ -97,6 +97,10 @@ PHP_ARG_WITH(db1,, PHP_ARG_WITH(dbm,, [ --with-dbm[=DIR] DBA: DBM support], no, no) +PHP_ARG_WITH(tcadb,, +[ --with-tcadb[=DIR] DBA: Tokyo Cabinet abstract DB support], no, no) + + dnl dnl Library checks dnl @@ -193,6 +197,37 @@ if test "$PHP_NDBM" != "no"; then fi PHP_DBA_STD_RESULT(ndbm) +dnl TCADB +if test "$PHP_TCADB" != "no"; then + PHP_DBA_STD_BEGIN + for i in $PHP_TCADB /usr/local /usr; do + if test -f "$i/include/tcadb.h"; then + THIS_PREFIX=$i + PHP_ADD_INCLUDE($THIS_PREFIX/include) + THIS_INCLUDE=$i/include/tcadb.h + break + fi + done + + if test -n "$THIS_INCLUDE"; then + for LIB in tokyocabinet; do + PHP_CHECK_LIBRARY($LIB, tcadbopen, [ + AC_DEFINE_UNQUOTED(TCADB_INCLUDE_FILE, "$THIS_INCLUDE", [ ]) + AC_DEFINE(DBA_TCADB, 1, [ ]) + THIS_LIBS=$LIB + ], [], [-L$THIS_PREFIX/$PHP_LIBDIR]) + if test -n "$THIS_LIBS"; then + break + fi + done + fi + + PHP_DBA_STD_ASSIGN + PHP_DBA_STD_CHECK + PHP_DBA_STD_ATTACH +fi +PHP_DBA_STD_RESULT(tcadb) + dnl Berkeley specific (library and version test) dnl parameters(version, library list, function) AC_DEFUN([PHP_DBA_DB_CHECK],[ @@ -590,7 +625,7 @@ if test "$HAVE_DBA" = "1"; then AC_MSG_RESULT([yes]) fi AC_DEFINE(HAVE_DBA, 1, [ ]) - 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_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 dba_tcadb.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 90ccbf34e..d11cf254a 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -50,6 +50,7 @@ #include "php_flatfile.h" #include "php_inifile.h" #include "php_qdbm.h" +#include "php_tcadb.h" /* {{{ arginfo */ ZEND_BEGIN_ARG_INFO_EX(arginfo_dba_popen, 0, 0, 2) @@ -337,6 +338,9 @@ static dba_handler handler[] = { #if DBA_QDBM DBA_HND(qdbm, DBA_LOCK_EXT) #endif +#if DBA_TCADB + DBA_HND(tcadb, DBA_LOCK_ALL) +#endif { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } }; @@ -358,6 +362,8 @@ static dba_handler handler[] = { #define DBA_DEFAULT "dbm" #elif DBA_QDBM #define DBA_DEFAULT "qdbm" +#elif DBA_TCADB +#define DBA_DEFAULT "tcadb" #else #define DBA_DEFAULT "" #endif @@ -554,20 +560,9 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode) DBA_WRITE_CHECK; - if (PG(magic_quotes_runtime)) { - v = estrndup(val, val_len); - php_stripslashes(v, &val_len TSRMLS_CC); - if (info->hnd->update(info, key_str, key_len, v, val_len, mode TSRMLS_CC) == SUCCESS) { - efree(v); - DBA_ID_DONE; - RETURN_TRUE; - } - efree(v); - } else { - if (info->hnd->update(info, key_str, key_len, val, val_len, mode TSRMLS_CC) == SUCCESS) { - DBA_ID_DONE; - RETURN_TRUE; - } + if (info->hnd->update(info, key_str, key_len, val, val_len, mode TSRMLS_CC) == SUCCESS) { + DBA_ID_DONE; + RETURN_TRUE; } DBA_ID_DONE; @@ -832,7 +827,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) /* 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(lock_name, lock_file_mode, STREAM_MUST_SEEK|IGNORE_PATH|ENFORCE_SAFE_MODE|persistent_flag, &opened_path); + info->lock.fp = php_stream_open_wrapper(lock_name, lock_file_mode, STREAM_MUST_SEEK|IGNORE_PATH|persistent_flag, &opened_path); } 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 */ @@ -847,7 +842,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) } } if (!info->lock.fp) { - info->lock.fp = php_stream_open_wrapper(lock_name, lock_file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE|persistent_flag, &opened_path); + info->lock.fp = php_stream_open_wrapper(lock_name, lock_file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|persistent_flag, &opened_path); if (info->lock.fp) { if (lock_dbf) { /* replace the path info with the real path of the opened file */ @@ -885,7 +880,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) 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|persistent_flag, NULL); + info->fp = php_stream_open_wrapper(info->path, file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|persistent_flag, NULL); } if (!info->fp) { dba_close(info TSRMLS_CC); @@ -1023,9 +1018,6 @@ PHP_FUNCTION(dba_fetch) 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); } diff --git a/ext/dba/dba_db4.c b/ext/dba/dba_db4.c index 29dfba560..5052f869b 100644 --- a/ext/dba/dba_db4.c +++ b/ext/dba/dba_db4.c @@ -48,7 +48,7 @@ static void php_dba_db4_errcall_fcn( /* Bug 51086, Berkeley DB 4.8.26 */ /* This code suppresses a BDB 4.8+ error message, thus keeping PHP test compatibility */ { - char *function = get_active_function_name(TSRMLS_C); + const char *function = get_active_function_name(TSRMLS_C); if (function && (!strcmp(function,"dba_popen") || !strcmp(function,"dba_open")) && (!strncmp(msg, "fop_read_meta", sizeof("fop_read_meta")-1) || !strncmp(msg, "BDB0004 fop_read_meta", sizeof("BDB0004 fop_read_meta")-1))) { diff --git a/ext/dba/dba_tcadb.c b/ext/dba/dba_tcadb.c new file mode 100644 index 000000000..8ee0116eb --- /dev/null +++ b/ext/dba/dba_tcadb.c @@ -0,0 +1,221 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2012 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 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_01.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: Michael Maclean <mgdm@php.net> | + +----------------------------------------------------------------------+ + */ + +/* $Id: dba_tcadb.c 321634 2012-01-01 13:15:04Z felipe $ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php.h" + +#if DBA_TCADB +#include "php_tcadb.h" + +#ifdef TCADB_INCLUDE_FILE +#include TCADB_INCLUDE_FILE +#endif + +#define TCADB_DATA dba_tcadb_data *dba = info->dbf + +typedef struct { + TCADB *tcadb; +} dba_tcadb_data; + +DBA_OPEN_FUNC(tcadb) +{ + char *path_string; + TCADB *tcadb = tcadbnew(); + + if (tcadb) { + switch(info->mode) { + case DBA_READER: + spprintf(&path_string, 0, "%s#mode=r", info->path); + break; + case DBA_WRITER: + spprintf(&path_string, 0, "%s#mode=w", info->path); + break; + case DBA_CREAT: + spprintf(&path_string, 0, "%s#mode=wc", info->path); + break; + case DBA_TRUNC: + spprintf(&path_string, 0, "%s#mode=wct", info->path); + break; + default: + tcadbdel(tcadb); + return FAILURE; + } + + if (!tcadbopen(tcadb, path_string)) { + efree(path_string); + tcadbdel(tcadb); + return FAILURE; + } + + efree(path_string); + + info->dbf = pemalloc(sizeof(dba_tcadb_data), info->flags & DBA_PERSISTENT); + memset(info->dbf, 0, sizeof(dba_tcadb_data)); + ((dba_tcadb_data *) info->dbf)->tcadb = tcadb; + return SUCCESS; + } + + return FAILURE; +} + +DBA_CLOSE_FUNC(tcadb) +{ + TCADB_DATA; + + tcadbclose(dba->tcadb); + pefree(dba, info->flags & DBA_PERSISTENT); +} + +DBA_FETCH_FUNC(tcadb) +{ + TCADB_DATA; + char *value, *new = NULL; + int value_size; + + value = tcadbget(dba->tcadb, key, keylen, &value_size); + if (value) { + if (newlen) { + *newlen = value_size; + } + new = estrndup(value, value_size); + tcfree(value); + } + + return new; +} + +DBA_UPDATE_FUNC(tcadb) +{ + TCADB_DATA; + int result; + + if (mode == 1) { + /* Insert */ + if (tcadbvsiz(dba->tcadb, key, keylen) > -1) { + return FAILURE; + } + } + + result = tcadbput(dba->tcadb, key, keylen, val, vallen); + + if (result) { + return SUCCESS; + } + + php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "Error updating data"); + return FAILURE; +} + +DBA_EXISTS_FUNC(tcadb) +{ + TCADB_DATA; + char *value; + int value_len; + + value = tcadbget(dba->tcadb, key, keylen, &value_len); + if (value) { + tcfree(value); + return SUCCESS; + } + + return FAILURE; +} + +DBA_DELETE_FUNC(tcadb) +{ + TCADB_DATA; + + return tcadbout(dba->tcadb, key, keylen) ? SUCCESS : FAILURE; +} + +DBA_FIRSTKEY_FUNC(tcadb) +{ + TCADB_DATA; + int value_size; + char *value, *new = NULL; + + tcadbiterinit(dba->tcadb); + + value = tcadbiternext(dba->tcadb, &value_size); + if (value) { + if (newlen) { + *newlen = value_size; + } + new = estrndup(value, value_size); + tcfree(value); + } + + return new; +} + +DBA_NEXTKEY_FUNC(tcadb) +{ + TCADB_DATA; + int value_size; + char *value, *new = NULL; + + value = tcadbiternext(dba->tcadb, &value_size); + if (value) { + if (newlen) { + *newlen = value_size; + } + new = estrndup(value, value_size); + tcfree(value); + } + + return new; +} + +DBA_OPTIMIZE_FUNC(tcadb) +{ + TCADB_DATA; + +#if _TC_LIBVER >= 811 + return tcadboptimize(dba->tcadb, NULL) ? SUCCESS : FAILURE; +#else + return FAILURE; +#endif +} + +DBA_SYNC_FUNC(tcadb) +{ + TCADB_DATA; + + return tcadbsync(dba->tcadb) ? SUCCESS : FAILURE; +} + +DBA_INFO_FUNC(tcadb) +{ + return estrdup(tcversion); +} + +#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/libflatfile/flatfile.c b/ext/dba/libflatfile/flatfile.c index 2d4af534c..297fbb3a7 100644 --- a/ext/dba/libflatfile/flatfile.c +++ b/ext/dba/libflatfile/flatfile.c @@ -27,7 +27,6 @@ #include "php.h" #include "php_globals.h" -#include "safe_mode.h" #include <stdlib.h> #include <string.h> diff --git a/ext/dba/libinifile/inifile.c b/ext/dba/libinifile/inifile.c index 5d492c838..112702a4b 100644 --- a/ext/dba/libinifile/inifile.c +++ b/ext/dba/libinifile/inifile.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: inifile.c 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: inifile.c 298625 2010-04-26 23:53:30Z kalle $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -24,7 +24,6 @@ #include "php.h" #include "php_globals.h" -#include "safe_mode.h" #include <stdlib.h> #include <string.h> @@ -43,7 +42,7 @@ /* {{{ inifile_version */ char *inifile_version() { - return "1.0, $Revision: 293036 $"; + return "1.0, $Revision: 298625 $"; } /* }}} */ diff --git a/ext/dba/php_tcadb.h b/ext/dba/php_tcadb.h new file mode 100644 index 000000000..0b29177a7 --- /dev/null +++ b/ext/dba/php_tcadb.h @@ -0,0 +1,41 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2012 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 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_01.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: Michael Maclean <mgdm@php.net> | + +----------------------------------------------------------------------+ + */ + +/* $Id: php_tcadb.h 321634 2012-01-01 13:15:04Z felipe $ */ + +#ifndef PHP_TCADB_H +#define PHP_TCADB_H + +#if DBA_TCADB + +#include "php_dba.h" + +DBA_FUNCS(tcadb); + +#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/tests/dba_cdb_make.phpt b/ext/dba/tests/dba_cdb_make.phpt index e3ff9662a..6a5f2dd9c 100644 --- a/ext/dba/tests/dba_cdb_make.phpt +++ b/ext/dba/tests/dba_cdb_make.phpt @@ -1,7 +1,5 @@ --TEST-- DBA CDB_MAKE handler test ---INI-- -magic_quotes_runtime=1 --SKIPIF-- <?php $handler = 'cdb_make'; @@ -37,7 +35,6 @@ magic_quotes_runtime=1 require(dirname(__FILE__) .'/clean.inc'); ?> --EXPECT-- -Deprecated: Directive 'magic_quotes_runtime' is deprecated in PHP 5.3 and greater in Unknown on line 0 database handler: cdb_make string(32) "12fc5ba2b9dcfef2480e5324eeb5f3e5" string(32) "12fc5ba2b9dcfef2480e5324eeb5f3e5" diff --git a/ext/dba/tests/dba_tcadb.phpt b/ext/dba/tests/dba_tcadb.phpt new file mode 100644 index 000000000..52dd4de33 --- /dev/null +++ b/ext/dba/tests/dba_tcadb.phpt @@ -0,0 +1,50 @@ +--TEST-- +DBA TCADB handler test +--SKIPIF-- +<?php + $handler = 'tcadb'; + require_once dirname(__FILE__) .'/skipif.inc'; +?> +--FILE-- +<?php + $handler = 'tcadb'; + require_once dirname(__FILE__) .'/skipif.inc'; + $lock_flag = 'l'; + $db_filename = $db_file = dirname(__FILE__) .'/test0.tch'; + @unlink($db_filename); + @unlink($db_filename.'.lck'); + require_once dirname(__FILE__) .'/dba_handler.inc'; +?> +===DONE=== +--EXPECT-- +database handler: tcadb +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=== |