1 /* 2 +----------------------------------------------------------------------+ 3 | PHP Version 7 | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) 1997-2018 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: Sascha Schumann <sascha@schumann.cx> | 16 +----------------------------------------------------------------------+ 17 */ 18 19 /* $Id$ */ 20 21 #ifndef PHP_DBA_H 22 #define PHP_DBA_H 23 24 #include "php_version.h" 25 #define PHP_DBA_VERSION PHP_VERSION 26 27 #if HAVE_DBA 28 29 typedef enum { 30 /* do not allow 0 here */ 31 DBA_READER = 1, 32 DBA_WRITER, 33 DBA_TRUNC, 34 DBA_CREAT 35 } dba_mode_t; 36 37 typedef struct dba_lock { 38 php_stream *fp; 39 char *name; 40 int mode; /* LOCK_EX,LOCK_SH */ 41 } dba_lock; 42 43 typedef struct dba_info { 44 /* public */ 45 void *dbf; /* ptr to private data or whatever */ 46 char *path; 47 dba_mode_t mode; 48 php_stream *fp; /* this is the database stream for builtin handlers */ 49 int fd; 50 /* arg[cv] are only available when the dba_open handler is called! */ 51 int argc; 52 zval *argv; 53 /* private */ 54 int flags; /* whether and how dba did locking and other flags*/ 55 struct dba_handler *hnd; 56 dba_lock lock; 57 } dba_info; 58 59 #define DBA_LOCK_READER (0x0001) 60 #define DBA_LOCK_WRITER (0x0002) 61 #define DBA_LOCK_CREAT (0x0004) 62 #define DBA_LOCK_TRUNC (0x0008) 63 64 #define DBA_LOCK_EXT (0) 65 #define DBA_LOCK_ALL (DBA_LOCK_READER|DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC) 66 #define DBA_LOCK_WCT (DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC) 67 68 #define DBA_STREAM_OPEN (0x0010) 69 #define DBA_PERSISTENT (0x0020) 70 71 #define DBA_CAST_AS_FD (0x0050) 72 #define DBA_NO_APPEND (0x00D0) 73 74 extern zend_module_entry dba_module_entry; 75 #define dba_module_ptr &dba_module_entry 76 77 typedef struct dba_handler { 78 char *name; /* handler name */ 79 int flags; /* whether and how dba does locking and other flags*/ 80 int (*open)(dba_info *, char **error); 81 void (*close)(dba_info *); 82 char* (*fetch)(dba_info *, char *, size_t, int, size_t *); 83 int (*update)(dba_info *, char *, size_t, char *, size_t, int); 84 int (*exists)(dba_info *, char *, size_t); 85 int (*delete)(dba_info *, char *, size_t); 86 char* (*firstkey)(dba_info *, size_t *); 87 char* (*nextkey)(dba_info *, size_t *); 88 int (*optimize)(dba_info *); 89 int (*sync)(dba_info *); 90 char* (*info)(struct dba_handler *hnd, dba_info *); 91 /* dba_info==NULL: Handler info, dba_info!=NULL: Database info */ 92 } dba_handler; 93 94 /* common prototypes which must be supplied by modules */ 95 96 #define DBA_OPEN_FUNC(x) \ 97 int dba_open_##x(dba_info *info, char **error) 98 #define DBA_CLOSE_FUNC(x) \ 99 void dba_close_##x(dba_info *info) 100 #define DBA_FETCH_FUNC(x) \ 101 char *dba_fetch_##x(dba_info *info, char *key, size_t keylen, int skip, size_t *newlen) 102 #define DBA_UPDATE_FUNC(x) \ 103 int dba_update_##x(dba_info *info, char *key, size_t keylen, char *val, size_t vallen, int mode) 104 #define DBA_EXISTS_FUNC(x) \ 105 int dba_exists_##x(dba_info *info, char *key, size_t keylen) 106 #define DBA_DELETE_FUNC(x) \ 107 int dba_delete_##x(dba_info *info, char *key, size_t keylen) 108 #define DBA_FIRSTKEY_FUNC(x) \ 109 char *dba_firstkey_##x(dba_info *info, size_t *newlen) 110 #define DBA_NEXTKEY_FUNC(x) \ 111 char *dba_nextkey_##x(dba_info *info, size_t *newlen) 112 #define DBA_OPTIMIZE_FUNC(x) \ 113 int dba_optimize_##x(dba_info *info) 114 #define DBA_SYNC_FUNC(x) \ 115 int dba_sync_##x(dba_info *info) 116 #define DBA_INFO_FUNC(x) \ 117 char *dba_info_##x(dba_handler *hnd, dba_info *info) 118 119 #define DBA_FUNCS(x) \ 120 DBA_OPEN_FUNC(x); \ 121 DBA_CLOSE_FUNC(x); \ 122 DBA_FETCH_FUNC(x); \ 123 DBA_UPDATE_FUNC(x); \ 124 DBA_DELETE_FUNC(x); \ 125 DBA_EXISTS_FUNC(x); \ 126 DBA_FIRSTKEY_FUNC(x); \ 127 DBA_NEXTKEY_FUNC(x); \ 128 DBA_OPTIMIZE_FUNC(x); \ 129 DBA_SYNC_FUNC(x); \ 130 DBA_INFO_FUNC(x) 131 132 PHP_FUNCTION(dba_open); 133 PHP_FUNCTION(dba_popen); 134 PHP_FUNCTION(dba_close); 135 PHP_FUNCTION(dba_firstkey); 136 PHP_FUNCTION(dba_nextkey); 137 PHP_FUNCTION(dba_replace); 138 PHP_FUNCTION(dba_insert); 139 PHP_FUNCTION(dba_delete); 140 PHP_FUNCTION(dba_exists); 141 PHP_FUNCTION(dba_fetch); 142 PHP_FUNCTION(dba_optimize); 143 PHP_FUNCTION(dba_sync); 144 PHP_FUNCTION(dba_handlers); 145 PHP_FUNCTION(dba_list); 146 PHP_FUNCTION(dba_key_split); 147 148 #else 149 #define dba_module_ptr NULL 150 #endif 151 152 #define phpext_dba_ptr dba_module_ptr 153 154 #endif 155