Ticket #9: ng-autoindex-namelen-1.patch

File ng-autoindex-namelen-1.patch, 3.5 KB (added by shipilev.livejournal.com, 15 years ago)

proposed patch

  • src/http/modules/ngx_http_autoindex_module.c

    diff -r fb2982a359ef -r 3687ef725d90 src/http/modules/ngx_http_autoindex_module.c
    a b  
    3939    ngx_flag_t     enable;
    4040    ngx_flag_t     localtime;
    4141    ngx_flag_t     exact_size;
     42    ngx_uint_t     max_name_len;
    4243} ngx_http_autoindex_loc_conf_t;
    4344
    4445
    4546#define NGX_HTTP_AUTOINDEX_PREALLOCATE  50
    4647
    47 #define NGX_HTTP_AUTOINDEX_NAME_LEN     50
    48 
    4948
    5049static int ngx_libc_cdecl ngx_http_autoindex_cmp_entries(const void *one,
    5150    const void *two);
     
    8079      offsetof(ngx_http_autoindex_loc_conf_t, exact_size),
    8180      NULL },
    8281
     82    { ngx_string("autoindex_max_name_len"),
     83      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
     84      ngx_conf_set_size_slot,
     85      NGX_HTTP_LOC_CONF_OFFSET,
     86      offsetof(ngx_http_autoindex_loc_conf_t, max_name_len),
     87      NULL },
     88
    8389      ngx_null_command
    8490};
    8591
     
    374380            + 1                                          /* 1 is for "/" */
    375381            + sizeof("\">") - 1
    376382            + entry[i].name.len - entry[i].utf_len + entry[i].colon * 2
    377             + NGX_HTTP_AUTOINDEX_NAME_LEN + sizeof(">") - 2
     383            + alcf->max_name_len + sizeof(">") - 2
    378384            + sizeof("</a>") - 1
    379385            + sizeof(" 28-Sep-1970 12:00 ") - 1
    380386            + 20                                         /* the file size */
     
    432438        len = entry[i].utf_len;
    433439
    434440        if (entry[i].name.len != len) {
    435             if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) {
    436                 utf_len = NGX_HTTP_AUTOINDEX_NAME_LEN - 3 + 1;
     441            if (len > alcf->max_name_len) {
     442                utf_len = alcf->max_name_len - 3 + 1;
    437443
    438444            } else {
    439                 utf_len = NGX_HTTP_AUTOINDEX_NAME_LEN + 1;
     445                utf_len = alcf->max_name_len + 1;
    440446            }
    441447
    442448            b->last = ngx_utf8_cpystrn(b->last, entry[i].name.data,
     
    445451
    446452        } else {
    447453            b->last = ngx_cpystrn(b->last, entry[i].name.data,
    448                                   NGX_HTTP_AUTOINDEX_NAME_LEN + 1);
     454                                  alcf->max_name_len + 1);
    449455            last = b->last - 3;
    450456        }
    451457
    452         if (len > NGX_HTTP_AUTOINDEX_NAME_LEN) {
     458        if (len > alcf->max_name_len) {
    453459            b->last = ngx_cpymem(last, "..&gt;</a>", sizeof("..&gt;</a>") - 1);
    454460
    455461        } else {
    456             if (entry[i].dir && NGX_HTTP_AUTOINDEX_NAME_LEN - len > 0) {
     462            if (entry[i].dir && alcf->max_name_len - len > 0) {
    457463                *b->last++ = '/';
    458464                len++;
    459465            }
    460466
    461467            b->last = ngx_cpymem(b->last, "</a>", sizeof("</a>") - 1);
    462             ngx_memset(b->last, ' ', NGX_HTTP_AUTOINDEX_NAME_LEN - len);
    463             b->last += NGX_HTTP_AUTOINDEX_NAME_LEN - len;
     468            ngx_memset(b->last, ' ', (alcf->max_name_len - len));
     469            b->last += (alcf->max_name_len - len);
    464470        }
    465471
    466472        *b->last++ = ' ';
     
    633639    conf->enable = NGX_CONF_UNSET;
    634640    conf->localtime = NGX_CONF_UNSET;
    635641    conf->exact_size = NGX_CONF_UNSET;
     642    conf->max_name_len = NGX_CONF_UNSET_UINT;
    636643
    637644    return conf;
    638645}
     
    647654    ngx_conf_merge_value(conf->enable, prev->enable, 0);
    648655    ngx_conf_merge_value(conf->localtime, prev->localtime, 0);
    649656    ngx_conf_merge_value(conf->exact_size, prev->exact_size, 1);
     657    ngx_conf_merge_uint_value(conf->max_name_len, prev->max_name_len, 50);
    650658
    651659    return NGX_CONF_OK;
    652660}