Ticket #59: nginx-1.1.8-xslt-fix.patch
| File nginx-1.1.8-xslt-fix.patch, 7.0 KB (added by , 15 years ago) |
|---|
-
src/http/modules/ngx_http_xslt_filter_module.c
Only in nginx-1.1.8-new: .gdb_history Only in nginx-1.1.8-new: Makefile Only in nginx-1.1.8-new: objs diff -ur nginx-1.1.8/src/http/modules/ngx_http_xslt_filter_module.c nginx-1.1.8-new/src/http/modules/ngx_http_xslt_filter_module.c
old new 40 40 typedef struct { 41 41 xsltStylesheetPtr stylesheet; 42 42 ngx_array_t params; /* ngx_http_complex_value_t */ 43 ngx_str_t name; 43 44 } ngx_http_xslt_sheet_t; 44 45 45 46 … … 90 91 static void *ngx_http_xslt_filter_create_conf(ngx_conf_t *cf); 91 92 static char *ngx_http_xslt_filter_merge_conf(ngx_conf_t *cf, void *parent, 92 93 void *child); 94 static ngx_int_t ngx_http_xslt_filter_preinit(ngx_conf_t *cf); 93 95 static ngx_int_t ngx_http_xslt_filter_init(ngx_conf_t *cf); 94 96 static void ngx_http_xslt_filter_exit(ngx_cycle_t *cycle); 95 97 96 97 98 ngx_str_t ngx_http_xslt_default_types[] = { 98 99 ngx_string("text/xml"), 99 100 ngx_null_string … … 128 129 129 130 130 131 static ngx_http_module_t ngx_http_xslt_filter_module_ctx = { 131 NULL,/* preconfiguration */132 ngx_http_xslt_filter_preinit, /* preconfiguration */ 132 133 ngx_http_xslt_filter_init, /* postconfiguration */ 133 134 134 135 ngx_http_xslt_filter_create_main_conf, /* create main configuration */ … … 764 765 765 766 ngx_str_t *value; 766 767 ngx_uint_t i, n; 767 ngx_pool_cleanup_t *cln;768 ngx_http_xslt_file_t *file;769 768 ngx_http_xslt_sheet_t *sheet; 770 769 ngx_http_complex_value_t *param; 771 770 ngx_http_compile_complex_value_t ccv; 772 ngx_http_xslt_filter_main_conf_t *xmcf;773 771 774 772 value = cf->args->elts; 775 773 … … 789 787 790 788 ngx_memzero(sheet, sizeof(ngx_http_xslt_sheet_t)); 791 789 792 if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) { 793 return NGX_CONF_ERROR; 794 } 795 796 xmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_xslt_filter_module); 797 798 file = xmcf->sheet_files.elts; 799 for (i = 0; i < xmcf->sheet_files.nelts; i++) { 800 if (ngx_strcmp(file[i].name, &value[1].data) == 0) { 801 sheet->stylesheet = file[i].data; 802 goto found; 803 } 804 } 805 806 cln = ngx_pool_cleanup_add(cf->pool, 0); 807 if (cln == NULL) { 808 return NGX_CONF_ERROR; 809 } 810 811 sheet->stylesheet = xsltParseStylesheetFile(value[1].data); 812 if (sheet->stylesheet == NULL) { 813 ngx_conf_log_error(NGX_LOG_ERR, cf, 0, 814 "xsltParseStylesheetFile(\"%s\") failed", 815 value[1].data); 816 return NGX_CONF_ERROR; 817 } 818 819 cln->handler = ngx_http_xslt_cleanup_stylesheet; 820 cln->data = sheet->stylesheet; 821 822 file = ngx_array_push(&xmcf->sheet_files); 823 if (file == NULL) { 824 return NGX_CONF_ERROR; 825 } 826 827 file->name = value[1].data; 828 file->data = sheet->stylesheet; 829 830 found: 790 sheet->name.len = value[1].len; 791 sheet->name.data = value[1].data; 831 792 832 793 n = cf->args->nelts; 833 794 … … 935 896 { 936 897 ngx_http_xslt_filter_loc_conf_t *prev = parent; 937 898 ngx_http_xslt_filter_loc_conf_t *conf = child; 899 ngx_http_xslt_sheet_t *sheet = NULL; 900 ngx_http_xslt_filter_main_conf_t *xmcf = NULL; 901 ngx_http_core_loc_conf_t *clcf = NULL; 902 903 xmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_xslt_filter_module); 904 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); 938 905 939 906 if (conf->dtd == NULL) { 940 907 conf->dtd = prev->dtd; … … 943 910 if (conf->sheets.nelts == 0) { 944 911 conf->sheets = prev->sheets; 945 912 } 913 else 914 { 915 ngx_uint_t i = 0, ii = 0; 916 ngx_http_xslt_file_t *file = NULL; 917 918 sheet = conf->sheets.elts; 919 for (i = 0; i < conf->sheets.nelts; i++) 920 { 921 if(sheet[i].name.len 922 && !(sheet[i].name.data[0] == '/' 923 || (sheet[i].name.data[0] != '.' && sheet[i].name.data[1] != '/') 924 || (sheet[i].name.data[0] != '.' && sheet[i].name.data[1] != '.' 925 && sheet[i].name.data[2] != '/')) 926 && clcf->root.len) { 927 928 u_char *s = sheet[i].name.data; 929 930 sheet[i].name.data = ngx_pcalloc(cf->pool, sheet[i].name.len + 1 + clcf->root.len + 1); 931 if(sheet[i].name.data == NULL) { 932 return NGX_CONF_ERROR; 933 } 934 935 ngx_sprintf(sheet[i].name.data, "%s/%s", clcf->root.data, s); 936 } else if (ngx_conf_full_name(cf->cycle, &sheet[i].name, 0) != NGX_OK) { 937 return NGX_CONF_ERROR; 938 } 939 940 file = xmcf->sheet_files.elts; 941 for (ii = 0; ii < xmcf->sheet_files.nelts; ii++) 942 { 943 if (ngx_strcmp(file[ii].name, sheet[i].name.data) == 0) 944 { 945 sheet[i].stylesheet = file[ii].data; 946 } 947 } 948 949 if(!sheet[i].stylesheet) 950 { 951 ngx_pool_cleanup_t *cln = NULL; 952 953 cln = ngx_pool_cleanup_add(cf->pool, 0); 954 if (cln == NULL) { 955 return NGX_CONF_ERROR; 956 } 957 958 sheet[i].stylesheet = xsltParseStylesheetFile(sheet[i].name.data); 959 if (sheet[i].stylesheet == NULL) { 960 ngx_conf_log_error(NGX_LOG_ERR, cf, 0, 961 "xsltParseStylesheetFile(\"%s\") failed", 962 sheet[i].name.data); 963 return NGX_CONF_ERROR; 964 } 965 966 cln->handler = ngx_http_xslt_cleanup_stylesheet; 967 cln->data = sheet[i].stylesheet; 968 969 file = ngx_array_push(&xmcf->sheet_files); 970 if (file == NULL) { 971 return NGX_CONF_ERROR; 972 } 973 974 file->name = sheet[i].name.data; 975 file->data = sheet[i].stylesheet; 976 } 977 } 978 } 946 979 947 980 if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types, 948 981 &prev->types_keys, &prev->types, … … 952 985 return NGX_CONF_ERROR; 953 986 } 954 987 988 955 989 return NGX_CONF_OK; 956 990 } 957 991 958 959 992 static ngx_int_t 960 ngx_http_xslt_filter_ init(ngx_conf_t *cf)993 ngx_http_xslt_filter_preinit(ngx_conf_t *cf) 961 994 { 995 /* ensure init before actualy using libXML */ 962 996 xmlInitParser(); 963 997 964 998 #if (NGX_HAVE_EXSLT) 965 999 exsltRegisterAll(); 966 1000 #endif 967 1001 1002 return NGX_OK; 1003 } 1004 1005 static ngx_int_t 1006 ngx_http_xslt_filter_init(ngx_conf_t *cf) 1007 { 968 1008 ngx_http_next_header_filter = ngx_http_top_header_filter; 969 1009 ngx_http_top_header_filter = ngx_http_xslt_header_filter; 970 1010 … … 974 1014 return NGX_OK; 975 1015 } 976 1016 977 978 1017 static void 979 1018 ngx_http_xslt_filter_exit(ngx_cycle_t *cycle) 980 1019 {
