Ticket #287: xcache-itk_vhost.patch
| File xcache-itk_vhost.patch, 6.0 KB (added by mzhg, 9 months ago) |
|---|
-
xcache-trunk/xcache.c
14 14 15 15 #include <signal.h> 16 16 17 #include <pwd.h> 18 17 19 #include "php.h" 18 20 #include "ext/standard/info.h" 19 21 #include "ext/standard/md5.h" … … 118 120 119 121 /* any function in *_unlocked is only safe be called within locked (single thread access) area */ 120 122 123 static zval* hg_internal_compute_prefix() 124 { 125 zval* zprefix = NULL; 126 int userid = 33; // default id for www-data on Ubuntu 127 // we base the prefix on the user id because we use mpm-itk which run each virtual host under a specific user 128 // the prefix could be set via the INI settings 129 userid = getuid(); 130 MAKE_STD_ZVAL(zprefix); 131 Z_TYPE_P(zprefix) = IS_LONG; 132 Z_LVAL_P(zprefix) = userid; 133 convert_to_string(zprefix); 134 return zprefix; 135 } 136 137 static int hg_internal_startwith_prefix(zval** name) 138 { 139 char* from = NULL; 140 char* prefix = NULL; 141 142 zval* zprefix = hg_internal_compute_prefix(); 143 prefix = Z_STRVAL_P(zprefix); 144 from = Z_STRVAL_PP(name); 145 146 // php_printf("from= %s<br />", from); 147 // php_printf("prefix= %s<br />", prefix); 148 149 if (strncmp(from, prefix, strlen(prefix)) == 0) 150 { 151 // php_printf("MATCH<br />"); 152 return 1; 153 } else { 154 return 0; 155 } 156 } 157 158 static void hg_internal_remove_prefix(zval** name) 159 { 160 char* from = NULL; 161 char* to = NULL; 162 char* prefix = NULL; 163 int index = 0; 164 165 zval* zprefix = hg_internal_compute_prefix(); 166 prefix = Z_STRVAL_P(zprefix); 167 168 from = Z_STRVAL_PP(name); 169 index = strlen(prefix) + 1; 170 171 to = emalloc(strlen(from) - index + 2); 172 strncpy(to, from + index, strlen(from) - index + 1); 173 174 ZVAL_STRING(*name, to, 1); 175 } 176 177 static void hg_internal_prefix_entry_name(zval** name) 178 { 179 char *string = NULL; 180 char *final = NULL; 181 char *prefix = NULL; 182 183 zval* zprefix = hg_internal_compute_prefix(); // get prefix, should be cache in some way 184 prefix = Z_STRVAL_P(zprefix); 185 186 convert_to_string(*name); 187 188 // php_printf("<br />zname original= "); 189 // PHPWRITE(Z_STRVAL_PP(name), Z_STRLEN_PP(name)); 190 191 string = Z_STRVAL_PP(name); 192 193 // php_printf("<br />zprefix= "); 194 // PHPWRITE(Z_STRVAL_P(zprefix), Z_STRLEN_P(zprefix)); 195 196 final = emalloc(strlen(prefix) + strlen(string) + 2); 197 snprintf(final, (strlen(prefix) + strlen(string) + 2), "%s_%s", prefix, string); 198 // php_printf("<br />final= %s", final); 199 200 ZVAL_STRING(*name, final, 1); 201 202 // php_printf("<br />zname= "); 203 // PHPWRITE(Z_STRVAL_PP(name), Z_STRLEN_PP(name)); 204 // php_printf("<br />"); 205 } 206 121 207 static void xc_php_add_unlocked(xc_cache_t *cache, xc_entry_data_php_t *php) /* {{{ */ 122 208 { 123 209 xc_entry_data_php_t **head = &(cache->phps[php->hvalue]); … … 663 749 if (del) { 664 750 add_assoc_long_ex(ei, ZEND_STRS("dtime"), entry->dtime); 665 751 } 752 zval *zv; 753 ALLOC_INIT_ZVAL(zv); 666 754 #ifdef IS_UNICODE 667 755 do { 668 zval *zv;669 ALLOC_INIT_ZVAL(zv);756 // zval *zv; 757 // ALLOC_INIT_ZVAL(zv); 670 758 switch (entry->name_type) { 671 759 case IS_UNICODE: 672 760 ZVAL_UNICODEL(zv, entry->name.ustr.val, entry->name.ustr.len, 1); … … 678 766 assert(0); 679 767 } 680 768 zv->type = entry->name_type; 681 add_assoc_zval_ex(ei, ZEND_STRS("name"), zv); 769 // hg_internal_remove_prefix(&zv); 770 // add_assoc_zval_ex(ei, ZEND_STRS("name"), zv); 682 771 } while (0); 683 772 #else 684 add_assoc_stringl_ex(ei, ZEND_STRS("name"), entry->name.str.val, entry->name.str.len, 1); 773 do { 774 // zval *zv; 775 // ALLOC_INIT_ZVAL(zv); 776 ZVAL_STRINGL(zv, entry->name.str.val, entry->name.str.len, 1); 777 // hg_internal_remove_prefix(&zv); 778 // add_assoc_stringl_ex(ei, ZEND_STRS("name"), entry->name.str.val, entry->name.str.len, 1); 779 // add_assoc_zval_ex(ei, ZEND_STRS("name"), zv); 780 } while (0); 685 781 #endif 782 int comp = hg_internal_startwith_prefix(&zv); 783 if (comp == 0) return; 784 785 hg_internal_remove_prefix(&zv); 786 add_assoc_zval_ex(ei, ZEND_STRS("name"), zv); 787 686 788 switch (type) { 687 789 case XC_TYPE_PHP: 688 790 php = entry_php->php; … … 2388 2490 CHECK(xc_var_caches = xc_cache_init(shm, &xc_var_hcache, &xc_var_hentry, NULL, xc_var_size), "failed init variable cache"); 2389 2491 } 2390 2492 } 2493 2391 2494 return SUCCESS; 2392 2495 2393 2496 err: … … 2798 2901 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { 2799 2902 return; 2800 2903 } 2904 2905 hg_internal_prefix_entry_name(&name); 2906 2801 2907 xc_entry_var_init_key(&entry_var, &entry_hash, name TSRMLS_CC); 2802 2908 cache = xc_var_caches[entry_hash.cacheid]; 2803 2909 … … 2835 2941 return; 2836 2942 } 2837 2943 2944 hg_internal_prefix_entry_name(&name); 2945 2838 2946 /* max ttl */ 2839 2947 if (xc_var_maxttl && (!entry_var.entry.ttl || entry_var.entry.ttl > xc_var_maxttl)) { 2840 2948 entry_var.entry.ttl = xc_var_maxttl; … … 2870 2978 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { 2871 2979 return; 2872 2980 } 2981 2982 hg_internal_prefix_entry_name(&name); 2983 2873 2984 xc_entry_var_init_key(&entry_var, &entry_hash, name TSRMLS_CC); 2874 2985 cache = xc_var_caches[entry_hash.cacheid]; 2875 2986 … … 2904 3015 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { 2905 3016 return; 2906 3017 } 3018 3019 hg_internal_prefix_entry_name(&name); 3020 2907 3021 xc_entry_var_init_key(&entry_var, &entry_hash, name TSRMLS_CC); 2908 3022 cache = xc_var_caches[entry_hash.cacheid]; 2909 3023 … … 2935 3049 return; 2936 3050 } 2937 3051 3052 hg_internal_prefix_entry_name(&prefix); 3053 2938 3054 for (i = 0, iend = xc_var_hcache.size; i < iend; i ++) { 2939 3055 xc_cache_t *cache = xc_var_caches[i]; 2940 3056 ENTER_LOCK(cache) { … … 2972 3088 return; 2973 3089 } 2974 3090 3091 hg_internal_prefix_entry_name(&name); 3092 2975 3093 /* max ttl */ 2976 3094 if (xc_var_maxttl && (!entry_var.entry.ttl || entry_var.entry.ttl > xc_var_maxttl)) { 2977 3095 entry_var.entry.ttl = xc_var_maxttl; -
xcache-trunk/xcache.h
1 1 #ifndef __XCACHE_H 2 2 #define __XCACHE_H 3 3 #define XCACHE_NAME "XCache" 4 #define XCACHE_VERSION "2.0.0 "4 #define XCACHE_VERSION "2.0.0+itk_vhost" 5 5 #define XCACHE_AUTHOR "mOo" 6 6 #define XCACHE_COPYRIGHT "Copyright (c) 2005-2012" 7 7 #define XCACHE_URL "http://xcache.lighttpd.net"

