├── CREDITS ├── tests ├── tdb_get_seqnum_002.phpt ├── tdb_open_003.phpt ├── tdb_transactions_002.phpt ├── tdb_replace_001.phpt ├── tdb_transactions_004.phpt ├── tdb_error_001.phpt ├── tdb_exists_001.phpt ├── tdb_lock_003.phpt ├── tdb_get_flags_001.phpt ├── tdb_chainunlock_001.phpt ├── tdb_first_key_001.phpt ├── tdb_chainlock_003.phpt ├── tdb_lock_001.phpt ├── tdb_transactions_005.phpt ├── tdb_lock_002.phpt ├── tdb_insert_001.phpt ├── tdb_transactions_003.phpt ├── tdb_close_001.phpt ├── tdb_unlock_001.phpt ├── tdb_next_key_001.phpt ├── tdb_chainlock_001.phpt ├── tdb_set_max_dead_001.phpt ├── tdb_append_001.phpt ├── tdb_get_seqnum_001.phpt ├── tdb_open_001.phpt ├── tdb_fetch_001.phpt ├── tdb_chainlock_002.phpt ├── tdb_delete_001.phpt ├── tdb_update_001.phpt ├── tdb_unlock_002.phpt ├── tdb_chainunlock_002.phpt ├── tdb_open_002.phpt ├── tdb_transactions_001.phpt └── tdb_store_001.phpt ├── README ├── php_tdb.h ├── config.m4 ├── package.xml └── tdb.c /CREDITS: -------------------------------------------------------------------------------- 1 | Antony Dovgal 2 | -------------------------------------------------------------------------------- /tests/tdb_get_seqnum_002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_get_seqnum() without TDB_SEQNUM 3 | --FILE-- 4 | 18 | --EXPECTF-- 19 | int(0) 20 | int(0) 21 | int(0) 22 | Done 23 | -------------------------------------------------------------------------------- /tests/tdb_open_003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_open() in-memory test 3 | --FILE-- 4 | 14 | --EXPECTF-- 15 | resource(%d) of type (Trivial DB context) 16 | bool(true) 17 | 18 | Warning: unlink(%stest.tdb): No such file or directory in %s on line %d 19 | bool(false) 20 | Done 21 | -------------------------------------------------------------------------------- /tests/tdb_transactions_002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | transactions - in-memory TDB 3 | --FILE-- 4 | 17 | --EXPECTF-- 18 | bool(false) 19 | bool(true) 20 | bool(false) 21 | 22 | Warning: tdb_transaction_start(): Invalid parameter in %s on line %d 23 | bool(false) 24 | 25 | Warning: tdb_transaction_start(): Invalid parameter in %s on line %d 26 | bool(false) 27 | Done 28 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | It looks like Trivial DB is shipped only with Samba itself nowadays and there is no separate project for it. 2 | This means to compile TDB you need to download Samba sources and do the following: 3 | 4 | 1) run Samba's main ./configure; 5 | 2) run autogen.sh and ./configure in sources/tdb/ dir; 6 | 7 | For some reason I also had to tweak Makefile manually in order to move "-I../include" to the beginning of CPPFLAGS, 8 | otherwise wrong config.h was used (we need the global one). 9 | After that `make` succeeded, but libtdb.a was NOT installed by `make install`, so I had to put it in place manually. 10 | 11 | That's it, no more magic, --with-tdb= should work after that. 12 | 13 | -------------------------------------------------------------------------------- /tests/tdb_replace_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_replace() basic tests 3 | --FILE-- 4 | 19 | --EXPECTF-- 20 | Warning: tdb_replace() expects exactly 3 parameters, 0 given in %s on line %d 21 | NULL 22 | 23 | Warning: tdb_replace() expects exactly 3 parameters, 4 given in %s on line %d 24 | NULL 25 | bool(true) 26 | bool(true) 27 | string(0) "" 28 | string(5) "value" 29 | Done 30 | -------------------------------------------------------------------------------- /tests/tdb_transactions_004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | transactions - nested transactions 3 | --FILE-- 4 | 22 | --EXPECTF-- 23 | bool(true) 24 | bool(true) 25 | bool(true) 26 | bool(true) 27 | bool(true) 28 | 29 | Warning: tdb_transaction_commit(): IO Error in %s on line %d 30 | bool(false) 31 | Done 32 | -------------------------------------------------------------------------------- /tests/tdb_error_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_error() basic tests 3 | --FILE-- 4 | 21 | --EXPECTF-- 22 | Warning: tdb_error() expects exactly 1 parameter, 0 given in %s on line %d 23 | NULL 24 | 25 | Warning: tdb_error() expects exactly 1 parameter, 2 given in %s on line %d 26 | NULL 27 | bool(false) 28 | 29 | Warning: tdb_transaction_start(): Invalid parameter in %s on line %d 30 | string(17) "Invalid parameter" 31 | 32 | Warning: tdb_error(): %d is not a valid Trivial DB context resource in %s on line %d 33 | bool(false) 34 | Done 35 | -------------------------------------------------------------------------------- /tests/tdb_exists_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_exists() basic tests 3 | --FILE-- 4 | 24 | --EXPECTF-- 25 | Warning: tdb_exists() expects exactly 2 parameters, 0 given in %s on line %d 26 | NULL 27 | 28 | Warning: tdb_exists() expects exactly 2 parameters, 4 given in %s on line %d 29 | NULL 30 | bool(false) 31 | bool(false) 32 | bool(true) 33 | bool(true) 34 | 35 | Warning: tdb_exists(): %d is not a valid Trivial DB context resource in %s on line %d 36 | bool(false) 37 | Done 38 | -------------------------------------------------------------------------------- /tests/tdb_lock_003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_lock() and read lock 3 | --FILE-- 4 | 25 | --EXPECTF-- 26 | Warning: tdb_lock() expects at least 1 parameter, 0 given in %s on line %d 27 | NULL 28 | 29 | Warning: tdb_lock() expects at most 2 parameters, 3 given in %s on line %d 30 | NULL 31 | bool(true) 32 | bool(true) 33 | 34 | Warning: tdb_lock(): Locking error in %s on line %d 35 | bool(false) 36 | string(13) "Locking error" 37 | 38 | Warning: tdb_lock(): %d is not a valid Trivial DB context resource in %s on line %d 39 | bool(false) 40 | Done 41 | -------------------------------------------------------------------------------- /tests/tdb_get_flags_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_get_flags() basic tests 3 | --FILE-- 4 | 28 | --EXPECTF-- 29 | Warning: tdb_get_flags() expects exactly 1 parameter, 0 given in %s on line %d 30 | NULL 31 | 32 | Warning: tdb_get_flags() expects exactly 1 parameter, 2 given in %s on line %d 33 | NULL 34 | int(142) 35 | int(14) 36 | int(0) 37 | 38 | Warning: tdb_get_flags(): %d is not a valid Trivial DB context resource in %s on line %d 39 | bool(false) 40 | Done 41 | -------------------------------------------------------------------------------- /tests/tdb_chainunlock_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_chainunlock() and in-memory TDB 3 | --FILE-- 4 | 23 | --EXPECTF-- 24 | Warning: tdb_chainunlock() expects at least 2 parameters, 0 given in %s on line %d 25 | NULL 26 | 27 | Warning: tdb_chainunlock() expects at most 3 parameters, 4 given in %s on line %d 28 | NULL 29 | bool(true) 30 | bool(true) 31 | bool(true) 32 | bool(true) 33 | bool(false) 34 | 35 | Warning: tdb_chainunlock(): %d is not a valid Trivial DB context resource in %s on line %d 36 | bool(false) 37 | Done 38 | -------------------------------------------------------------------------------- /tests/tdb_first_key_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_first_key() basic tests 3 | --FILE-- 4 | 24 | --EXPECTF-- 25 | Warning: tdb_first_key() expects exactly 1 parameter, 0 given in %s on line %d 26 | NULL 27 | 28 | Warning: tdb_first_key() expects exactly 1 parameter, 3 given in %s on line %d 29 | NULL 30 | bool(false) 31 | string(3) "key" 32 | string(3) "key" 33 | string(1) "a" 34 | 35 | Warning: tdb_first_key(): %d is not a valid Trivial DB context resource in %s on line %d 36 | bool(false) 37 | Done 38 | -------------------------------------------------------------------------------- /tests/tdb_chainlock_003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_chainlock() and read chainlock 3 | --FILE-- 4 | 27 | --EXPECTF-- 28 | Warning: tdb_chainlock() expects at least 2 parameters, 0 given in %s on line %d 29 | NULL 30 | 31 | Warning: tdb_chainlock() expects at most 3 parameters, 4 given in %s on line %d 32 | NULL 33 | bool(true) 34 | bool(true) 35 | bool(true) 36 | string(8) "IO Error" 37 | 38 | Warning: tdb_chainlock(): %d is not a valid Trivial DB context resource in %s on line %d 39 | bool(false) 40 | Done 41 | -------------------------------------------------------------------------------- /tests/tdb_lock_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_lock() and in-memory TDB 3 | --FILE-- 4 | 23 | --EXPECTF-- 24 | Warning: tdb_lock() expects at least 1 parameter, 0 given in %s on line %d 25 | NULL 26 | 27 | Warning: tdb_lock() expects at most 2 parameters, 3 given in %s on line %d 28 | NULL 29 | bool(true) 30 | bool(true) 31 | 32 | Warning: tdb_lock(): Locking error in %s on line %d 33 | bool(false) 34 | 35 | Warning: tdb_lock(): Locking error in %s on line %d 36 | bool(false) 37 | string(13) "Locking error" 38 | 39 | Warning: tdb_lock(): %d is not a valid Trivial DB context resource in %s on line %d 40 | bool(false) 41 | Done 42 | -------------------------------------------------------------------------------- /tests/tdb_transactions_005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | transactions - basic transactions 3 | --FILE-- 4 | 29 | --EXPECTF-- 30 | bool(true) 31 | bool(true) 32 | 33 | Warning: tdb_fetch(): Record does not exist in %s on line %d 34 | bool(false) 35 | bool(true) 36 | bool(true) 37 | string(4) "data" 38 | bool(true) 39 | bool(true) 40 | string(8) "new data" 41 | Done 42 | -------------------------------------------------------------------------------- /tests/tdb_lock_002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_lock() basic tests 3 | --FILE-- 4 | 26 | --EXPECTF-- 27 | Warning: tdb_lock() expects at least 1 parameter, 0 given in %s on line %d 28 | NULL 29 | 30 | Warning: tdb_lock() expects at most 2 parameters, 3 given in %s on line %d 31 | NULL 32 | bool(true) 33 | bool(true) 34 | 35 | Warning: tdb_lock(): Locking error in %s on line %d 36 | bool(false) 37 | 38 | Warning: tdb_lock(): Locking error in %s on line %d 39 | bool(false) 40 | string(13) "Locking error" 41 | 42 | Warning: tdb_lock(): %d is not a valid Trivial DB context resource in %s on line %d 43 | bool(false) 44 | Done 45 | -------------------------------------------------------------------------------- /tests/tdb_insert_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_insert() basic tests 3 | --FILE-- 4 | 23 | --EXPECTF-- 24 | Warning: tdb_insert() expects exactly 3 parameters, 0 given in %s on line %d 25 | NULL 26 | 27 | Warning: tdb_insert() expects exactly 3 parameters, 4 given in %s on line %d 28 | NULL 29 | bool(true) 30 | bool(true) 31 | string(0) "" 32 | string(5) "value" 33 | 34 | Warning: tdb_insert(): Record exists in %s on line %d 35 | bool(false) 36 | 37 | Warning: tdb_insert(): Record exists in %s on line %d 38 | bool(false) 39 | string(0) "" 40 | string(5) "value" 41 | Done 42 | -------------------------------------------------------------------------------- /tests/tdb_transactions_003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | transactions - basic tests 3 | --FILE-- 4 | 32 | --EXPECTF-- 33 | bool(false) 34 | bool(true) 35 | bool(false) 36 | bool(true) 37 | bool(true) 38 | bool(true) 39 | bool(true) 40 | bool(true) 41 | bool(true) 42 | bool(true) 43 | bool(true) 44 | bool(true) 45 | bool(true) 46 | Done 47 | -------------------------------------------------------------------------------- /tests/tdb_close_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_close() basic tests 3 | --FILE-- 4 | 27 | --EXPECTF-- 28 | Warning: tdb_close() expects exactly 1 parameter, 0 given in %s on line %d 29 | NULL 30 | 31 | Warning: tdb_close() expects exactly 1 parameter, 2 given in %s on line %d 32 | NULL 33 | 34 | Warning: tdb_close(): supplied resource is not a valid Trivial DB context resource in %s on line %d 35 | bool(false) 36 | 37 | Warning: tdb_close(): %d is not a valid Trivial DB context resource in %s on line %d 38 | bool(false) 39 | bool(true) 40 | 41 | Warning: tdb_close(): %d is not a valid Trivial DB context resource in %s on line %d 42 | bool(false) 43 | bool(true) 44 | Done 45 | -------------------------------------------------------------------------------- /tests/tdb_unlock_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_unlock() and in-memory TDB 3 | --FILE-- 4 | 23 | --EXPECTF-- 24 | Warning: tdb_unlock() expects at least 1 parameter, 0 given in %s on line %d 25 | NULL 26 | 27 | Warning: tdb_unlock() expects at most 2 parameters, 3 given in %s on line %d 28 | NULL 29 | 30 | Warning: tdb_unlock(): Locking error in %s on line %d 31 | bool(false) 32 | 33 | Warning: tdb_unlock(): Locking error in %s on line %d 34 | bool(false) 35 | 36 | Warning: tdb_unlock(): Locking error in %s on line %d 37 | bool(false) 38 | 39 | Warning: tdb_unlock(): Locking error in %s on line %d 40 | bool(false) 41 | string(13) "Locking error" 42 | 43 | Warning: tdb_unlock(): %d is not a valid Trivial DB context resource in %s on line %d 44 | bool(false) 45 | Done 46 | -------------------------------------------------------------------------------- /tests/tdb_next_key_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_next_key() basic tests 3 | --FILE-- 4 | 29 | --EXPECTF-- 30 | Warning: tdb_next_key() expects exactly 2 parameters, 0 given in %s on line %d 31 | NULL 32 | 33 | Warning: tdb_next_key() expects exactly 2 parameters, 3 given in %s on line %d 34 | NULL 35 | 36 | Warning: tdb_next_key(): Record does not exist in %s on line %d 37 | bool(false) 38 | bool(false) 39 | string(4) "key2" 40 | string(1) "a" 41 | string(3) "key" 42 | string(4) "key2" 43 | 44 | Warning: tdb_next_key(): %d is not a valid Trivial DB context resource in %s on line %d 45 | bool(false) 46 | Done 47 | -------------------------------------------------------------------------------- /tests/tdb_chainlock_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_chainlock() and in-memory TDB 3 | --FILE-- 4 | 32 | --EXPECTF-- 33 | Warning: tdb_chainlock() expects at least 2 parameters, 0 given in %s on line %d 34 | NULL 35 | bool(true) 36 | bool(true) 37 | bool(true) 38 | bool(true) 39 | bool(true) 40 | bool(false) 41 | bool(true) 42 | bool(true) 43 | string(8) "IO Error" 44 | bool(true) 45 | bool(true) 46 | string(8) "IO Error" 47 | 48 | Warning: tdb_chainlock(): %d is not a valid Trivial DB context resource in %s on line %d 49 | bool(false) 50 | Done 51 | -------------------------------------------------------------------------------- /tests/tdb_set_max_dead_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_set_max_dead() basic tests 3 | --FILE-- 4 | 30 | --EXPECTF-- 31 | 32 | Warning: tdb_set_max_dead() expects exactly 2 parameters, 0 given in %s on line %d 33 | NULL 34 | 35 | Warning: tdb_set_max_dead() expects exactly 2 parameters, 3 given in %s on line %d 36 | NULL 37 | 38 | Warning: tdb_set_max_dead(): Maximum number of dead records cannot be less than zero in %s on line %d 39 | bool(false) 40 | bool(true) 41 | bool(true) 42 | bool(true) 43 | bool(true) 44 | bool(true) 45 | 46 | Warning: tdb_set_max_dead(): %d is not a valid Trivial DB context resource in %s on line %d 47 | bool(false) 48 | Done 49 | -------------------------------------------------------------------------------- /tests/tdb_append_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_append() basic tests 3 | --FILE-- 4 | 28 | --EXPECTF-- 29 | Warning: tdb_append() expects exactly 3 parameters, 0 given in %s on line %d 30 | NULL 31 | 32 | Warning: tdb_append() expects exactly 3 parameters, 4 given in %s on line %d 33 | NULL 34 | bool(true) 35 | bool(true) 36 | string(0) "" 37 | string(5) "value" 38 | 39 | Warning: tdb_append(): Out of memory in %s on line %d 40 | bool(false) 41 | bool(true) 42 | string(0) "" 43 | string(11) "valuevalue2" 44 | bool(true) 45 | bool(true) 46 | string(4) "test" 47 | string(17) "valuevalue2value3" 48 | Done 49 | -------------------------------------------------------------------------------- /tests/tdb_get_seqnum_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_get_seqnum() basic tests 3 | --FILE-- 4 | 33 | --EXPECTF-- 34 | Warning: tdb_get_seqnum() expects exactly 1 parameter, 0 given in %s on line %d 35 | NULL 36 | 37 | Warning: tdb_get_seqnum() expects exactly 1 parameter, 2 given in %s on line %d 38 | NULL 39 | int(0) 40 | int(1) 41 | int(2) 42 | int(3) 43 | int(5) 44 | int(7) 45 | int(9) 46 | 47 | Warning: tdb_get_seqnum(): %d is not a valid Trivial DB context resource in %s on line %d 48 | bool(false) 49 | Done 50 | -------------------------------------------------------------------------------- /tests/tdb_open_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_open() errors 3 | --FILE-- 4 | 27 | --EXPECTF-- 28 | Warning: tdb_open(): No such file or directory in %s on line %d 29 | bool(false) 30 | 31 | Warning: tdb_open(): Is a directory in %s on line %d 32 | bool(false) 33 | 34 | Warning: tdb_open(): No such file or directory in %s on line %d 35 | bool(false) 36 | 37 | Warning: tdb_open(): The integer value of hash_size cannot be less than zero in %s on line %d 38 | bool(false) 39 | 40 | Warning: tdb_open(): No such file or directory in %s on line %d 41 | bool(false) 42 | resource(%d) of type (Trivial DB context) 43 | 44 | Warning: tdb_open(): Bad file descriptor in %s on line %d 45 | bool(false) 46 | 47 | Warning: tdb_open(): Permission denied in %s on line %d 48 | bool(false) 49 | Done 50 | -------------------------------------------------------------------------------- /tests/tdb_fetch_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_fetch() basic tests 3 | --FILE-- 4 | 25 | --EXPECTF-- 26 | Warning: tdb_fetch() expects exactly 2 parameters, 0 given in %s on line %d 27 | NULL 28 | 29 | Warning: tdb_fetch() expects exactly 2 parameters, 4 given in %s on line %d 30 | NULL 31 | 32 | Warning: tdb_fetch(): Record does not exist in %s on line %d 33 | bool(false) 34 | 35 | Warning: tdb_fetch(): Record does not exist in %s on line %d 36 | bool(false) 37 | string(5) "value" 38 | string(256) "" 39 | 40 | Warning: tdb_fetch(): %d is not a valid Trivial DB context resource in %s on line %d 41 | bool(false) 42 | Done 43 | -------------------------------------------------------------------------------- /tests/tdb_chainlock_002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_chainlock() basic tests 3 | --FILE-- 4 | 38 | --EXPECTF-- 39 | bool(true) 40 | bool(true) 41 | 42 | Warning: tdb_chainlock(): Locking error in %s on line %d 43 | bool(false) 44 | bool(true) 45 | bool(true) 46 | bool(true) 47 | string(13) "Locking error" 48 | bool(true) 49 | bool(true) 50 | string(13) "Locking error" 51 | bool(true) 52 | bool(true) 53 | string(13) "Locking error" 54 | 55 | Warning: tdb_chainlock(): %d is not a valid Trivial DB context resource in %s on line %d 56 | bool(false) 57 | Done 58 | -------------------------------------------------------------------------------- /tests/tdb_delete_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_delete() basic tests 3 | --FILE-- 4 | 28 | --EXPECTF-- 29 | Warning: tdb_delete() expects exactly 2 parameters, 0 given in %s on line %d 30 | NULL 31 | 32 | Warning: tdb_delete() expects exactly 2 parameters, 4 given in %s on line %d 33 | NULL 34 | 35 | Warning: tdb_delete(): Record does not exist in %s on line %d 36 | bool(false) 37 | 38 | Warning: tdb_delete(): Record does not exist in %s on line %d 39 | bool(false) 40 | string(0) "" 41 | bool(true) 42 | 43 | Warning: tdb_fetch(): Record does not exist in %s on line %d 44 | bool(false) 45 | string(5) "value" 46 | bool(true) 47 | 48 | Warning: tdb_fetch(): Record does not exist in %s on line %d 49 | bool(false) 50 | 51 | Warning: tdb_delete(): %d is not a valid Trivial DB context resource in %s on line %d 52 | bool(false) 53 | Done 54 | -------------------------------------------------------------------------------- /tests/tdb_update_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_update() basic tests 3 | --FILE-- 4 | 28 | --EXPECTF-- 29 | Warning: tdb_update() expects exactly 3 parameters, 0 given in %s on line %d 30 | NULL 31 | 32 | Warning: tdb_update() expects exactly 3 parameters, 4 given in %s on line %d 33 | NULL 34 | 35 | Warning: tdb_update(): Record does not exist in %s on line %d 36 | bool(false) 37 | 38 | Warning: tdb_update(): Record does not exist in %s on line %d 39 | bool(false) 40 | 41 | Warning: tdb_fetch(): Record does not exist in %s on line %d 42 | bool(false) 43 | 44 | Warning: tdb_fetch(): Record does not exist in %s on line %d 45 | bool(false) 46 | bool(true) 47 | bool(true) 48 | string(0) "" 49 | string(6) "value2" 50 | bool(true) 51 | bool(true) 52 | string(0) "" 53 | string(6) "value3" 54 | Done 55 | -------------------------------------------------------------------------------- /tests/tdb_unlock_002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_unlock() basic tests 3 | --FILE-- 4 | 33 | --EXPECTF-- 34 | Warning: tdb_unlock() expects at least 1 parameter, 0 given in %s on line %d 35 | NULL 36 | 37 | Warning: tdb_unlock() expects at most 2 parameters, 3 given in %s on line %d 38 | NULL 39 | 40 | Warning: tdb_unlock(): Locking error in %s on line %d 41 | bool(false) 42 | 43 | Warning: tdb_unlock(): Locking error in %s on line %d 44 | bool(false) 45 | bool(true) 46 | bool(true) 47 | 48 | Warning: tdb_unlock(): Locking error in %s on line %d 49 | bool(false) 50 | bool(true) 51 | 52 | Warning: tdb_unlock(): Locking error in %s on line %d 53 | bool(false) 54 | bool(true) 55 | 56 | Warning: tdb_unlock(): Locking error in %s on line %d 57 | bool(false) 58 | string(13) "Locking error" 59 | 60 | Warning: tdb_unlock(): %d is not a valid Trivial DB context resource in %s on line %d 61 | bool(false) 62 | Done 63 | -------------------------------------------------------------------------------- /tests/tdb_chainunlock_002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_chainunlock() basic tests 3 | --FILE-- 4 | 44 | --EXPECTF-- 45 | Warning: tdb_chainunlock() expects at least 2 parameters, 0 given in %s on line %d 46 | NULL 47 | 48 | Warning: tdb_chainunlock() expects at most 3 parameters, 4 given in %s on line %d 49 | NULL 50 | bool(true) 51 | bool(true) 52 | 53 | Warning: tdb_chainunlock(): Locking error in %s on line %d 54 | bool(false) 55 | bool(true) 56 | bool(true) 57 | bool(true) 58 | 59 | Warning: tdb_chainunlock(): IO Error in %s on line %d 60 | bool(false) 61 | bool(true) 62 | bool(true) 63 | bool(false) 64 | bool(false) 65 | bool(false) 66 | 67 | Warning: tdb_chainunlock(): %d is not a valid Trivial DB context resource in %s on line %d 68 | bool(false) 69 | Done 70 | -------------------------------------------------------------------------------- /php_tdb.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2007 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: Antony Dovgal | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | 21 | #ifndef PHP_TDB_H 22 | #define PHP_TDB_H 23 | 24 | extern zend_module_entry tdb_module_entry; 25 | #define phpext_tdb_ptr &tdb_module_entry 26 | 27 | #define PHP_TDB_VERSION "1.0.1-dev" 28 | 29 | #ifdef PHP_WIN32 30 | #define PHP_TDB_API __declspec(dllexport) 31 | #else 32 | #define PHP_TDB_API 33 | #endif 34 | 35 | #ifdef ZTS 36 | #include "TSRM.h" 37 | #endif 38 | 39 | PHP_MINIT_FUNCTION(tdb); 40 | PHP_MSHUTDOWN_FUNCTION(tdb); 41 | PHP_MINFO_FUNCTION(tdb); 42 | 43 | #endif /* PHP_TDB_H */ 44 | 45 | 46 | /* 47 | * Local variables: 48 | * tab-width: 4 49 | * c-basic-offset: 4 50 | * End: 51 | * vim600: noet sw=4 ts=4 fdm=marker 52 | * vim<600: noet sw=4 ts=4 53 | */ 54 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl $Id$ 2 | 3 | PHP_ARG_WITH(tdb, for Trivial DB support, 4 | [ --with-tdb Include Trivial DB support]) 5 | 6 | if test "$PHP_TDB" != "no"; then 7 | 8 | SEARCH_PATH="/usr/local/ /usr/" 9 | SEARCH_FOR="include/tdb.h" 10 | if test "$PHP_TDB" = "yes"; then 11 | AC_MSG_CHECKING([for Trivial DB files in default path]) 12 | for i in $SEARCH_PATH ; do 13 | if test -r $i/$SEARCH_FOR; then 14 | TDB_DIR=$i 15 | AC_MSG_RESULT(found in $i) 16 | fi 17 | done 18 | elif test -r $PHP_TDB/$SEARCH_FOR; then 19 | AC_MSG_CHECKING([for Trivial DB files in $PHP_TDB]) 20 | TDB_DIR=$PHP_TDB 21 | fi 22 | 23 | if test -z "$TDB_DIR"; then 24 | AC_MSG_RESULT([not found]) 25 | AC_MSG_ERROR([Could not find Trivial DB headers]) 26 | fi 27 | 28 | AC_MSG_RESULT([found]) 29 | 30 | dnl check if the headers contain definitions of required constants 31 | old_CFLAGS=$CFLAGS 32 | CFLAGS="-I$TDB_DIR/include" 33 | AC_CACHE_CHECK(for TDB_NOSYNC and TDB_SEQNUM presence, ac_cv_new_tdb, 34 | AC_TRY_COMPILE([ 35 | #include 36 | #include 37 | ],[ 38 | int a = TDB_NOSYNC; 39 | int b = TDB_SEQNUM; 40 | ],[ 41 | ac_cv_new_tdb=yes 42 | ],[ 43 | ac_cv_new_tdb=no 44 | ]) 45 | ) 46 | if test "$ac_cv_new_tdb" = "no"; then 47 | AC_MSG_ERROR([You seem to be using outdated version of TDB, which is not supported. See README for more info.]) 48 | fi 49 | CFLAGS=$old_CFLAGS 50 | 51 | PHP_ADD_INCLUDE($TDB_DIR/include) 52 | 53 | LIBNAME=tdb 54 | LIBSYMBOL=tdb_open 55 | 56 | PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, 57 | [ 58 | PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $TDB_DIR/lib, TDB_SHARED_LIBADD) 59 | AC_DEFINE(HAVE_TDBLIB,1,[ ]) 60 | ],[ 61 | AC_MSG_ERROR([wrong Trivial DB lib version or lib not found]) 62 | ],[ 63 | -L$TDB_DIR/lib -lm 64 | ]) 65 | 66 | if test "$enable_experimental_zts" = "yes"; then 67 | AC_MSG_ERROR([Trivial DB is not thread safe]) 68 | fi 69 | 70 | AC_DEFINE(HAVE_TDB,1,[ ]) 71 | PHP_SUBST(TDB_SHARED_LIBADD) 72 | 73 | PHP_NEW_EXTENSION(tdb, tdb.c, $ext_shared) 74 | fi 75 | -------------------------------------------------------------------------------- /tests/tdb_open_002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_open() errors - 2 3 | --FILE-- 4 | 49 | --EXPECTF-- 50 | Warning: tdb_open() expects at least 1 parameter, 0 given in %s on line %d 51 | NULL 52 | 53 | Warning: tdb_open() expects at most 5 parameters, 7 given in %s on line %d 54 | NULL 55 | 56 | Warning: tdb_open() expects at most 5 parameters, 7 given in %s on line %d 57 | NULL 58 | resource(%d) of type (Trivial DB context) 59 | bool(true) 60 | resource(%d) of type (Trivial DB context) 61 | bool(true) 62 | resource(%d) of type (Trivial DB context) 63 | bool(true) 64 | 65 | Warning: tdb_open(): No such file or directory in %s on line %d 66 | bool(false) 67 | 68 | Warning: tdb_open(): No such file or directory in %s on line %d 69 | bool(false) 70 | 71 | Warning: tdb_open(): No such file or directory in %s on line %d 72 | bool(false) 73 | 74 | Warning: tdb_open(): No such file or directory in %s on line %d 75 | bool(false) 76 | 77 | Warning: tdb_open(): No such file or directory in %s on line %d 78 | bool(false) 79 | 80 | Warning: tdb_open(): Input/output error in %s on line %d 81 | bool(false) 82 | resource(%d) of type (Trivial DB context) 83 | bool(true) 84 | resource(%d) of type (Trivial DB context) 85 | bool(true) 86 | resource(%d) of type (Trivial DB context) 87 | bool(true) 88 | resource(%d) of type (Trivial DB context) 89 | bool(true) 90 | Done 91 | -------------------------------------------------------------------------------- /tests/tdb_transactions_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | transactions funcs tests - wrong arguments 3 | --FILE-- 4 | 32 | --EXPECTF-- 33 | Warning: tdb_transaction_start() expects exactly 1 parameter, 0 given in %s on line %d 34 | NULL 35 | 36 | Warning: tdb_transaction_start() expects exactly 1 parameter, 3 given in %s on line %d 37 | NULL 38 | 39 | Warning: tdb_transaction_start() expects exactly 1 parameter, 2 given in %s on line %d 40 | NULL 41 | 42 | Warning: tdb_transaction_cancel() expects exactly 1 parameter, 0 given in %s on line %d 43 | NULL 44 | 45 | Warning: tdb_transaction_cancel() expects exactly 1 parameter, 3 given in %s on line %d 46 | NULL 47 | 48 | Warning: tdb_transaction_cancel() expects exactly 1 parameter, 2 given in %s on line %d 49 | NULL 50 | 51 | Warning: tdb_transaction_commit() expects exactly 1 parameter, 0 given in %s on line %d 52 | NULL 53 | 54 | Warning: tdb_transaction_commit() expects exactly 1 parameter, 3 given in %s on line %d 55 | NULL 56 | 57 | Warning: tdb_transaction_commit() expects exactly 1 parameter, 2 given in %s on line %d 58 | NULL 59 | 60 | Warning: tdb_transaction_recover() expects exactly 1 parameter, 0 given in %s on line %d 61 | NULL 62 | 63 | Warning: tdb_transaction_recover() expects exactly 1 parameter, 3 given in %s on line %d 64 | NULL 65 | 66 | Warning: tdb_transaction_recover() expects exactly 1 parameter, 2 given in %s on line %d 67 | NULL 68 | 69 | Warning: tdb_transaction_start(): %d is not a valid Trivial DB context resource in %s on line %d 70 | bool(false) 71 | 72 | Warning: tdb_transaction_cancel(): %d is not a valid Trivial DB context resource in %s on line %d 73 | bool(false) 74 | 75 | Warning: tdb_transaction_commit(): %d is not a valid Trivial DB context resource in %s on line %d 76 | bool(false) 77 | 78 | Warning: tdb_transaction_recover(): %d is not a valid Trivial DB context resource in %s on line %d 79 | bool(false) 80 | Done 81 | -------------------------------------------------------------------------------- /tests/tdb_store_001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | tdb_store() basic tests 3 | --FILE-- 4 | 43 | --EXPECTF-- 44 | Warning: tdb_store() expects exactly 4 parameters, 1 given in %s on line %d 45 | NULL 46 | 47 | Warning: tdb_store() expects exactly 4 parameters, 5 given in %s on line %d 48 | NULL 49 | 50 | Warning: tdb_store(): Invalid operation mode specified: 0 in %s on line %d 51 | bool(false) 52 | 53 | Warning: tdb_store(): Invalid operation mode specified: -1 in %s on line %d 54 | bool(false) 55 | 56 | Warning: tdb_store(): Invalid operation mode specified: 2147483647 in %s on line %d 57 | bool(false) 58 | 59 | Warning: tdb_store(): Record does not exist in %s on line %d 60 | bool(false) 61 | bool(true) 62 | 63 | Warning: tdb_store(): Record exists in %s on line %d 64 | bool(false) 65 | string(0) "" 66 | bool(true) 67 | string(1024) "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest" 68 | bool(true) 69 | string(256) "blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah" 70 | bool(true) 71 | string(10) "test value" 72 | bool(true) 73 | string(10) "test value" 74 | bool(true) 75 | string(11) "test value2" 76 | 77 | Warning: tdb_store(): %d is not a valid Trivial DB context resource in %s on line %d 78 | bool(false) 79 | Done 80 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | tdb 7 | pecl.php.net 8 | Trivial DB bindings 9 | 10 | This extension provides bindings for Trivial DB. 11 | 12 | 13 | Antony Dovgal 14 | tony2001 15 | tony2001@php.net 16 | yes 17 | 18 | 2008-04-18 19 | 20 | 21 | 1.0.0 22 | 1.0.0 23 | 24 | 25 | stable 26 | stable 27 | 28 | PHP 29 | 30 | - Fixed PECL bug #13684 (tdb fails to configure on FreeBSD) 31 | - Improved configure checks in order to detect wrong TDB version. 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 5.0.0 82 | 6.0.0 83 | 6.0.0 84 | 85 | 86 | 1.4.0b1 87 | 88 | 89 | 90 | tdb 91 | 92 | 93 | 94 | 95 | 2007-08-06 96 | 97 | 98 | 0.1.0 99 | 0.1.0 100 | 101 | 102 | beta 103 | beta 104 | 105 | PHP 106 | 107 | - Initial release. 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /tdb.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2007 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: Antony Dovgal | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif 24 | 25 | #include "php.h" 26 | #include "php_ini.h" 27 | #include "ext/standard/info.h" 28 | #include "php_tdb.h" 29 | 30 | #include 31 | #include 32 | 33 | static int le_tdb; 34 | #define le_tdb_name "Trivial DB context" 35 | 36 | #ifdef COMPILE_DL_TDB 37 | ZEND_GET_MODULE(tdb) 38 | #endif 39 | 40 | typedef struct _php_tdb_context_t { 41 | int id; 42 | TDB_CONTEXT *tdb; 43 | } php_tdb_context_t; 44 | 45 | #define PHP_FETCH_TDB_RESOURCE(tdb_zval, ctx) \ 46 | ZEND_FETCH_RESOURCE(ctx, php_tdb_context_t*, &tdb_zval, -1, le_tdb_name, le_tdb); \ 47 | /* this is pure paranoia */ \ 48 | if (!ctx->tdb) { \ 49 | RETURN_FALSE; \ 50 | } 51 | 52 | static void php_tdb_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */ 53 | { 54 | php_tdb_context_t *ctx = (php_tdb_context_t *)rsrc->ptr; 55 | 56 | if (ctx->tdb) { 57 | tdb_close(ctx->tdb); 58 | ctx->tdb = NULL; 59 | } 60 | efree(ctx); 61 | } 62 | /* }}} */ 63 | 64 | static inline void php_tdb_errmsg(php_tdb_context_t *ctx TSRMLS_DC) /* {{{ */ 65 | { 66 | if (ctx && ctx->tdb && tdb_error(ctx->tdb)) { 67 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", tdb_errorstr(ctx->tdb)); 68 | } 69 | } 70 | /* }}} */ 71 | 72 | #define PHP_TDB_CONSTANT(name) \ 73 | REGISTER_LONG_CONSTANT( #name, name, CONST_CS | CONST_PERSISTENT) 74 | 75 | /* {{{ PHP_MINIT_FUNCTION 76 | */ 77 | PHP_MINIT_FUNCTION(tdb) 78 | { 79 | le_tdb = zend_register_list_destructors_ex(php_tdb_list_dtor, NULL, le_tdb_name, module_number); 80 | 81 | PHP_TDB_CONSTANT(TDB_REPLACE); 82 | PHP_TDB_CONSTANT(TDB_INSERT); 83 | PHP_TDB_CONSTANT(TDB_MODIFY); 84 | 85 | PHP_TDB_CONSTANT(TDB_CLEAR_IF_FIRST); 86 | PHP_TDB_CONSTANT(TDB_INTERNAL); 87 | PHP_TDB_CONSTANT(TDB_NOLOCK); 88 | PHP_TDB_CONSTANT(TDB_NOMMAP); 89 | PHP_TDB_CONSTANT(TDB_NOSYNC); 90 | PHP_TDB_CONSTANT(TDB_SEQNUM); 91 | 92 | PHP_TDB_CONSTANT(O_CREAT); 93 | PHP_TDB_CONSTANT(O_APPEND); 94 | PHP_TDB_CONSTANT(O_EXCL); 95 | PHP_TDB_CONSTANT(O_SYNC); 96 | PHP_TDB_CONSTANT(O_TRUNC); 97 | PHP_TDB_CONSTANT(O_RDONLY); 98 | PHP_TDB_CONSTANT(O_RDWR); 99 | 100 | PHP_TDB_CONSTANT(S_IRWXU); 101 | PHP_TDB_CONSTANT(S_IRUSR); 102 | PHP_TDB_CONSTANT(S_IWUSR); 103 | PHP_TDB_CONSTANT(S_IXUSR); 104 | PHP_TDB_CONSTANT(S_IRWXG); 105 | PHP_TDB_CONSTANT(S_IRGRP); 106 | PHP_TDB_CONSTANT(S_IWGRP); 107 | PHP_TDB_CONSTANT(S_IXGRP); 108 | PHP_TDB_CONSTANT(S_IRWXO); 109 | PHP_TDB_CONSTANT(S_IROTH); 110 | PHP_TDB_CONSTANT(S_IWOTH); 111 | PHP_TDB_CONSTANT(S_IXOTH); 112 | 113 | return SUCCESS; 114 | } 115 | /* }}} */ 116 | 117 | /* {{{ PHP_MSHUTDOWN_FUNCTION 118 | */ 119 | PHP_MSHUTDOWN_FUNCTION(tdb) 120 | { 121 | return SUCCESS; 122 | } 123 | /* }}} */ 124 | 125 | /* {{{ PHP_MINFO_FUNCTION 126 | */ 127 | PHP_MINFO_FUNCTION(tdb) 128 | { 129 | php_info_print_table_start(); 130 | php_info_print_table_header(2, "Trivial DB support", "enabled"); 131 | php_info_print_table_row(2, "Extension version", PHP_TDB_VERSION); 132 | php_info_print_table_row(2, "Revision", "$Revision$"); 133 | php_info_print_table_end(); 134 | } 135 | /* }}} */ 136 | 137 | /* {{{ proto resource tdb_open(string file [, int hash_size [, int tdb_flags [, int open_flags [, int mode ]]]]) 138 | Open or create the database and return DB resource. 139 | */ 140 | static PHP_FUNCTION(tdb_open) 141 | { 142 | php_tdb_context_t *ctx; 143 | TDB_CONTEXT *tdb; 144 | char *file; 145 | int file_len; 146 | long hash_size = 0; 147 | long tdb_flags = 0; 148 | long open_flags = O_CREAT|O_RDWR; 149 | long mode = S_IRUSR|S_IWUSR; 150 | 151 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|llll", &file, &file_len, &hash_size, &tdb_flags, &open_flags, &mode) == FAILURE) { 152 | return; 153 | } 154 | 155 | #if PHP_MAJOR_VERSION < 6 156 | if (file_len && PG(safe_mode) && (!php_checkuid(file, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { 157 | RETURN_FALSE; 158 | } 159 | #endif 160 | 161 | if (php_check_open_basedir(file TSRMLS_CC)) { 162 | RETURN_FALSE; 163 | } 164 | 165 | if ((int)hash_size < 0) { 166 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "The integer value of hash_size cannot be less than zero"); 167 | RETURN_FALSE; 168 | } 169 | 170 | tdb = tdb_open(file, (int)hash_size, (int)tdb_flags, (int)open_flags, (mode_t)mode); 171 | 172 | if (!tdb) { 173 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); 174 | RETURN_FALSE; 175 | } 176 | 177 | ctx = emalloc(sizeof(php_tdb_context_t)); 178 | ctx->tdb = tdb; 179 | 180 | ctx->id = ZEND_REGISTER_RESOURCE(return_value, ctx, le_tdb); 181 | } 182 | /* }}} */ 183 | 184 | /* {{{ proto bool tdb_close(resource tdb) 185 | Close & free the TDB resource 186 | */ 187 | static PHP_FUNCTION(tdb_close) 188 | { 189 | php_tdb_context_t *ctx; 190 | zval *tdb; 191 | int res; 192 | 193 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tdb) == FAILURE) { 194 | return; 195 | } 196 | 197 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 198 | 199 | res = tdb_close(ctx->tdb); 200 | ctx->tdb = NULL; 201 | zend_list_delete(ctx->id); 202 | 203 | if (res) { 204 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); 205 | RETURN_FALSE; 206 | } 207 | RETURN_TRUE; 208 | } 209 | /* }}} */ 210 | 211 | /* {{{ proto string tdb_error(resource tdb) 212 | Return the error status of the TDB context or false if no error occured 213 | */ 214 | static PHP_FUNCTION(tdb_error) 215 | { 216 | php_tdb_context_t *ctx; 217 | zval *tdb; 218 | enum TDB_ERROR err; 219 | 220 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tdb) == FAILURE) { 221 | return; 222 | } 223 | 224 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 225 | 226 | err = tdb_error(ctx->tdb); 227 | 228 | /* don't return "Success" error */ 229 | if (err) { 230 | RETURN_STRING((char *)tdb_errorstr(ctx->tdb), 1); 231 | } 232 | RETURN_FALSE; 233 | } 234 | /* }}} */ 235 | 236 | static void php_tdb_store(INTERNAL_FUNCTION_PARAMETERS, long flag) /* {{{ */ 237 | { 238 | php_tdb_context_t *ctx; 239 | zval *tdb; 240 | TDB_DATA tdb_key, tdb_data; 241 | char *key, *data; 242 | int key_len, data_len, res; 243 | 244 | if (!flag) { 245 | /* store */ 246 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssl", &tdb, &key, &key_len, &data, &data_len, &flag) == FAILURE) { 247 | return; 248 | } 249 | switch(flag) { 250 | case TDB_REPLACE: 251 | case TDB_INSERT: 252 | case TDB_MODIFY: 253 | break; 254 | default: 255 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid operation mode specified: %ld", flag); 256 | RETURN_FALSE; 257 | break; 258 | } 259 | } else { 260 | /* update / insert / replace */ 261 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &tdb, &key, &key_len, &data, &data_len) == FAILURE) { 262 | return; 263 | } 264 | } 265 | 266 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 267 | 268 | tdb_key.dptr = key; 269 | tdb_key.dsize = key_len; 270 | tdb_data.dptr = data; 271 | tdb_data.dsize = data_len; 272 | 273 | res = tdb_store(ctx->tdb, tdb_key, tdb_data, (int)flag); 274 | 275 | if (res) { 276 | php_tdb_errmsg(ctx TSRMLS_CC); 277 | RETURN_FALSE; 278 | } 279 | RETURN_TRUE; 280 | } 281 | /* }}} */ 282 | 283 | /* {{{ proto bool tdb_store(resource tdb, string key, string data, int flag) 284 | Store the data in the database using the specified key 285 | */ 286 | static PHP_FUNCTION(tdb_store) 287 | { 288 | php_tdb_store(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); 289 | } 290 | /* }}} */ 291 | 292 | /* {{{ proto bool tdb_replace(resource tdb, string key, string data) 293 | Replaces or inserts the data in the database using the specified key. 294 | This works even if such record doesn't exist. 295 | */ 296 | static PHP_FUNCTION(tdb_replace) 297 | { 298 | php_tdb_store(INTERNAL_FUNCTION_PARAM_PASSTHRU, TDB_REPLACE); 299 | } 300 | /* }}} */ 301 | 302 | /* {{{ proto bool tdb_insert(resource tdb, string key, string data) 303 | Inserts the data in the database using the specified key. 304 | Insert will fail if such record already exists. 305 | */ 306 | static PHP_FUNCTION(tdb_insert) 307 | { 308 | php_tdb_store(INTERNAL_FUNCTION_PARAM_PASSTHRU, TDB_INSERT); 309 | } 310 | /* }}} */ 311 | 312 | /* {{{ proto bool tdb_update(resource tdb, string key, string data) 313 | Modifies the data in the database using the specified key. 314 | This operation will fail if such record doesn't exist. 315 | */ 316 | static PHP_FUNCTION(tdb_update) 317 | { 318 | php_tdb_store(INTERNAL_FUNCTION_PARAM_PASSTHRU, TDB_MODIFY); 319 | } 320 | /* }}} */ 321 | 322 | /* {{{ proto bool tdb_append(resource tdb, string key, string data) 323 | Appends the data to the record or creates new record with the data. 324 | */ 325 | static PHP_FUNCTION(tdb_append) 326 | { 327 | php_tdb_context_t *ctx; 328 | zval *tdb; 329 | TDB_DATA tdb_key, tdb_data; 330 | char *key, *data; 331 | int key_len, data_len, res; 332 | 333 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &tdb, &key, &key_len, &data, &data_len) == FAILURE) { 334 | return; 335 | } 336 | 337 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 338 | 339 | tdb_key.dptr = key; 340 | tdb_key.dsize = key_len; 341 | tdb_data.dptr = data; 342 | tdb_data.dsize = data_len; 343 | 344 | res = tdb_append(ctx->tdb, tdb_key, tdb_data); 345 | 346 | if (res) { 347 | php_tdb_errmsg(ctx TSRMLS_CC); 348 | RETURN_FALSE; 349 | } 350 | RETURN_TRUE; 351 | } 352 | /* }}} */ 353 | 354 | /* {{{ proto string tdb_fetch(resource tdb, string key) 355 | Fetch the data from the database. 356 | */ 357 | static PHP_FUNCTION(tdb_fetch) 358 | { 359 | php_tdb_context_t *ctx; 360 | zval *tdb; 361 | TDB_DATA tdb_key, tdb_data; 362 | char *key; 363 | int key_len; 364 | 365 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &tdb, &key, &key_len) == FAILURE) { 366 | return; 367 | } 368 | 369 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 370 | 371 | tdb_key.dptr = key; 372 | tdb_key.dsize = key_len; 373 | 374 | tdb_data = tdb_fetch(ctx->tdb, tdb_key); 375 | 376 | if (tdb_data.dptr == NULL) { 377 | php_tdb_errmsg(ctx TSRMLS_CC); 378 | RETURN_FALSE; 379 | } 380 | RETVAL_STRINGL(tdb_data.dptr, tdb_data.dsize, 1); 381 | free(tdb_data.dptr); 382 | } 383 | /* }}} */ 384 | 385 | /* {{{ proto bool tdb_delete(resource tdb, string key) 386 | Delete record from the database 387 | */ 388 | static PHP_FUNCTION(tdb_delete) 389 | { 390 | php_tdb_context_t *ctx; 391 | zval *tdb; 392 | TDB_DATA tdb_key; 393 | char *key; 394 | int key_len, res; 395 | 396 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &tdb, &key, &key_len) == FAILURE) { 397 | return; 398 | } 399 | 400 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 401 | 402 | tdb_key.dptr = key; 403 | tdb_key.dsize = key_len; 404 | 405 | res = tdb_delete(ctx->tdb, tdb_key); 406 | 407 | if (res) { 408 | php_tdb_errmsg(ctx TSRMLS_CC); 409 | RETURN_FALSE; 410 | } 411 | RETURN_TRUE; 412 | } 413 | /* }}} */ 414 | 415 | /* {{{ proto bool tdb_exists(resource tdb, string key) 416 | Return true if such record exists and false otherwise 417 | */ 418 | static PHP_FUNCTION(tdb_exists) 419 | { 420 | php_tdb_context_t *ctx; 421 | zval *tdb; 422 | TDB_DATA tdb_key; 423 | char *key; 424 | int key_len, res; 425 | 426 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &tdb, &key, &key_len) == FAILURE) { 427 | return; 428 | } 429 | 430 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 431 | 432 | tdb_key.dptr = key; 433 | tdb_key.dsize = key_len; 434 | 435 | res = tdb_exists(ctx->tdb, tdb_key); 436 | 437 | if (res) { /* found */ 438 | RETURN_TRUE; 439 | } 440 | RETURN_FALSE; 441 | } 442 | /* }}} */ 443 | 444 | /* {{{ proto bool tdb_lock(resource tdb [, bool read_lock]) 445 | Lock the database 446 | */ 447 | static PHP_FUNCTION(tdb_lock) 448 | { 449 | php_tdb_context_t *ctx; 450 | zval *tdb; 451 | int res; 452 | zend_bool read_lock = 0; 453 | 454 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|b", &tdb, &read_lock) == FAILURE) { 455 | return; 456 | } 457 | 458 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 459 | 460 | if (!read_lock) { 461 | res = tdb_lockall(ctx->tdb); 462 | } else { 463 | res = tdb_lockall_read(ctx->tdb); 464 | } 465 | 466 | if (res) { 467 | php_tdb_errmsg(ctx TSRMLS_CC); 468 | RETURN_FALSE; 469 | } 470 | RETURN_TRUE; 471 | } 472 | /* }}} */ 473 | 474 | /* {{{ proto bool tdb_unlock(resource tdb [, bool read_lock]) 475 | Unlock the database 476 | */ 477 | static PHP_FUNCTION(tdb_unlock) 478 | { 479 | php_tdb_context_t *ctx; 480 | zval *tdb; 481 | int res; 482 | zend_bool read_lock = 0; 483 | 484 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|b", &tdb, &read_lock) == FAILURE) { 485 | return; 486 | } 487 | 488 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 489 | 490 | if (!read_lock) { 491 | res = tdb_unlockall(ctx->tdb); 492 | } else { 493 | res = tdb_unlockall_read(ctx->tdb); 494 | } 495 | 496 | if (res) { 497 | php_tdb_errmsg(ctx TSRMLS_CC); 498 | RETURN_FALSE; 499 | } 500 | RETURN_TRUE; 501 | } 502 | /* }}} */ 503 | 504 | /* {{{ proto bool tdb_chainlock(resource tdb, string key [, bool read_lock]) 505 | Lock one hash chain 506 | */ 507 | static PHP_FUNCTION(tdb_chainlock) 508 | { 509 | php_tdb_context_t *ctx; 510 | zval *tdb; 511 | int res; 512 | zend_bool read_lock = 0; 513 | char *key; 514 | int key_len; 515 | TDB_DATA tdb_key; 516 | 517 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|b", &tdb, &key, &key_len, &read_lock) == FAILURE) { 518 | return; 519 | } 520 | 521 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 522 | 523 | tdb_key.dptr = key; 524 | tdb_key.dsize = key_len; 525 | 526 | if (!read_lock) { 527 | res = tdb_chainlock(ctx->tdb, tdb_key); 528 | } else { 529 | res = tdb_chainlock_read(ctx->tdb, tdb_key); 530 | } 531 | 532 | if (res) { 533 | php_tdb_errmsg(ctx TSRMLS_CC); 534 | RETURN_FALSE; 535 | } 536 | RETURN_TRUE; 537 | } 538 | /* }}} */ 539 | 540 | /* {{{ proto bool tdb_chainunlock(resource tdb, string key [, bool read_lock]) 541 | Unlock one hash chain 542 | */ 543 | static PHP_FUNCTION(tdb_chainunlock) 544 | { 545 | php_tdb_context_t *ctx; 546 | zval *tdb; 547 | int res; 548 | zend_bool read_lock = 0; 549 | char *key; 550 | int key_len; 551 | TDB_DATA tdb_key; 552 | 553 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|b", &tdb, &key, &key_len, &read_lock) == FAILURE) { 554 | return; 555 | } 556 | 557 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 558 | 559 | tdb_key.dptr = key; 560 | tdb_key.dsize = key_len; 561 | 562 | if (!read_lock) { 563 | res = tdb_chainunlock(ctx->tdb, tdb_key); 564 | } else { 565 | res = tdb_chainunlock_read(ctx->tdb, tdb_key); 566 | } 567 | 568 | if (res) { 569 | php_tdb_errmsg(ctx TSRMLS_CC); 570 | RETURN_FALSE; 571 | } 572 | RETURN_TRUE; 573 | } 574 | /* }}} */ 575 | 576 | /* {{{ PHP_TDB_1_PARAM_FUNCTION(func) */ 577 | #define PHP_TDB_1_PARAM_FUNCTION(func) \ 578 | php_tdb_context_t *ctx; \ 579 | zval *tdb; \ 580 | int res; \ 581 | \ 582 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tdb) == FAILURE) { \ 583 | return; \ 584 | } \ 585 | \ 586 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); \ 587 | \ 588 | res = func(ctx->tdb); \ 589 | \ 590 | if (res) { \ 591 | php_tdb_errmsg(ctx TSRMLS_CC); \ 592 | RETURN_FALSE; \ 593 | } \ 594 | RETURN_TRUE; 595 | 596 | /* }}} */ 597 | 598 | /* {{{ proto bool tdb_transaction_start(resource tdb) 599 | Start transaction 600 | */ 601 | static PHP_FUNCTION(tdb_transaction_start) 602 | { 603 | PHP_TDB_1_PARAM_FUNCTION(tdb_transaction_start); 604 | } 605 | /* }}} */ 606 | 607 | /* {{{ proto bool tdb_transaction_commit(resource tdb) 608 | Commit transaction 609 | */ 610 | static PHP_FUNCTION(tdb_transaction_commit) 611 | { 612 | PHP_TDB_1_PARAM_FUNCTION(tdb_transaction_commit); 613 | } 614 | /* }}} */ 615 | 616 | /* {{{ proto bool tdb_transaction_cancel(resource tdb) 617 | Cancel transaction 618 | */ 619 | static PHP_FUNCTION(tdb_transaction_cancel) 620 | { 621 | PHP_TDB_1_PARAM_FUNCTION(tdb_transaction_cancel); 622 | } 623 | /* }}} */ 624 | 625 | /* {{{ proto bool tdb_transaction_recover(resource tdb) 626 | Recover transaction 627 | */ 628 | static PHP_FUNCTION(tdb_transaction_recover) 629 | { 630 | PHP_TDB_1_PARAM_FUNCTION(tdb_transaction_recover); 631 | } 632 | /* }}} */ 633 | 634 | /* {{{ proto string tdb_first_key(resource tdb) 635 | Return key of the first record in the db 636 | */ 637 | static PHP_FUNCTION(tdb_first_key) 638 | { 639 | php_tdb_context_t *ctx; 640 | zval *tdb; 641 | TDB_DATA tdb_key; 642 | 643 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tdb) == FAILURE) { 644 | return; 645 | } 646 | 647 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 648 | 649 | tdb_key = tdb_firstkey(ctx->tdb); 650 | 651 | if (!tdb_key.dptr) { 652 | php_tdb_errmsg(ctx TSRMLS_CC); 653 | RETURN_FALSE; 654 | } 655 | RETVAL_STRINGL(tdb_key.dptr, tdb_key.dsize, 1); 656 | free(tdb_key.dptr); 657 | } 658 | /* }}} */ 659 | 660 | /* {{{ proto string tdb_next_key(resource tdb, string key) 661 | Return key of the next entry in the db 662 | */ 663 | static PHP_FUNCTION(tdb_next_key) 664 | { 665 | php_tdb_context_t *ctx; 666 | zval *tdb; 667 | char *key; 668 | int key_len; 669 | TDB_DATA old_key, tdb_key; 670 | 671 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &tdb, &key, &key_len) == FAILURE) { 672 | return; 673 | } 674 | 675 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 676 | 677 | old_key.dptr = key; 678 | old_key.dsize = key_len; 679 | 680 | tdb_key = tdb_nextkey(ctx->tdb, old_key); 681 | 682 | if (!tdb_key.dptr) { 683 | php_tdb_errmsg(ctx TSRMLS_CC); 684 | RETURN_FALSE; 685 | } 686 | RETVAL_STRINGL(tdb_key.dptr, tdb_key.dsize, 1); 687 | free(tdb_key.dptr); 688 | } 689 | /* }}} */ 690 | 691 | /* {{{ proto bool tdb_set_max_dead(resource tdb, long dead) 692 | Set the maximum number of dead records per hash chain 693 | */ 694 | static PHP_FUNCTION(tdb_set_max_dead) 695 | { 696 | php_tdb_context_t *ctx; 697 | zval *tdb; 698 | long dead; 699 | int dead_int; 700 | 701 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &tdb, &dead) == FAILURE) { 702 | return; 703 | } 704 | 705 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 706 | 707 | dead_int = (int)dead; 708 | if (dead_int < 0) { 709 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Maximum number of dead records cannot be less than zero"); 710 | RETURN_FALSE; 711 | } 712 | 713 | tdb_set_max_dead(ctx->tdb, dead_int); 714 | RETURN_TRUE; 715 | } 716 | /* }}} */ 717 | 718 | /* {{{ proto long tdb_get_seqnum(resource tdb) 719 | Get the TDB sequence number. 720 | */ 721 | static PHP_FUNCTION(tdb_get_seqnum) 722 | { 723 | php_tdb_context_t *ctx; 724 | zval *tdb; 725 | int res; 726 | 727 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tdb) == FAILURE) { 728 | return; 729 | } 730 | 731 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 732 | 733 | res = tdb_get_seqnum(ctx->tdb); 734 | RETURN_LONG(res); 735 | } 736 | /* }}} */ 737 | 738 | /* {{{ proto long tdb_get_flags(resource tdb) 739 | Get the flags used when the db was created. 740 | */ 741 | static PHP_FUNCTION(tdb_get_flags) 742 | { 743 | php_tdb_context_t *ctx; 744 | zval *tdb; 745 | int res; 746 | 747 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tdb) == FAILURE) { 748 | return; 749 | } 750 | 751 | PHP_FETCH_TDB_RESOURCE(tdb, ctx); 752 | 753 | res = tdb_get_flags(ctx->tdb); 754 | RETURN_LONG(res); 755 | } 756 | /* }}} */ 757 | 758 | /* {{{ tdb_functions[] 759 | */ 760 | zend_function_entry tdb_functions[] = { 761 | PHP_FE(tdb_open, NULL) 762 | PHP_FE(tdb_close, NULL) 763 | PHP_FE(tdb_error, NULL) 764 | PHP_FE(tdb_store, NULL) 765 | PHP_FE(tdb_replace, NULL) 766 | PHP_FE(tdb_insert, NULL) 767 | PHP_FE(tdb_update, NULL) 768 | PHP_FE(tdb_append, NULL) 769 | PHP_FE(tdb_fetch, NULL) 770 | PHP_FE(tdb_delete, NULL) 771 | PHP_FE(tdb_exists, NULL) 772 | PHP_FE(tdb_lock, NULL) 773 | PHP_FE(tdb_unlock, NULL) 774 | PHP_FE(tdb_chainlock, NULL) 775 | PHP_FE(tdb_chainunlock, NULL) 776 | PHP_FE(tdb_transaction_start, NULL) 777 | PHP_FE(tdb_transaction_commit, NULL) 778 | PHP_FE(tdb_transaction_cancel, NULL) 779 | PHP_FE(tdb_transaction_recover, NULL) 780 | PHP_FE(tdb_first_key, NULL) 781 | PHP_FE(tdb_next_key, NULL) 782 | PHP_FE(tdb_set_max_dead, NULL) 783 | PHP_FE(tdb_get_seqnum, NULL) 784 | PHP_FE(tdb_get_flags, NULL) 785 | {NULL, NULL, NULL} 786 | }; 787 | /* }}} */ 788 | 789 | /* {{{ tdb_module_entry 790 | */ 791 | zend_module_entry tdb_module_entry = { 792 | #if ZEND_MODULE_API_NO >= 20010901 793 | STANDARD_MODULE_HEADER, 794 | #endif 795 | "tdb", 796 | tdb_functions, 797 | PHP_MINIT(tdb), 798 | PHP_MSHUTDOWN(tdb), 799 | NULL, 800 | NULL, 801 | PHP_MINFO(tdb), 802 | #if ZEND_MODULE_API_NO >= 20010901 803 | PHP_TDB_VERSION, 804 | #endif 805 | STANDARD_MODULE_PROPERTIES 806 | }; 807 | /* }}} */ 808 | 809 | /* 810 | * Local variables: 811 | * tab-width: 4 812 | * c-basic-offset: 4 813 | * End: 814 | * vim600: noet sw=4 ts=4 fdm=marker 815 | * vim<600: noet sw=4 ts=4 816 | */ 817 | --------------------------------------------------------------------------------