Ticket #59: nginx-1.1.8-xslt-fix.patch

File nginx-1.1.8-xslt-fix.patch, 7.0 KB (added by sam, 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  
    4040typedef struct {
    4141    xsltStylesheetPtr    stylesheet;
    4242    ngx_array_t          params;       /* ngx_http_complex_value_t */
     43    ngx_str_t            name;
    4344} ngx_http_xslt_sheet_t;
    4445
    4546
     
    9091static void *ngx_http_xslt_filter_create_conf(ngx_conf_t *cf);
    9192static char *ngx_http_xslt_filter_merge_conf(ngx_conf_t *cf, void *parent,
    9293    void *child);
     94    static ngx_int_t ngx_http_xslt_filter_preinit(ngx_conf_t *cf);
    9395static ngx_int_t ngx_http_xslt_filter_init(ngx_conf_t *cf);
    9496static void ngx_http_xslt_filter_exit(ngx_cycle_t *cycle);
    9597
    96 
    9798ngx_str_t  ngx_http_xslt_default_types[] = {
    9899    ngx_string("text/xml"),
    99100    ngx_null_string
     
    128129
    129130
    130131static ngx_http_module_t  ngx_http_xslt_filter_module_ctx = {
    131     NULL,                                  /* preconfiguration */
     132    ngx_http_xslt_filter_preinit,          /* preconfiguration */
    132133    ngx_http_xslt_filter_init,             /* postconfiguration */
    133134
    134135    ngx_http_xslt_filter_create_main_conf, /* create main configuration */
     
    764765
    765766    ngx_str_t                         *value;
    766767    ngx_uint_t                         i, n;
    767     ngx_pool_cleanup_t                *cln;
    768     ngx_http_xslt_file_t              *file;
    769768    ngx_http_xslt_sheet_t             *sheet;
    770769    ngx_http_complex_value_t          *param;
    771770    ngx_http_compile_complex_value_t   ccv;
    772     ngx_http_xslt_filter_main_conf_t  *xmcf;
    773771
    774772    value = cf->args->elts;
    775773
     
    789787
    790788    ngx_memzero(sheet, sizeof(ngx_http_xslt_sheet_t));
    791789
    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;
    831792
    832793    n = cf->args->nelts;
    833794
     
    935896{
    936897    ngx_http_xslt_filter_loc_conf_t *prev = parent;
    937898    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);
    938905
    939906    if (conf->dtd == NULL) {
    940907        conf->dtd = prev->dtd;
     
    943910    if (conf->sheets.nelts == 0) {
    944911        conf->sheets = prev->sheets;
    945912    }
     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    }
    946979
    947980    if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types,
    948981                             &prev->types_keys, &prev->types,
     
    952985        return NGX_CONF_ERROR;
    953986    }
    954987
     988
    955989    return NGX_CONF_OK;
    956990}
    957991
    958 
    959992static ngx_int_t
    960 ngx_http_xslt_filter_init(ngx_conf_t *cf)
     993ngx_http_xslt_filter_preinit(ngx_conf_t *cf)
    961994{
     995    /* ensure init before actualy using libXML */
    962996    xmlInitParser();
    963997
    964998#if (NGX_HAVE_EXSLT)
    965999    exsltRegisterAll();
    9661000#endif
    9671001
     1002    return NGX_OK;
     1003}
     1004
     1005static ngx_int_t
     1006ngx_http_xslt_filter_init(ngx_conf_t *cf)
     1007{
    9681008    ngx_http_next_header_filter = ngx_http_top_header_filter;
    9691009    ngx_http_top_header_filter = ngx_http_xslt_header_filter;
    9701010
     
    9741014    return NGX_OK;
    9751015}
    9761016
    977 
    9781017static void
    9791018ngx_http_xslt_filter_exit(ngx_cycle_t *cycle)
    9801019{