comparison src/http/modules/ngx_http_ssi_filter_module.c @ 5540:3a8e19528b30

SSI: fixed $date_local and $date_gmt without SSI (ticket #230). If there is no SSI context in a given request at a given time, the $date_local and $date_gmt variables used "%s" format, instead of "%A, %d-%b-%Y %H:%M:%S %Z" documented as the default and used if there is SSI module context and timefmt wasn't modified using the "config" SSI command. While use of these variables outside of the SSI evaluation isn't strictly valid, previous behaviour is certainly inconsistent, hence the fix.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 28 Jan 2014 15:40:45 +0400
parents 74bfa803a5aa
children e491b26fa5a1
comparison
equal deleted inserted replaced
5539:c86dd32573c0 5540:3a8e19528b30
211 211
212 212
213 static u_char ngx_http_ssi_string[] = "<!--"; 213 static u_char ngx_http_ssi_string[] = "<!--";
214 214
215 static ngx_str_t ngx_http_ssi_none = ngx_string("(none)"); 215 static ngx_str_t ngx_http_ssi_none = ngx_string("(none)");
216 static ngx_str_t ngx_http_ssi_timefmt = ngx_string("%A, %d-%b-%Y %H:%M:%S %Z");
216 static ngx_str_t ngx_http_ssi_null_string = ngx_null_string; 217 static ngx_str_t ngx_http_ssi_null_string = ngx_null_string;
217 218
218 219
219 #define NGX_HTTP_SSI_INCLUDE_VIRTUAL 0 220 #define NGX_HTTP_SSI_INCLUDE_VIRTUAL 0
220 #define NGX_HTTP_SSI_INCLUDE_FILE 1 221 #define NGX_HTTP_SSI_INCLUDE_FILE 1
357 ctx->params.elts = ctx->params_array; 358 ctx->params.elts = ctx->params_array;
358 ctx->params.size = sizeof(ngx_table_elt_t); 359 ctx->params.size = sizeof(ngx_table_elt_t);
359 ctx->params.nalloc = NGX_HTTP_SSI_PARAMS_N; 360 ctx->params.nalloc = NGX_HTTP_SSI_PARAMS_N;
360 ctx->params.pool = r->pool; 361 ctx->params.pool = r->pool;
361 362
362 ngx_str_set(&ctx->timefmt, "%A, %d-%b-%Y %H:%M:%S %Z"); 363 ctx->timefmt = ngx_http_ssi_timefmt;
363 ngx_str_set(&ctx->errmsg, 364 ngx_str_set(&ctx->errmsg,
364 "[an error occurred while processing the directive]"); 365 "[an error occurred while processing the directive]");
365 366
366 r->filter_need_in_memory = 1; 367 r->filter_need_in_memory = 1;
367 368
2718 ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r, 2719 ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r,
2719 ngx_http_variable_value_t *v, uintptr_t gmt) 2720 ngx_http_variable_value_t *v, uintptr_t gmt)
2720 { 2721 {
2721 ngx_http_ssi_ctx_t *ctx; 2722 ngx_http_ssi_ctx_t *ctx;
2722 ngx_time_t *tp; 2723 ngx_time_t *tp;
2724 ngx_str_t *timefmt;
2723 struct tm tm; 2725 struct tm tm;
2724 char buf[NGX_HTTP_SSI_DATE_LEN]; 2726 char buf[NGX_HTTP_SSI_DATE_LEN];
2725 2727
2726 v->valid = 1; 2728 v->valid = 1;
2727 v->no_cacheable = 0; 2729 v->no_cacheable = 0;
2729 2731
2730 tp = ngx_timeofday(); 2732 tp = ngx_timeofday();
2731 2733
2732 ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module); 2734 ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module);
2733 2735
2734 if (ctx == NULL 2736 timefmt = ctx ? &ctx->timefmt : &ngx_http_ssi_timefmt;
2735 || (ctx->timefmt.len == sizeof("%s") - 1 2737
2736 && ctx->timefmt.data[0] == '%' && ctx->timefmt.data[1] == 's')) 2738 if (timefmt->len == sizeof("%s") - 1
2739 && timefmt->data[0] == '%' && timefmt->data[1] == 's')
2737 { 2740 {
2738 v->data = ngx_pnalloc(r->pool, NGX_TIME_T_LEN); 2741 v->data = ngx_pnalloc(r->pool, NGX_TIME_T_LEN);
2739 if (v->data == NULL) { 2742 if (v->data == NULL) {
2740 return NGX_ERROR; 2743 return NGX_ERROR;
2741 } 2744 }
2750 } else { 2753 } else {
2751 ngx_libc_localtime(tp->sec, &tm); 2754 ngx_libc_localtime(tp->sec, &tm);
2752 } 2755 }
2753 2756
2754 v->len = strftime(buf, NGX_HTTP_SSI_DATE_LEN, 2757 v->len = strftime(buf, NGX_HTTP_SSI_DATE_LEN,
2755 (char *) ctx->timefmt.data, &tm); 2758 (char *) timefmt->data, &tm);
2756 if (v->len == 0) { 2759 if (v->len == 0) {
2757 return NGX_ERROR; 2760 return NGX_ERROR;
2758 } 2761 }
2759 2762
2760 v->data = ngx_pnalloc(r->pool, v->len); 2763 v->data = ngx_pnalloc(r->pool, v->len);