Changeset 1140 for trunk/mod_cacher/xc_cacher.c
- Timestamp:
- 2012-08-09T16:36:06+02:00 (10 months ago)
- File:
-
- 1 edited
-
trunk/mod_cacher/xc_cacher.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/mod_cacher/xc_cacher.c
r1135 r1140 243 243 } 244 244 245 assert( IS_ABSOLUTE_PATH(entry1->name.str.val, entry1->name.str.len));246 assert( IS_ABSOLUTE_PATH(entry2->name.str.val, entry2->name.str.len));245 assert(strstr(entry1->name.str.val, "://") != NULL || IS_ABSOLUTE_PATH(entry1->name.str.val, entry1->name.str.len)); 246 assert(strstr(entry1->name.str.val, "://") != NULL || IS_ABSOLUTE_PATH(entry2->name.str.val, entry2->name.str.len)); 247 247 248 248 return entry1->name.str.len == entry2->name.str.len … … 947 947 /* }}} */ 948 948 949 #define XC_RESOLVE_PATH_CHECKER(name) zend_boolname(const char *filepath, size_t filepath_len, void *data TSRMLS_DC)949 #define XC_RESOLVE_PATH_CHECKER(name) int name(const char *filepath, size_t filepath_len, void *data TSRMLS_DC) 950 950 typedef XC_RESOLVE_PATH_CHECKER((*xc_resolve_path_checker_func_t)); 951 static zend_boolxc_resolve_path(const char *filepath, char *path_buffer, xc_resolve_path_checker_func_t checker_func, void *data TSRMLS_DC) /* {{{ */951 static int xc_resolve_path(const char *filepath, char *path_buffer, xc_resolve_path_checker_func_t checker_func, void *data TSRMLS_DC) /* {{{ */ 952 952 { 953 953 char *paths, *path; … … 967 967 !*path) { 968 968 969 if (checker_func(path_buffer, path_buffer_len, data TSRMLS_CC)) { 970 ret = 1; 971 } 972 else { 973 ret = FAILURE; 974 } 969 ret = checker_func(path_buffer, path_buffer_len, data TSRMLS_CC); 975 970 goto finish; 976 971 } … … 984 979 path_buffer_len = snprintf(path_buffer, MAXPATHLEN, "%s/%s", path, filepath); 985 980 if (path_buffer_len < MAXPATHLEN - 1) { 986 if (checker_func(path_buffer, path_buffer_len, data TSRMLS_CC)) {987 ret = 1;981 ret = checker_func(path_buffer, path_buffer_len, data TSRMLS_CC); 982 if (ret == SUCCESS) { 988 983 goto finish; 989 984 } … … 993 988 /* fall back to current directory */ 994 989 if (zend_is_executing(TSRMLS_C)) { 995 const char *executed_filename = zend_get_executed_filename(TSRMLS_C); 996 if (executed_filename && executed_filename[0] && executed_filename[0] != '[') { 997 size_t filename_len = strlen(filepath); 998 size_t dirname_len; 999 1000 for (dirname_len = strlen(executed_filename) - 1; dirname_len > 0; --dirname_len) { 1001 if (IS_SLASH(executed_filename[dirname_len])) { 1002 if (dirname_len + filename_len < MAXPATHLEN - 1) { 1003 ++dirname_len; /* include tailing slash */ 1004 memcpy(path_buffer, executed_filename, dirname_len); 1005 memcpy(path_buffer + dirname_len, filepath, filename_len); 1006 path_buffer_len = dirname_len + filename_len; 1007 path_buffer[path_buffer_len] = '\0'; 1008 if (checker_func(path_buffer, path_buffer_len, data TSRMLS_CC)) { 1009 ret = 1; 1010 goto finish; 1011 } 1012 } 1013 break; 1014 } 1015 } 1016 } 1017 } 1018 1019 ret = 0; 990 const char *executing_filename = zend_get_executed_filename(TSRMLS_C); 991 int dirname_len = strlen(executing_filename); 992 size_t filename_len = strlen(filepath); 993 994 while ((--dirname_len >= 0) && !IS_SLASH(executing_filename[dirname_len])); 995 if (executing_filename && dirname_len > 0 && executing_filename[0] && executing_filename[0] != '[' 996 && dirname_len + 1 + filename_len + 1 < MAXPATHLEN) { 997 memcpy(path_buffer, executing_filename, dirname_len + 1); 998 memcpy(path_buffer + dirname_len + 1, filepath, filename_len + 1); 999 path_buffer_len = dirname_len + 1 + filename_len; 1000 ret = checker_func(path_buffer, path_buffer_len, data TSRMLS_CC); 1001 if (ret == SUCCESS) { 1002 goto finish; 1003 } 1004 } 1005 } 1006 1007 ret = FAILURE; 1020 1008 1021 1009 finish: … … 1025 1013 } 1026 1014 /* }}} */ 1015 1016 static zend_bool xc_is_absolute(const char *filepath, size_t filepath_len) /* {{{ */ 1017 { 1018 const char *p; 1019 1020 if (IS_ABSOLUTE_PATH(filepath, filepath_len)) { 1021 return 1; 1022 } 1023 1024 for (p = filepath; isalnum((int)*p) || *p == '+' || *p == '-' || *p == '.'; p++); 1025 if ((*p == ':') && (p - filepath > 1) && (p[1] == '/') && (p[2] == '/')) { 1026 return 1; 1027 } 1028 1029 return 0; 1030 } 1031 /* }}} */ 1032 static int xc_stat(const char *filepath, struct stat *statbuf TSRMLS_DC) /* {{{ */ 1033 { 1034 if (strstr(filepath, "://") != NULL) { 1035 php_stream_statbuf ssb; 1036 php_stream_wrapper *wrapper = NULL; 1037 char *path_for_open = NULL; 1038 1039 wrapper = php_stream_locate_url_wrapper(filepath, &path_for_open, 0 TSRMLS_CC); 1040 if (wrapper && wrapper->wops->url_stat 1041 && wrapper != &php_plain_files_wrapper 1042 && wrapper->wops->url_stat(wrapper, path_for_open, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL TSRMLS_CC) == SUCCESS) { 1043 *statbuf = ssb.sb; 1044 return SUCCESS; 1045 } 1046 1047 return FAILURE; 1048 } 1049 1050 return VCWD_STAT(filepath, statbuf); 1051 } 1052 /* }}} */ 1053 static XC_RESOLVE_PATH_CHECKER(xc_resolve_path_stat_checker) /* {{{ */ 1054 { 1055 return xc_stat(filepath, (struct stat *) data TSRMLS_CC); 1056 } 1057 /* }}} */ 1027 1058 #ifndef ZEND_ENGINE_2_3 1028 static XC_RESOLVE_PATH_CHECKER(xc_stat_file) /* {{{ */1029 {1030 return VCWD_STAT(filepath, (struct stat *) data) == 0 ? 1 : 0;1031 }1032 /* }}} */1033 1059 static int xc_resolve_path_stat(const char *filepath, char *path_buffer, struct stat *pbuf TSRMLS_DC) /* {{{ */ 1034 1060 { 1035 return xc_resolve_path(filepath, path_buffer, xc_stat_file, (void *) pbuf TSRMLS_CC) 1036 ? SUCCESS 1037 : FAILURE; 1061 return xc_resolve_path(filepath, path_buffer, xc_resolve_path_stat_checker, (void *) pbuf TSRMLS_CC); 1038 1062 } 1039 1063 /* }}} */ … … 1051 1075 } xc_compiler_t; 1052 1076 /* }}} */ 1053 typedef struct xc_ entry_resolve_path_data_t { /* {{{ */1077 typedef struct xc_resolve_path_entry_checker_t { /* {{{ */ 1054 1078 xc_compiler_t *compiler; 1055 1079 xc_entry_php_t **stored_entry; 1056 } xc_ entry_resolve_path_data_t;1057 /* }}} */ 1058 static XC_RESOLVE_PATH_CHECKER(xc_ entry_resolve_path_func_unlocked) /* {{{ */1059 { 1060 xc_ entry_resolve_path_data_t *entry_resolve_path_data = (xc_entry_resolve_path_data_t *) data;1061 xc_compiler_t *compiler = entry_ resolve_path_data->compiler;1080 } xc_resolve_path_entry_checker_data_t; 1081 /* }}} */ 1082 static XC_RESOLVE_PATH_CHECKER(xc_resolve_path_entry_checker) /* {{{ */ 1083 { 1084 xc_resolve_path_entry_checker_data_t *entry_checker_data = (xc_resolve_path_entry_checker_data_t *) data; 1085 xc_compiler_t *compiler = entry_checker_data->compiler; 1062 1086 1063 1087 compiler->new_entry.entry.name.str.val = xc_expand_url(filepath, compiler->opened_path_buffer TSRMLS_CC); 1064 1088 compiler->new_entry.entry.name.str.len = strlen(compiler->new_entry.entry.name.str.val); 1065 1089 1066 *entry_ resolve_path_data->stored_entry = (xc_entry_php_t *) xc_entry_find_unlocked(1090 *entry_checker_data->stored_entry = (xc_entry_php_t *) xc_entry_find_unlocked( 1067 1091 XC_TYPE_PHP 1068 1092 , &xc_php_caches[compiler->entry_hash.cacheid] … … 1071 1095 TSRMLS_CC); 1072 1096 1073 return *entry_ resolve_path_data->stored_entry ? 1 : 0;1074 } 1075 /* }}} */ 1076 static int xc_ entry_resolve_path_unlocked(xc_compiler_t *compiler, const char *filepath, xc_entry_php_t **stored_entry TSRMLS_DC) /* {{{ */1097 return *entry_checker_data->stored_entry ? SUCCESS : FAILURE; 1098 } 1099 /* }}} */ 1100 static int xc_resolve_path_check_entry_unlocked(xc_compiler_t *compiler, const char *filepath, xc_entry_php_t **stored_entry TSRMLS_DC) /* {{{ */ 1077 1101 { 1078 1102 char path_buffer[MAXPATHLEN]; 1079 xc_entry_resolve_path_data_t entry_resolve_path_data; 1080 entry_resolve_path_data.compiler = compiler; 1081 entry_resolve_path_data.stored_entry = stored_entry; 1082 1083 return xc_resolve_path(filepath, path_buffer, xc_entry_resolve_path_func_unlocked, (void *) &entry_resolve_path_data TSRMLS_CC) 1084 ? SUCCESS 1085 : FAILURE; 1103 xc_resolve_path_entry_checker_data_t entry_checker_data; 1104 entry_checker_data.compiler = compiler; 1105 entry_checker_data.stored_entry = stored_entry; 1106 1107 return xc_resolve_path(filepath, path_buffer, xc_resolve_path_entry_checker, (void *) &entry_checker_data TSRMLS_CC); 1086 1108 } 1087 1109 /* }}} */ … … 1104 1126 1105 1127 /* absolute path */ 1106 if ( IS_ABSOLUTE_PATH(compiler->filename, strlen(compiler->filename))) {1107 if (statbuf && VCWD_STAT(compiler->filename, statbuf) != 0) {1128 if (xc_is_absolute(compiler->filename, strlen(compiler->filename))) { 1129 if (statbuf && xc_stat(compiler->filename, statbuf TSRMLS_CC) != SUCCESS) { 1108 1130 return FAILURE; 1109 1131 } … … 1147 1169 efree(opened_path); 1148 1170 compiler->opened_path = compiler->opened_path_buffer; 1149 if (!statbuf || VCWD_STAT(compiler->opened_path, statbuf) == 0) {1171 if (!statbuf || xc_stat(compiler->opened_path, statbuf TSRMLS_CC) == SUCCESS) { 1150 1172 return SUCCESS; 1151 1173 } … … 1169 1191 1170 1192 if (compiler->opened_path) { 1171 if ( VCWD_STAT(compiler->opened_path, &buf) != 0) {1193 if (xc_stat(compiler->opened_path, &buf TSRMLS_CC) != SUCCESS) { 1172 1194 return FAILURE; 1173 1195 } … … 2075 2097 2076 2098 ENTER_LOCK_EX(cache) { 2077 if (!compiler->opened_path && xc_ entry_resolve_path_unlocked(compiler, compiler->filename, &stored_entry TSRMLS_CC) == SUCCESS) {2099 if (!compiler->opened_path && xc_resolve_path_check_entry_unlocked(compiler, compiler->filename, &stored_entry TSRMLS_CC) == SUCCESS) { 2078 2100 compiler->opened_path = compiler->new_entry.entry.name.str.val; 2079 2101 } … … 2178 2200 || !h->filename 2179 2201 || !SG(request_info).path_translated 2180 || strstr(h->filename, "://") != NULL 2181 #ifdef ZEND_ENGINE_2_3 2182 /* supported by php_resolve_path */ 2183 || (!XG(stat) && strstr(PG(include_path), "://") != NULL) 2184 #else 2185 || strstr(PG(include_path), "://") != NULL 2186 #endif 2187 ) { 2202 2203 ) { 2188 2204 TRACE("%s", "cacher not enabled"); 2189 2205 return old_compile_file(h, type TSRMLS_CC);
Note: See TracChangeset
for help on using the changeset viewer.

