xref: /php-src/ext/dba/php_dba.h (revision 2097237d)
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 typedef struct dba_connection {
56 	dba_info *info;
57 	zend_string *hash;
58 	zend_object std;
59 } dba_connection;
60 
61 #define DBA_DEFAULT_DRIVER_FLAGS -1
62 
63 #define DBA_LOCK_READER  (0x0001)
64 #define DBA_LOCK_WRITER  (0x0002)
65 #define DBA_LOCK_CREAT   (0x0004)
66 #define DBA_LOCK_TRUNC   (0x0008)
67 
68 #define DBA_LOCK_EXT     (0)
69 #define DBA_LOCK_ALL     (DBA_LOCK_READER|DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC)
70 #define DBA_LOCK_WCT     (DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC)
71 
72 #define DBA_STREAM_OPEN  (0x0010)
73 #define DBA_PERSISTENT   (0x0020)
74 
75 #define DBA_CAST_AS_FD   (0x0050)
76 #define DBA_NO_APPEND    (0x00D0)
77 
78 extern zend_module_entry dba_module_entry;
79 #define dba_module_ptr &dba_module_entry
80 
81 typedef struct dba_handler {
82 	const char *name; /* handler name */
83 	int flags; /* whether and how dba does locking and other flags*/
84 	zend_result (*open)(dba_info *, const char **error);
85 	void (*close)(dba_info *);
86 	zend_string* (*fetch)(dba_info *, zend_string *, int);
87 	zend_result (*update)(dba_info *, zend_string *, zend_string *, int);
88 	zend_result (*exists)(dba_info *, zend_string *);
89 	zend_result (*delete)(dba_info *, zend_string *);
90 	zend_string* (*firstkey)(dba_info *);
91 	zend_string* (*nextkey)(dba_info *);
92 	zend_result (*optimize)(dba_info *);
93 	zend_result (*sync)(dba_info *);
94 	char* (*info)(const struct dba_handler *hnd, dba_info *);
95 		/* dba_info==NULL: Handler info, dba_info!=NULL: Database info */
96 } dba_handler;
97 
98 /* common prototypes which must be supplied by modules */
99 
100 #define DBA_OPEN_FUNC(x) \
101 	zend_result dba_open_##x(dba_info *info, const char **error)
102 #define DBA_CLOSE_FUNC(x) \
103 	void dba_close_##x(dba_info *info)
104 #define DBA_FETCH_FUNC(x) \
105 	zend_string *dba_fetch_##x(dba_info *info, zend_string *key, int skip)
106 #define DBA_UPDATE_FUNC(x) \
107 	zend_result dba_update_##x(dba_info *info, zend_string *key, zend_string *val, int mode)
108 #define DBA_EXISTS_FUNC(x) \
109 	zend_result dba_exists_##x(dba_info *info, zend_string *key)
110 #define DBA_DELETE_FUNC(x) \
111 	zend_result dba_delete_##x(dba_info *info, zend_string *key)
112 #define DBA_FIRSTKEY_FUNC(x) \
113 	zend_string *dba_firstkey_##x(dba_info *info)
114 #define DBA_NEXTKEY_FUNC(x) \
115 	zend_string *dba_nextkey_##x(dba_info *info)
116 #define DBA_OPTIMIZE_FUNC(x) \
117 	zend_result dba_optimize_##x(dba_info *info)
118 #define DBA_SYNC_FUNC(x) \
119 	zend_result dba_sync_##x(dba_info *info)
120 #define DBA_INFO_FUNC(x) \
121 	char *dba_info_##x(const dba_handler *hnd, dba_info *info)
122 
123 #define DBA_FUNCS(x) \
124 	DBA_OPEN_FUNC(x); \
125 	DBA_CLOSE_FUNC(x); \
126 	DBA_FETCH_FUNC(x); \
127 	DBA_UPDATE_FUNC(x); \
128 	DBA_DELETE_FUNC(x); \
129 	DBA_EXISTS_FUNC(x); \
130 	DBA_FIRSTKEY_FUNC(x); \
131 	DBA_NEXTKEY_FUNC(x); \
132 	DBA_OPTIMIZE_FUNC(x); \
133 	DBA_SYNC_FUNC(x); \
134 	DBA_INFO_FUNC(x)
135 
136 #else
137 #define dba_module_ptr NULL
138 #endif
139 
140 #define phpext_dba_ptr dba_module_ptr
141 
142 #endif
143