Back to index

php5  5.3.10
php_dba.h
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Author: Sascha Schumann <sascha@schumann.cx>                         |
00016    +----------------------------------------------------------------------+
00017  */
00018 
00019 /* $Id: php_dba.h 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #ifndef PHP_DBA_H
00022 #define PHP_DBA_H
00023 
00024 #if HAVE_DBA
00025 
00026 typedef enum { 
00027        /* do not allow 0 here */
00028        DBA_READER = 1,
00029        DBA_WRITER,
00030        DBA_TRUNC,
00031        DBA_CREAT
00032 } dba_mode_t;
00033 
00034 typedef struct dba_lock {
00035        php_stream *fp;
00036        char *name;
00037        int mode; /* LOCK_EX,LOCK_SH */
00038 } dba_lock;
00039 
00040 typedef struct dba_info {
00041        /* public */
00042        void *dbf;               /* ptr to private data or whatever */
00043        char *path;
00044        dba_mode_t mode;
00045        php_stream *fp;  /* this is the database stream for builtin handlers */
00046        int fd;
00047        /* arg[cv] are only available when the dba_open handler is called! */
00048        int argc;
00049        zval ***argv;
00050        /* private */
00051        int flags; /* whether and how dba did locking and other flags*/
00052        struct dba_handler *hnd;    
00053        dba_lock lock;
00054 } dba_info;
00055 
00056 #define DBA_LOCK_READER  (0x0001)
00057 #define DBA_LOCK_WRITER  (0x0002)
00058 #define DBA_LOCK_CREAT   (0x0004)
00059 #define DBA_LOCK_TRUNC   (0x0008)
00060 
00061 #define DBA_LOCK_EXT     (0)
00062 #define DBA_LOCK_ALL     (DBA_LOCK_READER|DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC)
00063 #define DBA_LOCK_WCT     (DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC)
00064 
00065 #define DBA_STREAM_OPEN  (0x0010)
00066 #define DBA_PERSISTENT   (0x0020)
00067 
00068 #define DBA_CAST_AS_FD   (0x0050)
00069 #define DBA_NO_APPEND    (0x00D0)
00070 
00071 extern zend_module_entry dba_module_entry;
00072 #define dba_module_ptr &dba_module_entry
00073 
00074 typedef struct dba_handler {
00075        char *name; /* handler name */
00076        int flags; /* whether and how dba does locking and other flags*/
00077        int (*open)(dba_info *, char **error TSRMLS_DC);
00078        void (*close)(dba_info * TSRMLS_DC);
00079        char* (*fetch)(dba_info *, char *, int, int, int * TSRMLS_DC);
00080        int (*update)(dba_info *, char *, int, char *, int, int TSRMLS_DC);
00081        int (*exists)(dba_info *, char *, int TSRMLS_DC);
00082        int (*delete)(dba_info *, char *, int TSRMLS_DC);
00083        char* (*firstkey)(dba_info *, int * TSRMLS_DC);
00084        char* (*nextkey)(dba_info *, int * TSRMLS_DC);
00085        int (*optimize)(dba_info * TSRMLS_DC);
00086        int (*sync)(dba_info * TSRMLS_DC);
00087        char* (*info)(struct dba_handler *hnd, dba_info * TSRMLS_DC);
00088               /* dba_info==NULL: Handler info, dba_info!=NULL: Database info */
00089 } dba_handler;
00090 
00091 /* common prototypes which must be supplied by modules */
00092 
00093 #define DBA_OPEN_FUNC(x) \
00094        int dba_open_##x(dba_info *info, char **error TSRMLS_DC)
00095 #define DBA_CLOSE_FUNC(x) \
00096        void dba_close_##x(dba_info *info TSRMLS_DC)
00097 #define DBA_FETCH_FUNC(x) \
00098        char *dba_fetch_##x(dba_info *info, char *key, int keylen, int skip, int *newlen TSRMLS_DC)
00099 #define DBA_UPDATE_FUNC(x) \
00100        int dba_update_##x(dba_info *info, char *key, int keylen, char *val, int vallen, int mode TSRMLS_DC)
00101 #define DBA_EXISTS_FUNC(x) \
00102        int dba_exists_##x(dba_info *info, char *key, int keylen TSRMLS_DC)
00103 #define DBA_DELETE_FUNC(x) \
00104        int dba_delete_##x(dba_info *info, char *key, int keylen TSRMLS_DC)
00105 #define DBA_FIRSTKEY_FUNC(x) \
00106        char *dba_firstkey_##x(dba_info *info, int *newlen TSRMLS_DC)
00107 #define DBA_NEXTKEY_FUNC(x) \
00108        char *dba_nextkey_##x(dba_info *info, int *newlen TSRMLS_DC)
00109 #define DBA_OPTIMIZE_FUNC(x) \
00110        int dba_optimize_##x(dba_info *info TSRMLS_DC)
00111 #define DBA_SYNC_FUNC(x) \
00112        int dba_sync_##x(dba_info *info TSRMLS_DC)
00113 #define DBA_INFO_FUNC(x) \
00114        char *dba_info_##x(dba_handler *hnd, dba_info *info TSRMLS_DC)
00115 
00116 #define DBA_FUNCS(x) \
00117        DBA_OPEN_FUNC(x); \
00118        DBA_CLOSE_FUNC(x); \
00119        DBA_FETCH_FUNC(x); \
00120        DBA_UPDATE_FUNC(x); \
00121        DBA_DELETE_FUNC(x); \
00122        DBA_EXISTS_FUNC(x); \
00123        DBA_FIRSTKEY_FUNC(x); \
00124        DBA_NEXTKEY_FUNC(x); \
00125        DBA_OPTIMIZE_FUNC(x); \
00126        DBA_SYNC_FUNC(x); \
00127        DBA_INFO_FUNC(x)
00128 
00129 #define VALLEN(p) Z_STRVAL_PP(p), Z_STRLEN_PP(p)
00130        
00131 PHP_FUNCTION(dba_open);
00132 PHP_FUNCTION(dba_popen);
00133 PHP_FUNCTION(dba_close);
00134 PHP_FUNCTION(dba_firstkey);
00135 PHP_FUNCTION(dba_nextkey);
00136 PHP_FUNCTION(dba_replace);
00137 PHP_FUNCTION(dba_insert);
00138 PHP_FUNCTION(dba_delete);
00139 PHP_FUNCTION(dba_exists);
00140 PHP_FUNCTION(dba_fetch);
00141 PHP_FUNCTION(dba_optimize);
00142 PHP_FUNCTION(dba_sync);
00143 PHP_FUNCTION(dba_handlers);
00144 PHP_FUNCTION(dba_list);
00145 PHP_FUNCTION(dba_key_split);
00146 
00147 #else
00148 #define dba_module_ptr NULL
00149 #endif
00150 
00151 #define phpext_dba_ptr dba_module_ptr
00152 
00153 #endif