xref: /PHP-8.3/ext/dba/php_dba.h (revision 421c56dd)
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    | https://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 #ifdef 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 	int mode; /* LOCK_EX,LOCK_SH */
36 } dba_lock;
37 
38 typedef struct dba_info {
39 	/* public */
40 	void *dbf;               /* ptr to private data or whatever */
41 	zend_string *path;
42 	dba_mode_t mode;
43 	php_stream *fp;  /* this is the database stream for builtin handlers */
44 	int fd;
45 	int file_permission;
46 	zend_long map_size;
47 	/* -1 for default driver flags */
48 	zend_long driver_flags;
49 	/* private */
50 	int flags; /* whether and how dba did locking and other flags*/
51 	const struct dba_handler *hnd;
52 	dba_lock lock;
53 } dba_info;
54 
55 #define DBA_DEFAULT_DRIVER_FLAGS -1
56 
57 #define DBA_LOCK_READER  (0x0001)
58 #define DBA_LOCK_WRITER  (0x0002)
59 #define DBA_LOCK_CREAT   (0x0004)
60 #define DBA_LOCK_TRUNC   (0x0008)
61 
62 #define DBA_LOCK_EXT     (0)
63 #define DBA_LOCK_ALL     (DBA_LOCK_READER|DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC)
64 #define DBA_LOCK_WCT     (DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC)
65 
66 #define DBA_STREAM_OPEN  (0x0010)
67 #define DBA_PERSISTENT   (0x0020)
68 
69 #define DBA_CAST_AS_FD   (0x0050)
70 #define DBA_NO_APPEND    (0x00D0)
71 
72 extern zend_module_entry dba_module_entry;
73 #define dba_module_ptr &dba_module_entry
74 
75 typedef struct dba_handler {
76 	const char *name; /* handler name */
77 	int flags; /* whether and how dba does locking and other flags*/
78 	zend_result (*open)(dba_info *, const char **error);
79 	void (*close)(dba_info *);
80 	zend_string* (*fetch)(dba_info *, zend_string *, int);
81 	zend_result (*update)(dba_info *, zend_string *, zend_string *, int);
82 	zend_result (*exists)(dba_info *, zend_string *);
83 	zend_result (*delete)(dba_info *, zend_string *);
84 	zend_string* (*firstkey)(dba_info *);
85 	zend_string* (*nextkey)(dba_info *);
86 	zend_result (*optimize)(dba_info *);
87 	zend_result (*sync)(dba_info *);
88 	char* (*info)(const struct dba_handler *hnd, dba_info *);
89 		/* dba_info==NULL: Handler info, dba_info!=NULL: Database info */
90 } dba_handler;
91 
92 /* common prototypes which must be supplied by modules */
93 
94 #define DBA_OPEN_FUNC(x) \
95 	zend_result dba_open_##x(dba_info *info, const char **error)
96 #define DBA_CLOSE_FUNC(x) \
97 	void dba_close_##x(dba_info *info)
98 #define DBA_FETCH_FUNC(x) \
99 	zend_string *dba_fetch_##x(dba_info *info, zend_string *key, int skip)
100 #define DBA_UPDATE_FUNC(x) \
101 	zend_result dba_update_##x(dba_info *info, zend_string *key, zend_string *val, int mode)
102 #define DBA_EXISTS_FUNC(x) \
103 	zend_result dba_exists_##x(dba_info *info, zend_string *key)
104 #define DBA_DELETE_FUNC(x) \
105 	zend_result dba_delete_##x(dba_info *info, zend_string *key)
106 #define DBA_FIRSTKEY_FUNC(x) \
107 	zend_string *dba_firstkey_##x(dba_info *info)
108 #define DBA_NEXTKEY_FUNC(x) \
109 	zend_string *dba_nextkey_##x(dba_info *info)
110 #define DBA_OPTIMIZE_FUNC(x) \
111 	zend_result dba_optimize_##x(dba_info *info)
112 #define DBA_SYNC_FUNC(x) \
113 	zend_result dba_sync_##x(dba_info *info)
114 #define DBA_INFO_FUNC(x) \
115 	char *dba_info_##x(const dba_handler *hnd, dba_info *info)
116 
117 #define DBA_FUNCS(x) \
118 	DBA_OPEN_FUNC(x); \
119 	DBA_CLOSE_FUNC(x); \
120 	DBA_FETCH_FUNC(x); \
121 	DBA_UPDATE_FUNC(x); \
122 	DBA_DELETE_FUNC(x); \
123 	DBA_EXISTS_FUNC(x); \
124 	DBA_FIRSTKEY_FUNC(x); \
125 	DBA_NEXTKEY_FUNC(x); \
126 	DBA_OPTIMIZE_FUNC(x); \
127 	DBA_SYNC_FUNC(x); \
128 	DBA_INFO_FUNC(x)
129 
130 #else
131 #define dba_module_ptr NULL
132 #endif
133 
134 #define phpext_dba_ptr dba_module_ptr
135 
136 #endif
137