Ticket #287: xcache_vhost.patch
| File xcache_vhost.patch, 11.2 KB (added by mzhg, 9 months ago) |
|---|
-
mod_cacher/xc_cacher.c
28 28 #endif 29 29 #include "ext/standard/php_math.h" 30 30 #include "SAPI.h" 31 #include <pwd.h> 31 32 32 33 #define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0]))) 33 34 #define ECALLOC_ONE(x) ECALLOC_N(x, 1) … … 144 145 145 146 static zend_bool xc_readonly_protection = 0; 146 147 148 static zend_ulong xc_var_prefix_mode = 0; 149 static char *xc_var_prefix_value = NULL; 150 static zval *xc_var_prefix_computed = NULL; 151 152 147 153 zend_bool xc_have_op_array_ctor = 0; 148 154 /* }}} */ 149 155 … … 151 157 152 158 /* any function in *_unlocked is only safe be called within locked (single thread access) area */ 153 159 160 161 static int hg_internal_var_prefix_startwith(zval** name) 162 { 163 char* from = NULL; 164 char* prefix = NULL; 165 166 #ifdef IS_UNICODE 167 switch (xc_var_prefix_computed->type) { 168 case IS_UNICODE: 169 prefix = Z_UNIVAL_P(xc_var_prefix_computed); 170 break; 171 case IS_STRING: 172 prefix = Z_STRVAL_P(xc_var_prefix_computed); 173 break; 174 default: 175 assert(0); 176 } 177 switch (name->type) { 178 case IS_UNICODE: 179 from = Z_UNIVAL_PP(name); 180 break; 181 case IS_STRING: 182 from = Z_STRVAL_PP(name); 183 break; 184 default: 185 assert(0); 186 } 187 #else 188 prefix = Z_STRVAL_P(xc_var_prefix_computed); 189 from = Z_STRVAL_PP(name); 190 #endif 191 if (strncmp(from, prefix, strlen(prefix)) == 0) 192 { 193 return 1; 194 } else { 195 return 0; 196 } 197 } 198 199 static void hg_internal_var_prefix_remove(zval** name) 200 { 201 char* from = NULL; 202 char* prefix = NULL; 203 int index = 0; 204 205 #ifdef IS_UNICODE 206 switch (xc_var_prefix_computed->type) { 207 case IS_UNICODE: 208 prefix = Z_UNIVAL_P(xc_var_prefix_computed); 209 break; 210 case IS_STRING: 211 prefix = Z_STRVAL_P(xc_var_prefix_computed); 212 break; 213 default: 214 assert(0); 215 } 216 switch (name->type) { 217 case IS_UNICODE: 218 from = Z_UNIVAL_PP(name); 219 break; 220 case IS_STRING: 221 from = Z_STRVAL_PP(name); 222 break; 223 default: 224 assert(0); 225 } 226 #else 227 prefix = Z_STRVAL_P(xc_var_prefix_computed); 228 from = Z_STRVAL_PP(name); 229 #endif 230 index = strlen(prefix); 231 232 #ifdef IS_UNICODE 233 switch (name->type) { 234 case IS_UNICODE: 235 ZVAL_UNICODEL(*name, from + index, strlen(from) - index, 1); 236 break; 237 case IS_STRING: 238 ZVAL_STRINGL(*name, from + index, strlen(from) - index, 1); 239 break; 240 default: 241 assert(0); 242 } 243 #else 244 ZVAL_STRINGL(*name, from + index, strlen(from) - index, 1); 245 #endif 246 /* * 247 #ifdef IS_UNICODE 248 php_printf("unicode prefix remove, name=%s<br>", Z_UNIVAL_PP(name)); 249 #else 250 php_printf("string prefix remove, name=%s<br>", Z_STRVAL_PP(name)); 251 #endif 252 // */ 253 } 254 255 static char* hg_internal_var_prefix_global_server_array(char* key) 256 { 257 // This code makes sure $_SERVER has been initialized 258 if (!zend_hash_exists(&EG(symbol_table), "_SERVER", 8)) { 259 zend_auto_global* auto_global; 260 if (zend_hash_find(CG(auto_globals), "_SERVER", 8, (void **)&auto_global) != FAILURE) { 261 auto_global->armed = auto_global->auto_global_callback(auto_global->name, auto_global->name_len TSRMLS_CC); 262 } 263 } 264 // This fetches $_SERVER['key'] 265 zval** arr; 266 if (zend_hash_find(&EG(symbol_table), "_SERVER", 8, (void**)&arr) != FAILURE) { 267 HashTable* ht = Z_ARRVAL_P(*arr); 268 zval** val; 269 if (zend_hash_find(ht, key, strlen(key)+1, (void**)&val) != FAILURE) { 270 return Z_STRVAL_PP(val); 271 } 272 } 273 return ""; 274 } 275 276 static void hg_internal_var_prefix_compute() 277 { 278 xc_var_prefix_computed = NULL; 279 int id = -1; 280 281 MAKE_STD_ZVAL(xc_var_prefix_computed); 282 283 switch(xc_var_prefix_mode) { 284 case 1: 285 if (strncmp(xc_var_prefix_value, "uid", 3) == 0) { 286 id = getuid(); 287 } else if (strncmp(xc_var_prefix_value, "gid", 3) == 0) { 288 id = getgid(); 289 } 290 if (id == -1){ 291 ZVAL_EMPTY_STRING(xc_var_prefix_computed); 292 // assert bad configuration ? 293 } else { 294 Z_TYPE_P(xc_var_prefix_computed) = IS_LONG; 295 Z_LVAL_P(xc_var_prefix_computed) = id; 296 #ifdef IS_UNICODE 297 convert_to_unicode(xc_var_prefix_computed); 298 #else 299 convert_to_string(xc_var_prefix_computed); 300 #endif 301 } 302 break; 303 case 2: 304 #ifdef IS_UNICODE 305 ZVAL_UNICODE(xc_var_prefix_computed, hg_internal_var_prefix_global_server_array(xc_var_prefix_value), 1); 306 #else 307 ZVAL_STRING(xc_var_prefix_computed, hg_internal_var_prefix_global_server_array(xc_var_prefix_value), 1); 308 #endif 309 break; 310 case 3: 311 #ifdef IS_UNICODE 312 ZVAL_UNICODE(xc_var_prefix_computed, xc_var_prefix_value, 1); 313 #else 314 ZVAL_STRING(xc_var_prefix_computed, xc_var_prefix_value, 1); 315 #endif 316 break; 317 case 0: 318 default: 319 ZVAL_EMPTY_STRING(xc_var_prefix_computed); 320 } 321 } 322 154 323 static void xc_php_add_unlocked(xc_cached_t *cached, xc_entry_data_php_t *php) /* {{{ */ 155 324 { 156 325 xc_entry_data_php_t **head = &(cached->phps[php->hvalue]); … … 272 441 static inline int xc_entry_has_prefix_unlocked(xc_entry_type_t type, xc_entry_t *entry, zval *prefix) /* {{{ */ 273 442 { 274 443 /* this function isn't required but can be in unlocked */ 444 zval* prefixprefix = NULL; 445 MAKE_STD_VAL(prefixprefix); 275 446 276 447 #ifdef IS_UNICODE 277 448 if (entry->name_type != prefix->type) { 278 449 return 0; 279 450 } 280 451 452 concat_function(prefixprefix, xc_var_prefix_computed, prefix); 453 281 454 if (entry->name_type == IS_UNICODE) { 282 if (entry->name.ustr.len < Z_USTRLEN_P(prefix )) {455 if (entry->name.ustr.len < Z_USTRLEN_P(prefixprefix)) { 283 456 return 0; 284 457 } 285 return memcmp(entry->name.ustr.val, Z_USTRVAL_P(prefix ), Z_USTRLEN_P(prefix) * sizeof(UChar)) == 0;458 return memcmp(entry->name.ustr.val, Z_USTRVAL_P(prefixprefix), Z_USTRLEN_P(prefixprefix) * sizeof(UChar)) == 0; 286 459 } 287 #e ndif460 #else 288 461 if (prefix->type != IS_STRING) { 289 462 return 0; 290 463 } 291 464 292 if (entry->name.str.len < Z_STRLEN_P(prefix)) { 465 concat_function(prefixprefix, xc_var_prefix_computed, prefix); 466 467 if (entry->name.str.len < Z_STRLEN_P(prefixprefix)) { 293 468 return 0; 294 469 } 295 470 296 return memcmp(entry->name.str.val, Z_STRVAL_P(prefix), Z_STRLEN_P(prefix)) == 0; 471 return memcmp(entry->name.str.val, Z_STRVAL_P(prefixprefix), Z_STRLEN_P(prefixprefix)) == 0; 472 #endif 297 473 } 298 474 /* }}} */ 299 475 static void xc_entry_add_unlocked(xc_cached_t *cached, xc_hash_value_t entryslotid, xc_entry_t *entry) /* {{{ */ … … 697 873 if (del) { 698 874 add_assoc_long_ex(ei, ZEND_STRS("dtime"), entry->dtime); 699 875 } 876 877 zval *zv; 878 ALLOC_INIT_ZVAL(zv); 700 879 #ifdef IS_UNICODE 701 880 do { 702 zval *zv;703 ALLOC_INIT_ZVAL(zv);704 881 switch (entry->name_type) { 705 882 case IS_UNICODE: 706 883 ZVAL_UNICODEL(zv, entry->name.ustr.val, entry->name.ustr.len, 1); … … 715 892 add_assoc_zval_ex(ei, ZEND_STRS("name"), zv); 716 893 } while (0); 717 894 #else 718 add_assoc_stringl_ex(ei, ZEND_STRS("name"), entry->name.str.val, entry->name.str.len, 1); 895 ZVAL_STRINGL(zv, entry->name.str.val, entry->name.str.len, 1); 896 // add_assoc_stringl_ex(ei, ZEND_STRS("name"), entry->name.str.val, entry->name.str.len, 1); 719 897 #endif 898 if (xc_var_prefix_mode > 0) { 899 if (hg_internal_var_prefix_startwith(&zv) == 0) return; 900 hg_internal_var_prefix_remove(&zv); 901 } 902 add_assoc_zval_ex(ei, ZEND_STRS("name"), zv); 903 720 904 switch (type) { 721 905 case XC_TYPE_PHP: { 722 906 xc_entry_php_t *entry_php = (xc_entry_php_t *) entry; … … 2501 2685 xc_stack_init(&XG(var_holds[i])); 2502 2686 } 2503 2687 } 2504 2688 hg_internal_var_prefix_compute(); 2505 2689 #ifdef ZEND_ENGINE_2 2506 2690 zend_llist_init(&XG(gc_op_arrays), sizeof(xc_gc_op_array_t), xc_gc_op_array, 0); 2507 2691 #endif … … 2519 2703 xc_gc_expires_php(TSRMLS_C); 2520 2704 xc_gc_expires_var(TSRMLS_C); 2521 2705 xc_gc_deletes(TSRMLS_C); 2706 ZVAL_EMPTY_STRING(xc_var_prefix_computed); 2522 2707 #ifdef ZEND_ENGINE_2 2523 2708 zend_llist_destroy(&XG(gc_op_arrays)); 2524 2709 #endif … … 2806 2991 static int xc_entry_var_init_key(xc_entry_var_t *entry_var, xc_entry_hash_t *entry_hash, zval *name TSRMLS_DC) /* {{{ */ 2807 2992 { 2808 2993 xc_hash_value_t hv; 2994 zval *new_name = NULL; 2809 2995 2810 2996 switch (name->type) { 2811 2997 #ifdef IS_UNICODE … … 2823 3009 #ifdef IS_UNICODE 2824 3010 entry_var->name_type = name->type; 2825 3011 #endif 2826 entry_var->entry.name = name->value; 3012 if (xc_var_prefix_mode>0) { 3013 MAKE_STD_ZVAL(new_name); 3014 #ifdef IS_UNICODE 3015 switch (name->type) { 3016 case IS_UNICODE: 3017 if (name->type != xc_var_prefix_computed->type) convert_to_unicode(xc_var_prefix_computed); 3018 case IS_STRING: 3019 if (name->type != xc_var_prefix_computed->type) convert_to_string(xc_var_prefix_computed); 3020 } 3021 #endif 3022 // do not concat into name directly, it update the variable php side too, the prefix goes back up to the client 3023 concat_function(new_name, xc_var_prefix_computed, name); 3024 // we change the entry name with the prefix, but let the real name zval untouch 3025 entry_var->entry.name = new_name->value; 3026 } else { 3027 entry_var->entry.name = name->value; 3028 } 2827 3029 2828 3030 hv = xc_entry_hash_var((xc_entry_t *) entry_var TSRMLS_CC); 2829 3031 … … 3220 3422 PHP_INI_ENTRY1 ("xcache.var_gc_interval", "120", PHP_INI_SYSTEM, xcache_OnUpdateULong, &xc_var_gc_interval) 3221 3423 PHP_INI_ENTRY1 ("xcache.var_allocator", "bestfit", PHP_INI_SYSTEM, xcache_OnUpdateString, &xc_var_allocator) 3222 3424 STD_PHP_INI_ENTRY ("xcache.var_ttl", "0", PHP_INI_ALL, OnUpdateLong, var_ttl, zend_xcache_globals, xcache_globals) 3425 PHP_INI_ENTRY1 ("xcache.var_prefix_mode", "0", PHP_INI_SYSTEM, xcache_OnUpdateULong, &xc_var_prefix_mode) 3426 PHP_INI_ENTRY1 ("xcache.var_prefix_value", "", PHP_INI_SYSTEM, xcache_OnUpdateString, &xc_var_prefix_value) 3223 3427 PHP_INI_END() 3224 3428 /* }}} */ 3225 3429 static PHP_MINFO_FUNCTION(xcache_cacher) /* {{{ */ … … 3394 3598 pefree(xc_var_allocator, 1); 3395 3599 xc_var_allocator = NULL; 3396 3600 } 3601 if (xc_var_prefix_value) { 3602 pefree(xc_var_prefix_value, 1); 3603 xc_var_prefix_value = NULL; 3604 } 3397 3605 3398 3606 return SUCCESS; 3399 3607 } -
htdocs/cacher/sub/entrylist.tpl.php
140 140 } 141 141 ?> 142 142 </table> 143 <?php if (!$isphp && $listName == 'Deleted') { ?>143 <?php if (!$isphp) { ?> 144 144 <input type="submit" value="<?php echo _T("Remove Selected"); ?>"> 145 145 <?php } ?> 146 146 </form> -
htdocs/cacher/edit.php
22 22 exit; 23 23 } 24 24 $value = xcache_get($name); 25 if (!empty($ enable['enable_eval'])) {25 if (!empty($config['enable_eval'])) { 26 26 $value = var_export($value, true); 27 27 $editable = true; 28 28 }

