php_dba.h 4.3 KB

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