php_dba.h 4.8 KB

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