1 /* 2 +----------------------------------------------------------------------+ 3 | Copyright (c) The PHP Group | 4 +----------------------------------------------------------------------+ 5 | This source file is subject to version 3.01 of the PHP license, | 6 | that is bundled with this package in the file LICENSE, and is | 7 | available through the world-wide-web at the following url: | 8 | http://www.php.net/license/3_01.txt | 9 | If you did not receive a copy of the PHP license and are unable to | 10 | obtain it through the world-wide-web, please send a note to | 11 | license@php.net so we can mail you a copy immediately. | 12 +----------------------------------------------------------------------+ 13 | Author: Sascha Schumann <sascha@schumann.cx> | 14 +----------------------------------------------------------------------+ 15 */ 16 17 #ifndef PHP_DBA_H 18 #define PHP_DBA_H 19 20 #include "php_version.h" 21 #define PHP_DBA_VERSION PHP_VERSION 22 23 #if HAVE_DBA 24 25 typedef enum { 26 /* do not allow 0 here */ 27 DBA_READER = 1, 28 DBA_WRITER, 29 DBA_TRUNC, 30 DBA_CREAT 31 } dba_mode_t; 32 33 typedef struct dba_lock { 34 php_stream *fp; 35 char *name; 36 int mode; /* LOCK_EX,LOCK_SH */ 37 } dba_lock; 38 39 typedef struct dba_info { 40 /* public */ 41 void *dbf; /* ptr to private data or whatever */ 42 char *path; 43 dba_mode_t mode; 44 php_stream *fp; /* this is the database stream for builtin handlers */ 45 int fd; 46 /* arg[cv] are only available when the dba_open handler is called! */ 47 int argc; 48 zval *argv; 49 /* private */ 50 int flags; /* whether and how dba did locking and other flags*/ 51 struct dba_handler *hnd; 52 dba_lock lock; 53 } dba_info; 54 55 #define DBA_LOCK_READER (0x0001) 56 #define DBA_LOCK_WRITER (0x0002) 57 #define DBA_LOCK_CREAT (0x0004) 58 #define DBA_LOCK_TRUNC (0x0008) 59 60 #define DBA_LOCK_EXT (0) 61 #define DBA_LOCK_ALL (DBA_LOCK_READER|DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC) 62 #define DBA_LOCK_WCT (DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC) 63 64 #define DBA_STREAM_OPEN (0x0010) 65 #define DBA_PERSISTENT (0x0020) 66 67 #define DBA_CAST_AS_FD (0x0050) 68 #define DBA_NO_APPEND (0x00D0) 69 70 extern zend_module_entry dba_module_entry; 71 #define dba_module_ptr &dba_module_entry 72 73 typedef struct dba_handler { 74 char *name; /* handler name */ 75 int flags; /* whether and how dba does locking and other flags*/ 76 int (*open)(dba_info *, char **error); 77 void (*close)(dba_info *); 78 char* (*fetch)(dba_info *, char *, size_t, int, size_t *); 79 int (*update)(dba_info *, char *, size_t, char *, size_t, int); 80 int (*exists)(dba_info *, char *, size_t); 81 int (*delete)(dba_info *, char *, size_t); 82 char* (*firstkey)(dba_info *, size_t *); 83 char* (*nextkey)(dba_info *, size_t *); 84 int (*optimize)(dba_info *); 85 int (*sync)(dba_info *); 86 char* (*info)(struct dba_handler *hnd, dba_info *); 87 /* dba_info==NULL: Handler info, dba_info!=NULL: Database info */ 88 } dba_handler; 89 90 /* common prototypes which must be supplied by modules */ 91 92 #define DBA_OPEN_FUNC(x) \ 93 int dba_open_##x(dba_info *info, char **error) 94 #define DBA_CLOSE_FUNC(x) \ 95 void dba_close_##x(dba_info *info) 96 #define DBA_FETCH_FUNC(x) \ 97 char *dba_fetch_##x(dba_info *info, char *key, size_t keylen, int skip, size_t *newlen) 98 #define DBA_UPDATE_FUNC(x) \ 99 int dba_update_##x(dba_info *info, char *key, size_t keylen, char *val, size_t vallen, int mode) 100 #define DBA_EXISTS_FUNC(x) \ 101 int dba_exists_##x(dba_info *info, char *key, size_t keylen) 102 #define DBA_DELETE_FUNC(x) \ 103 int dba_delete_##x(dba_info *info, char *key, size_t keylen) 104 #define DBA_FIRSTKEY_FUNC(x) \ 105 char *dba_firstkey_##x(dba_info *info, size_t *newlen) 106 #define DBA_NEXTKEY_FUNC(x) \ 107 char *dba_nextkey_##x(dba_info *info, size_t *newlen) 108 #define DBA_OPTIMIZE_FUNC(x) \ 109 int dba_optimize_##x(dba_info *info) 110 #define DBA_SYNC_FUNC(x) \ 111 int dba_sync_##x(dba_info *info) 112 #define DBA_INFO_FUNC(x) \ 113 char *dba_info_##x(dba_handler *hnd, dba_info *info) 114 115 #define DBA_FUNCS(x) \ 116 DBA_OPEN_FUNC(x); \ 117 DBA_CLOSE_FUNC(x); \ 118 DBA_FETCH_FUNC(x); \ 119 DBA_UPDATE_FUNC(x); \ 120 DBA_DELETE_FUNC(x); \ 121 DBA_EXISTS_FUNC(x); \ 122 DBA_FIRSTKEY_FUNC(x); \ 123 DBA_NEXTKEY_FUNC(x); \ 124 DBA_OPTIMIZE_FUNC(x); \ 125 DBA_SYNC_FUNC(x); \ 126 DBA_INFO_FUNC(x) 127 128 #else 129 #define dba_module_ptr NULL 130 #endif 131 132 #define phpext_dba_ptr dba_module_ptr 133 134 #endif 135