diff options
author | Marcus Boerger <helly@php.net> | 2002-12-30 13:07:30 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2002-12-30 13:07:30 +0000 |
commit | 4d2f7207c04a6377699cb96a7946cde3662c51fe (patch) | |
tree | 991d8a9236c178eeb497c2a58a56ff37c0cfcca8 | |
parent | 426cf8eb5712f10e84a16f1cbb127c1aaa045d9c (diff) | |
download | php-git-4d2f7207c04a6377699cb96a7946cde3662c51fe.tar.gz |
Add info function to handlers and return handler info when dba_handlers is
called with optional parameter full_info set true.
-rw-r--r-- | ext/dba/dba.c | 30 | ||||
-rw-r--r-- | ext/dba/dba_cdb.c | 13 | ||||
-rw-r--r-- | ext/dba/dba_db2.c | 5 | ||||
-rw-r--r-- | ext/dba/dba_db3.c | 5 | ||||
-rw-r--r-- | ext/dba/dba_db4.c | 5 | ||||
-rw-r--r-- | ext/dba/dba_dbm.c | 5 | ||||
-rw-r--r-- | ext/dba/dba_flatfile.c | 5 | ||||
-rw-r--r-- | ext/dba/dba_gdbm.c | 6 | ||||
-rw-r--r-- | ext/dba/dba_ndbm.c | 6 | ||||
-rw-r--r-- | ext/dba/libcdb/cdb.c | 7 | ||||
-rw-r--r-- | ext/dba/libcdb/cdb.h | 2 | ||||
-rw-r--r-- | ext/dba/libcdb/cdb_make.c | 6 | ||||
-rw-r--r-- | ext/dba/libcdb/cdb_make.h | 1 | ||||
-rw-r--r-- | ext/dba/libflatfile/flatfile.c | 7 | ||||
-rw-r--r-- | ext/dba/libflatfile/flatfile.h | 1 | ||||
-rw-r--r-- | ext/dba/php_dba.h | 22 |
16 files changed, 105 insertions, 21 deletions
diff --git a/ext/dba/dba.c b/ext/dba/dba.c index a6273e7f75..7441d7af8c 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -92,21 +92,6 @@ zend_module_entry dba_module_entry = { ZEND_GET_MODULE(dba) #endif -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); -} dba_handler; - /* {{{ macromania */ #define DBA_ID_PARS \ @@ -163,7 +148,7 @@ typedef struct dba_handler { {\ #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_optimize_##name, dba_sync_##name, dba_info_##name \ }, #define DBA_HND(name, flags) DBA_NAMED_HND(name, name, flags) @@ -207,7 +192,7 @@ static dba_handler handler[] = { #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, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } }; #if DBA_FLATFILE @@ -844,13 +829,14 @@ PHP_FUNCTION(dba_sync) } /* }}} */ -/* {{{ proto array dba_handlers() +/* {{{ proto array dba_handlers([bool full_info]) List configured databases */ PHP_FUNCTION(dba_handlers) { dba_handler *hptr; + zend_bool full_info = 0; - if (ZEND_NUM_ARGS()!=0) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &full_info) == FAILURE) { ZEND_WRONG_PARAM_COUNT(); RETURN_FALSE; } @@ -860,7 +846,11 @@ PHP_FUNCTION(dba_handlers) RETURN_FALSE; } for(hptr = handler; hptr->name; hptr++) { - add_next_index_string(return_value, hptr->name, 1); + 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); + } } } /* }}} */ diff --git a/ext/dba/dba_cdb.c b/ext/dba/dba_cdb.c index b704465ab9..8d773f90d2 100644 --- a/ext/dba/dba_cdb.c +++ b/ext/dba/dba_cdb.c @@ -324,6 +324,19 @@ DBA_SYNC_FUNC(cdb) 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 /* diff --git a/ext/dba/dba_db2.c b/ext/dba/dba_db2.c index e1afa98ff4..40cf535192 100644 --- a/ext/dba/dba_db2.c +++ b/ext/dba/dba_db2.c @@ -188,6 +188,11 @@ DBA_SYNC_FUNC(db2) return dba->dbp->sync(dba->dbp, 0) ? FAILURE : SUCCESS; } +DBA_INFO_FUNC(db2) +{ + return estrdup(DB_VERSION_STRING); +} + #endif /* diff --git a/ext/dba/dba_db3.c b/ext/dba/dba_db3.c index 25c7bdc028..97cd4ef390 100644 --- a/ext/dba/dba_db3.c +++ b/ext/dba/dba_db3.c @@ -218,6 +218,11 @@ DBA_SYNC_FUNC(db3) return dba->dbp->sync(dba->dbp, 0) ? FAILURE : SUCCESS; } +DBA_INFO_FUNC(db3) +{ + return estrdup(DB_VERSION_STRING); +} + #endif /* diff --git a/ext/dba/dba_db4.c b/ext/dba/dba_db4.c index 5de50df2c7..3f4c6ef857 100644 --- a/ext/dba/dba_db4.c +++ b/ext/dba/dba_db4.c @@ -217,6 +217,11 @@ DBA_SYNC_FUNC(db4) return dba->dbp->sync(dba->dbp, 0) ? FAILURE : SUCCESS; } +DBA_INFO_FUNC(db4) +{ + return estrdup(DB_VERSION_STRING); +} + #endif /* diff --git a/ext/dba/dba_dbm.c b/ext/dba/dba_dbm.c index cb7664987b..90efdb0baf 100644 --- a/ext/dba/dba_dbm.c +++ b/ext/dba/dba_dbm.c @@ -177,6 +177,11 @@ DBA_SYNC_FUNC(dbm) return SUCCESS; } +DBA_INFO_FUNC(dbm) +{ + return estrdup("DBM"); +} + #endif /* diff --git a/ext/dba/dba_flatfile.c b/ext/dba/dba_flatfile.c index 53a577ab57..f2100e124e 100644 --- a/ext/dba/dba_flatfile.c +++ b/ext/dba/dba_flatfile.c @@ -163,6 +163,11 @@ DBA_SYNC_FUNC(flatfile) return SUCCESS; } +DBA_INFO_FUNC(flatfile) +{ + return estrdup(flatfile_version()); +} + #endif /* diff --git a/ext/dba/dba_gdbm.c b/ext/dba/dba_gdbm.c index 93c53d4b94..84799e446b 100644 --- a/ext/dba/dba_gdbm.c +++ b/ext/dba/dba_gdbm.c @@ -180,6 +180,12 @@ DBA_SYNC_FUNC(gdbm) gdbm_sync(dba->dbf); return SUCCESS; } + +DBA_INFO_FUNC(gdbm) +{ + return estrdup(gdbm_version); +} + #endif /* diff --git a/ext/dba/dba_ndbm.c b/ext/dba/dba_ndbm.c index 06583c780b..c79bb3c5cc 100644 --- a/ext/dba/dba_ndbm.c +++ b/ext/dba/dba_ndbm.c @@ -153,6 +153,12 @@ DBA_SYNC_FUNC(ndbm) { return SUCCESS; } + +DBA_INFO_FUNC(ndbm) +{ + return estrdup("NDBM"); +} + #endif /* diff --git a/ext/dba/libcdb/cdb.c b/ext/dba/libcdb/cdb.c index fbc27eaceb..c4f1c625db 100644 --- a/ext/dba/libcdb/cdb.c +++ b/ext/dba/libcdb/cdb.c @@ -193,3 +193,10 @@ int cdb_find(struct cdb *c, char *key, unsigned int len TSRMLS_DC) 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 index a74ef2325b..df3bad45ba 100644 --- a/ext/dba/libcdb/cdb.h +++ b/ext/dba/libcdb/cdb.h @@ -52,4 +52,6 @@ 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 index 4023a154a6..9d1896af32 100644 --- a/ext/dba/libcdb/cdb_make.c +++ b/ext/dba/libcdb/cdb_make.c @@ -238,3 +238,9 @@ int cdb_make_finish(struct cdb_make *c TSRMLS_DC) 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 index e5fb65fe49..ff409682d9 100644 --- a/ext/dba/libcdb/cdb_make.h +++ b/ext/dba/libcdb/cdb_make.h @@ -59,5 +59,6 @@ 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/libflatfile/flatfile.c b/ext/dba/libflatfile/flatfile.c index 4cb820875e..c2d4f91ffb 100644 --- a/ext/dba/libflatfile/flatfile.c +++ b/ext/dba/libflatfile/flatfile.c @@ -295,6 +295,13 @@ datum flatfile_nextkey(flatfile *dba TSRMLS_DC) { } /* }}} */ +/* {{{ flatfile_version */ +char *flatfile_version() +{ + return "1.0, $Revision$"; +} +/* }}} */ + /* * Local variables: * tab-width: 4 diff --git a/ext/dba/libflatfile/flatfile.h b/ext/dba/libflatfile/flatfile.h index 9c910ae157..522028bcff 100644 --- a/ext/dba/libflatfile/flatfile.h +++ b/ext/dba/libflatfile/flatfile.h @@ -43,5 +43,6 @@ 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/php_dba.h b/ext/dba/php_dba.h index 2e8877b6b5..3f61219d5a 100644 --- a/ext/dba/php_dba.h +++ b/ext/dba/php_dba.h @@ -68,6 +68,23 @@ typedef struct dba_info { 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) \ @@ -90,6 +107,8 @@ extern zend_module_entry dba_module_entry; 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); \ @@ -101,7 +120,8 @@ extern zend_module_entry dba_module_entry; DBA_FIRSTKEY_FUNC(x); \ DBA_NEXTKEY_FUNC(x); \ DBA_OPTIMIZE_FUNC(x); \ - DBA_SYNC_FUNC(x) + DBA_SYNC_FUNC(x); \ + DBA_INFO_FUNC(x) #define VALLEN(p) Z_STRVAL_PP(p), Z_STRLEN_PP(p) |