php_dba.h 5.0 KB

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