comparison src/http/ngx_http_script.c @ 1454:f497ed7682a7

open_file_cache in HTTP
author Igor Sysoev <igor@sysoev.ru>
date Sat, 01 Sep 2007 12:12:48 +0000
parents 03341711f9a2
children 223e92651ca5
comparison
equal deleted inserted replaced
1453:f2feed5bffe1 1454:f497ed7682a7
950 950
951 951
952 void 952 void
953 ngx_http_script_file_code(ngx_http_script_engine_t *e) 953 ngx_http_script_file_code(ngx_http_script_engine_t *e)
954 { 954 {
955 ngx_err_t err; 955 ngx_str_t path;
956 ngx_file_info_t fi; 956 ngx_http_request_t *r;
957 ngx_open_file_info_t of;
958 ngx_http_core_loc_conf_t *clcf;
957 ngx_http_variable_value_t *value; 959 ngx_http_variable_value_t *value;
958 ngx_http_script_file_code_t *code; 960 ngx_http_script_file_code_t *code;
959 961
960 value = e->sp - 1; 962 value = e->sp - 1;
961 963
962 code = (ngx_http_script_file_code_t *) e->ip; 964 code = (ngx_http_script_file_code_t *) e->ip;
963 e->ip += sizeof(ngx_http_script_file_code_t); 965 e->ip += sizeof(ngx_http_script_file_code_t);
964 966
965 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, 967 path.len = value->len - 1;
966 "http script file op %p", code->op); 968 path.data = value->data;
967 969
968 if (ngx_file_info(value->data, &fi) == -1) { 970 r = e->request;
969 err = ngx_errno; 971
970 972 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
971 if (err != NGX_ENOENT && err != NGX_ENOTDIR) { 973 "http script file op %p \"%V\"", code->op, &path);
972 ngx_log_error(NGX_LOG_CRIT, e->request->connection->log, err, 974
975 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
976
977 of.test_dir = 0;
978 of.retest = clcf->open_file_cache_retest;
979 of.errors = clcf->open_file_cache_errors;
980
981 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
982 == NGX_ERROR)
983 {
984 if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) {
985 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
973 ngx_file_info_n " \"%s\" failed", value->data); 986 ngx_file_info_n " \"%s\" failed", value->data);
974 } 987 }
975 988
976 switch (code->op) { 989 switch (code->op) {
977 990
991 goto false; 1004 goto false;
992 } 1005 }
993 1006
994 switch (code->op) { 1007 switch (code->op) {
995 case ngx_http_script_file_plain: 1008 case ngx_http_script_file_plain:
996 if (ngx_is_file(&fi)) { 1009 if (of.is_file) {
997 goto true; 1010 goto true;
998 } 1011 }
999 goto false; 1012 goto false;
1000 1013
1001 case ngx_http_script_file_not_plain: 1014 case ngx_http_script_file_not_plain:
1002 if (ngx_is_file(&fi)) { 1015 if (of.is_file) {
1003 goto false; 1016 goto false;
1004 } 1017 }
1005 goto true; 1018 goto true;
1006 1019
1007 case ngx_http_script_file_dir: 1020 case ngx_http_script_file_dir:
1008 if (ngx_is_dir(&fi)) { 1021 if (of.is_dir) {
1009 goto true; 1022 goto true;
1010 } 1023 }
1011 goto false; 1024 goto false;
1012 1025
1013 case ngx_http_script_file_not_dir: 1026 case ngx_http_script_file_not_dir:
1014 if (ngx_is_dir(&fi)) { 1027 if (of.is_dir) {
1015 goto false; 1028 goto false;
1016 } 1029 }
1017 goto true; 1030 goto true;
1018 1031
1019 case ngx_http_script_file_exists: 1032 case ngx_http_script_file_exists:
1020 if (ngx_is_file(&fi) || ngx_is_dir(&fi) || ngx_is_link(&fi)) { 1033 if (of.is_file || of.is_dir || of.is_link) {
1021 goto true; 1034 goto true;
1022 } 1035 }
1023 goto false; 1036 goto false;
1024 1037
1025 case ngx_http_script_file_not_exists: 1038 case ngx_http_script_file_not_exists:
1026 if (ngx_is_file(&fi) || ngx_is_dir(&fi) || ngx_is_link(&fi)) { 1039 if (of.is_file || of.is_dir || of.is_link) {
1027 goto false; 1040 goto false;
1028 } 1041 }
1029 goto true; 1042 goto true;
1030 1043
1031 #if (NGX_WIN32)
1032
1033 case ngx_http_script_file_exec: 1044 case ngx_http_script_file_exec:
1045 if (of.is_exec) {
1046 goto true;
1047 }
1034 goto false; 1048 goto false;
1035 1049
1036 case ngx_http_script_file_not_exec: 1050 case ngx_http_script_file_not_exec:
1051 if (of.is_exec) {
1052 goto false;
1053 }
1037 goto true; 1054 goto true;
1038
1039 #else
1040
1041 case ngx_http_script_file_exec:
1042 if (ngx_is_exec(&fi)) {
1043 goto true;
1044 }
1045 goto false;
1046
1047 case ngx_http_script_file_not_exec:
1048 if (ngx_is_exec(&fi)) {
1049 goto false;
1050 }
1051 goto true;
1052
1053 #endif
1054 } 1055 }
1055 1056
1056 false: 1057 false:
1057 1058
1058 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0, 1059 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1059 "http script file op false"); 1060 "http script file op false");
1060 1061
1061 *value = ngx_http_variable_null_value; 1062 *value = ngx_http_variable_null_value;
1062 return; 1063 return;
1063 1064