1999-07-21 23:12:32 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-09 01:33:29 +08:00
|
|
|
| PHP Version 5 |
|
1999-07-21 23:12:32 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2007-01-01 17:36:18 +08:00
|
|
|
| Copyright (c) 1997-2007 The PHP Group |
|
1999-07-21 23:12:32 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2001-06-20 05:25:53 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 20:51:34 +08:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
2001-06-20 05:25:53 +08:00
|
|
|
| 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. |
|
1999-07-21 23:12:32 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2002-02-28 16:29:35 +08:00
|
|
|
| Author: Sascha Schumann <sascha@schumann.cx> |
|
1999-07-21 23:12:32 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2000-07-03 08:41:19 +08:00
|
|
|
#ifndef PHP_DBA_H
|
|
|
|
#define PHP_DBA_H
|
1999-07-21 23:12:32 +08:00
|
|
|
|
|
|
|
#if HAVE_DBA
|
|
|
|
|
|
|
|
typedef enum {
|
2002-11-08 09:03:53 +08:00
|
|
|
/* do not allow 0 here */
|
1999-07-21 23:12:32 +08:00
|
|
|
DBA_READER = 1,
|
|
|
|
DBA_WRITER,
|
|
|
|
DBA_TRUNC,
|
|
|
|
DBA_CREAT
|
|
|
|
} dba_mode_t;
|
|
|
|
|
2002-11-08 09:03:53 +08:00
|
|
|
typedef struct dba_lock {
|
|
|
|
php_stream *fp;
|
|
|
|
char *name;
|
2002-11-14 22:32:39 +08:00
|
|
|
int mode; /* LOCK_EX,LOCK_SH */
|
2002-11-08 09:03:53 +08:00
|
|
|
} dba_lock;
|
|
|
|
|
1999-07-21 23:12:32 +08:00
|
|
|
typedef struct dba_info {
|
|
|
|
/* public */
|
|
|
|
void *dbf; /* ptr to private data or whatever */
|
|
|
|
char *path;
|
|
|
|
dba_mode_t mode;
|
2002-11-11 01:58:46 +08:00
|
|
|
php_stream *fp; /* this is the database stream for builtin handlers */
|
2003-12-19 04:14:15 +08:00
|
|
|
int fd;
|
1999-07-21 23:12:32 +08:00
|
|
|
/* arg[cv] are only available when the dba_open handler is called! */
|
|
|
|
int argc;
|
2002-08-24 06:24:02 +08:00
|
|
|
zval ***argv;
|
1999-07-21 23:12:32 +08:00
|
|
|
/* private */
|
2002-11-14 22:32:39 +08:00
|
|
|
int flags; /* whether and how dba did locking and other flags*/
|
2002-11-11 01:58:46 +08:00
|
|
|
struct dba_handler *hnd;
|
2002-11-08 09:03:53 +08:00
|
|
|
dba_lock lock;
|
1999-07-21 23:12:32 +08:00
|
|
|
} dba_info;
|
|
|
|
|
2002-11-11 01:58:46 +08:00
|
|
|
#define DBA_LOCK_READER (0x0001)
|
|
|
|
#define DBA_LOCK_WRITER (0x0002)
|
|
|
|
#define DBA_LOCK_CREAT (0x0004)
|
|
|
|
#define DBA_LOCK_TRUNC (0x0008)
|
2002-11-08 09:03:53 +08:00
|
|
|
|
|
|
|
#define DBA_LOCK_EXT (0)
|
|
|
|
#define DBA_LOCK_ALL (DBA_LOCK_READER|DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC)
|
|
|
|
#define DBA_LOCK_WCT (DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC)
|
|
|
|
|
2002-11-11 01:58:46 +08:00
|
|
|
#define DBA_STREAM_OPEN (0x0010)
|
2002-12-21 01:47:58 +08:00
|
|
|
#define DBA_PERSISTENT (0x0020)
|
2002-11-11 01:58:46 +08:00
|
|
|
|
2003-12-19 04:14:15 +08:00
|
|
|
#define DBA_CAST_AS_FD (0x0050)
|
|
|
|
#define DBA_NO_APPEND (0x00D0)
|
|
|
|
|
1999-12-18 04:55:31 +08:00
|
|
|
extern zend_module_entry dba_module_entry;
|
1999-07-21 23:12:32 +08:00
|
|
|
#define dba_module_ptr &dba_module_entry
|
|
|
|
|
2002-12-30 21:07:30 +08:00
|
|
|
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;
|
|
|
|
|
1999-07-21 23:12:32 +08:00
|
|
|
/* common prototypes which must be supplied by modules */
|
|
|
|
|
|
|
|
#define DBA_OPEN_FUNC(x) \
|
2002-11-05 22:46:36 +08:00
|
|
|
int dba_open_##x(dba_info *info, char **error TSRMLS_DC)
|
1999-07-21 23:12:32 +08:00
|
|
|
#define DBA_CLOSE_FUNC(x) \
|
2002-11-04 20:27:13 +08:00
|
|
|
void dba_close_##x(dba_info *info TSRMLS_DC)
|
1999-07-21 23:12:32 +08:00
|
|
|
#define DBA_FETCH_FUNC(x) \
|
2002-11-04 20:27:13 +08:00
|
|
|
char *dba_fetch_##x(dba_info *info, char *key, int keylen, int skip, int *newlen TSRMLS_DC)
|
1999-07-21 23:12:32 +08:00
|
|
|
#define DBA_UPDATE_FUNC(x) \
|
2002-11-04 20:27:13 +08:00
|
|
|
int dba_update_##x(dba_info *info, char *key, int keylen, char *val, int vallen, int mode TSRMLS_DC)
|
1999-07-21 23:12:32 +08:00
|
|
|
#define DBA_EXISTS_FUNC(x) \
|
2002-11-04 20:27:13 +08:00
|
|
|
int dba_exists_##x(dba_info *info, char *key, int keylen TSRMLS_DC)
|
1999-07-21 23:12:32 +08:00
|
|
|
#define DBA_DELETE_FUNC(x) \
|
2002-11-04 20:27:13 +08:00
|
|
|
int dba_delete_##x(dba_info *info, char *key, int keylen TSRMLS_DC)
|
1999-07-21 23:12:32 +08:00
|
|
|
#define DBA_FIRSTKEY_FUNC(x) \
|
2002-11-04 20:27:13 +08:00
|
|
|
char *dba_firstkey_##x(dba_info *info, int *newlen TSRMLS_DC)
|
1999-07-21 23:12:32 +08:00
|
|
|
#define DBA_NEXTKEY_FUNC(x) \
|
2002-11-04 20:27:13 +08:00
|
|
|
char *dba_nextkey_##x(dba_info *info, int *newlen TSRMLS_DC)
|
1999-07-21 23:12:32 +08:00
|
|
|
#define DBA_OPTIMIZE_FUNC(x) \
|
2002-11-04 20:27:13 +08:00
|
|
|
int dba_optimize_##x(dba_info *info TSRMLS_DC)
|
1999-07-21 23:12:32 +08:00
|
|
|
#define DBA_SYNC_FUNC(x) \
|
2002-11-04 20:27:13 +08:00
|
|
|
int dba_sync_##x(dba_info *info TSRMLS_DC)
|
2002-12-30 21:07:30 +08:00
|
|
|
#define DBA_INFO_FUNC(x) \
|
|
|
|
char *dba_info_##x(dba_handler *hnd, dba_info *info TSRMLS_DC)
|
1999-07-21 23:12:32 +08:00
|
|
|
|
|
|
|
#define DBA_FUNCS(x) \
|
|
|
|
DBA_OPEN_FUNC(x); \
|
|
|
|
DBA_CLOSE_FUNC(x); \
|
|
|
|
DBA_FETCH_FUNC(x); \
|
|
|
|
DBA_UPDATE_FUNC(x); \
|
|
|
|
DBA_DELETE_FUNC(x); \
|
|
|
|
DBA_EXISTS_FUNC(x); \
|
|
|
|
DBA_FIRSTKEY_FUNC(x); \
|
|
|
|
DBA_NEXTKEY_FUNC(x); \
|
|
|
|
DBA_OPTIMIZE_FUNC(x); \
|
2002-12-30 21:07:30 +08:00
|
|
|
DBA_SYNC_FUNC(x); \
|
|
|
|
DBA_INFO_FUNC(x)
|
1999-07-21 23:12:32 +08:00
|
|
|
|
2000-11-23 05:47:15 +08:00
|
|
|
#define VALLEN(p) Z_STRVAL_PP(p), Z_STRLEN_PP(p)
|
1999-07-21 23:12:32 +08:00
|
|
|
|
|
|
|
PHP_FUNCTION(dba_open);
|
|
|
|
PHP_FUNCTION(dba_popen);
|
|
|
|
PHP_FUNCTION(dba_close);
|
|
|
|
PHP_FUNCTION(dba_firstkey);
|
|
|
|
PHP_FUNCTION(dba_nextkey);
|
|
|
|
PHP_FUNCTION(dba_replace);
|
|
|
|
PHP_FUNCTION(dba_insert);
|
|
|
|
PHP_FUNCTION(dba_delete);
|
|
|
|
PHP_FUNCTION(dba_exists);
|
|
|
|
PHP_FUNCTION(dba_fetch);
|
|
|
|
PHP_FUNCTION(dba_optimize);
|
|
|
|
PHP_FUNCTION(dba_sync);
|
2002-10-25 04:43:03 +08:00
|
|
|
PHP_FUNCTION(dba_handlers);
|
2002-10-25 18:06:35 +08:00
|
|
|
PHP_FUNCTION(dba_list);
|
2003-11-13 05:43:03 +08:00
|
|
|
PHP_FUNCTION(dba_key_split);
|
1999-07-21 23:12:32 +08:00
|
|
|
|
|
|
|
#else
|
|
|
|
#define dba_module_ptr NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define phpext_dba_ptr dba_module_ptr
|
|
|
|
|
|
|
|
#endif
|