| 1 | #ifndef __XCACHE_H |
|---|
| 2 | #define __XCACHE_H |
|---|
| 3 | #define XCACHE_NAME "XCache" |
|---|
| 4 | #define XCACHE_VERSION "1.0.2" |
|---|
| 5 | #define XCACHE_AUTHOR "mOo" |
|---|
| 6 | #define XCACHE_COPYRIGHT "Copyright (c) 2005-2006" |
|---|
| 7 | #define XCACHE_URL "http://xcache.lighttpd.net" |
|---|
| 8 | |
|---|
| 9 | #include <php.h> |
|---|
| 10 | #include <zend_compile.h> |
|---|
| 11 | #include <zend_API.h> |
|---|
| 12 | #include "php_ini.h" |
|---|
| 13 | #include "zend_hash.h" |
|---|
| 14 | |
|---|
| 15 | #ifdef HAVE_CONFIG_H |
|---|
| 16 | #include <config.h> |
|---|
| 17 | #endif |
|---|
| 18 | #include "myshm.h" |
|---|
| 19 | #include "mem.h" |
|---|
| 20 | #include "lock.h" |
|---|
| 21 | |
|---|
| 22 | #ifndef ZEND_WIN32 |
|---|
| 23 | /* UnDefine if your filesystem doesn't support inodes */ |
|---|
| 24 | # define HAVE_INODE |
|---|
| 25 | #endif |
|---|
| 26 | #if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1 || PHP_MAJOR_VERSION > 5) |
|---|
| 27 | # define ZEND_ENGINE_2_1 |
|---|
| 28 | #endif |
|---|
| 29 | |
|---|
| 30 | #define NOTHING |
|---|
| 31 | /* ZendEngine code Switcher */ |
|---|
| 32 | #ifndef ZEND_ENGINE_2 |
|---|
| 33 | # define ZESW(v1, v2) v1 |
|---|
| 34 | #else |
|---|
| 35 | # define ZESW(v1, v2) v2 |
|---|
| 36 | #endif |
|---|
| 37 | |
|---|
| 38 | /* unicode */ |
|---|
| 39 | #ifdef IS_UNICODE |
|---|
| 40 | # define UNISW(text, unicode) unicode |
|---|
| 41 | #else |
|---|
| 42 | # define UNISW(text, unicode) text |
|---|
| 43 | #endif |
|---|
| 44 | #define BUCKET_KEY_SIZE(b) \ |
|---|
| 45 | (UNISW( \ |
|---|
| 46 | (b)->nKeyLength, \ |
|---|
| 47 | ((b)->key.type == IS_UNICODE) \ |
|---|
| 48 | ? UBYTES(b->nKeyLength) \ |
|---|
| 49 | : b->nKeyLength \ |
|---|
| 50 | )) |
|---|
| 51 | #define BUCKET_KEY(b) (UNISW((b)->arKey, (b)->key.u.string)) |
|---|
| 52 | #define BUCKET_UKEY(b) (UNISW((b)->arKey, (b)->key.u.unicode)) |
|---|
| 53 | #define BUCKET_KEY_TYPE(b) (UNISW(0, (b)->key.type)) |
|---|
| 54 | #ifdef IS_UNICODE |
|---|
| 55 | # define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key) |
|---|
| 56 | #else |
|---|
| 57 | # define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey) |
|---|
| 58 | #endif |
|---|
| 59 | #define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b)) |
|---|
| 60 | |
|---|
| 61 | #ifndef IS_UNICODE |
|---|
| 62 | typedef char *zstr; |
|---|
| 63 | # define ZSTR_S(s) (s) |
|---|
| 64 | # define ZSTR_U(s) (s) |
|---|
| 65 | # define ZSTR_V(s) (s) |
|---|
| 66 | #else |
|---|
| 67 | # define ZSTR_S(s) ((s)->s) |
|---|
| 68 | # define ZSTR_U(s) ((s)->u) |
|---|
| 69 | # define ZSTR_V(s) ((s)->v) |
|---|
| 70 | #endif |
|---|
| 71 | |
|---|
| 72 | /* {{{ u hash wrapper */ |
|---|
| 73 | #ifndef IS_UNICODE |
|---|
| 74 | # define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \ |
|---|
| 75 | zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest) |
|---|
| 76 | |
|---|
| 77 | # define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \ |
|---|
| 78 | zend_hash_find(ht, arKey, nKeyLength, pData) |
|---|
| 79 | |
|---|
| 80 | # define add_u_assoc_zval_ex(arg, type, key, key_len, value) \ |
|---|
| 81 | add_assoc_zval_ex(arg, key, key_len, value) |
|---|
| 82 | |
|---|
| 83 | #endif |
|---|
| 84 | /* }}} */ |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | #define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0]))) |
|---|
| 88 | #define ECALLOC_ONE(x) ECALLOC_N(x, 1) |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | typedef ulong xc_hash_value_t; |
|---|
| 93 | typedef struct { |
|---|
| 94 | int bits; |
|---|
| 95 | int size; |
|---|
| 96 | int mask; |
|---|
| 97 | } xc_hash_t; |
|---|
| 98 | |
|---|
| 99 | /* the class entry type to be stored in class_table */ |
|---|
| 100 | typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t; |
|---|
| 101 | |
|---|
| 102 | /* xc_cest_t to (zend_class_entry*) */ |
|---|
| 103 | #define CestToCePtr(st) (ZESW(\ |
|---|
| 104 | &(st), \ |
|---|
| 105 | st \ |
|---|
| 106 | ) ) |
|---|
| 107 | |
|---|
| 108 | /* ZCEP=zend class entry ptr */ |
|---|
| 109 | #define ZCEP_REFCOUNT_PTR(pce) (ZESW( \ |
|---|
| 110 | (pce)->refcount, \ |
|---|
| 111 | &((pce)->refcount) \ |
|---|
| 112 | )) |
|---|
| 113 | |
|---|
| 114 | #define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce) |
|---|
| 115 | |
|---|
| 116 | typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC); |
|---|
| 117 | |
|---|
| 118 | /* {{{ xc_cache_t */ |
|---|
| 119 | typedef struct _xc_entry_t xc_entry_t; |
|---|
| 120 | typedef struct { |
|---|
| 121 | int cacheid; |
|---|
| 122 | xc_hash_t *hcache; /* hash to cacheid */ |
|---|
| 123 | |
|---|
| 124 | time_t compiling; |
|---|
| 125 | zend_ulong misses; |
|---|
| 126 | zend_ulong hits; |
|---|
| 127 | zend_ulong clogs; |
|---|
| 128 | zend_ulong ooms; |
|---|
| 129 | xc_lock_t *lck; |
|---|
| 130 | xc_shm_t *shm; /* to which shm contains us */ |
|---|
| 131 | xc_mem_t *mem; /* to which mem contains us */ |
|---|
| 132 | |
|---|
| 133 | xc_entry_t **entries; |
|---|
| 134 | int entries_count; |
|---|
| 135 | xc_entry_t *deletes; |
|---|
| 136 | int deletes_count; |
|---|
| 137 | xc_hash_t *hentry; /* hash to entry */ |
|---|
| 138 | } xc_cache_t; |
|---|
| 139 | /* }}} */ |
|---|
| 140 | /* {{{ xc_classinfo_t */ |
|---|
| 141 | typedef struct { |
|---|
| 142 | #ifdef IS_UNICODE |
|---|
| 143 | zend_uchar type; |
|---|
| 144 | #endif |
|---|
| 145 | char *key; |
|---|
| 146 | zend_uint key_size; |
|---|
| 147 | xc_cest_t cest; |
|---|
| 148 | } xc_classinfo_t; |
|---|
| 149 | /* }}} */ |
|---|
| 150 | /* {{{ xc_funcinfo_t */ |
|---|
| 151 | typedef struct { |
|---|
| 152 | #ifdef IS_UNICODE |
|---|
| 153 | zend_uchar type; |
|---|
| 154 | #endif |
|---|
| 155 | char *key; |
|---|
| 156 | zend_uint key_size; |
|---|
| 157 | zend_function func; |
|---|
| 158 | } xc_funcinfo_t; |
|---|
| 159 | /* }}} */ |
|---|
| 160 | typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t; |
|---|
| 161 | /* {{{ xc_entry_data_php_t */ |
|---|
| 162 | typedef struct { |
|---|
| 163 | size_t sourcesize; |
|---|
| 164 | #ifdef HAVE_INODE |
|---|
| 165 | int device; /* the filesystem device */ |
|---|
| 166 | int inode; /* the filesystem inode */ |
|---|
| 167 | #endif |
|---|
| 168 | time_t mtime; /* the mtime of origin source file */ |
|---|
| 169 | |
|---|
| 170 | zend_op_array *op_array; |
|---|
| 171 | |
|---|
| 172 | zend_uint funcinfo_cnt; |
|---|
| 173 | xc_funcinfo_t *funcinfos; |
|---|
| 174 | |
|---|
| 175 | zend_uint classinfo_cnt; |
|---|
| 176 | xc_classinfo_t *classinfos; |
|---|
| 177 | } xc_entry_data_php_t; |
|---|
| 178 | /* }}} */ |
|---|
| 179 | /* {{{ xc_entry_data_var_t */ |
|---|
| 180 | typedef struct { |
|---|
| 181 | zval *value; |
|---|
| 182 | time_t etime; |
|---|
| 183 | } xc_entry_data_var_t; |
|---|
| 184 | /* }}} */ |
|---|
| 185 | typedef zvalue_value xc_entry_name_t; |
|---|
| 186 | /* {{{ xc_entry_t */ |
|---|
| 187 | struct _xc_entry_t { |
|---|
| 188 | xc_entry_type_t type; |
|---|
| 189 | xc_hash_value_t hvalue; |
|---|
| 190 | xc_entry_t *next; |
|---|
| 191 | xc_cache_t *cache; /* which cache it's on */ |
|---|
| 192 | |
|---|
| 193 | size_t size; |
|---|
| 194 | zend_ulong refcount; |
|---|
| 195 | zend_ulong hits; |
|---|
| 196 | time_t ctime; /* the ctime of this entry */ |
|---|
| 197 | time_t atime; /* the atime of this entry */ |
|---|
| 198 | time_t dtime; /* the deletion time of this entry */ |
|---|
| 199 | |
|---|
| 200 | #ifdef IS_UNICODE |
|---|
| 201 | zend_uchar name_type; |
|---|
| 202 | #endif |
|---|
| 203 | xc_entry_name_t name; |
|---|
| 204 | |
|---|
| 205 | union { |
|---|
| 206 | xc_entry_data_php_t *php; |
|---|
| 207 | xc_entry_data_var_t *var; |
|---|
| 208 | } data; |
|---|
| 209 | }; |
|---|
| 210 | /* }}} */ |
|---|
| 211 | |
|---|
| 212 | extern zend_module_entry xcache_module_entry; |
|---|
| 213 | #define phpext_xcache_ptr &xcache_module_entry |
|---|
| 214 | |
|---|
| 215 | int xc_is_rw(const void *p); |
|---|
| 216 | int xc_is_ro(const void *p); |
|---|
| 217 | int xc_is_shm(const void *p); |
|---|
| 218 | |
|---|
| 219 | #endif /* __XCACHE_H */ |
|---|