[PATCH] Variable $time_short.

Gena Makhomed gmm at csdoc.com
Wed May 26 20:42:59 UTC 2021


# HG changeset patch
# User Gena Makhomed <gmm at csdoc.com>
# Date 1622061379 -10800
#      Wed May 26 23:36:19 2021 +0300
# Node ID b3c942ec8a13bc8f6cd4b3e2385acb8c14502c0d
# Parent  f5de03f308a6d7864b7d5108a968db56585b9a9b
Variable $time_short.

Variable $time_short in form "1970/09/28 12:00:00".
Added to ngx_http_core_module, ngx_http_log_module,
and ngx_stream_core_module.

diff -r f5de03f308a6 -r b3c942ec8a13 src/http/modules/ngx_http_log_module.c
--- a/src/http/modules/ngx_http_log_module.c	Tue May 25 15:28:56 2021 +0300
+++ b/src/http/modules/ngx_http_log_module.c	Wed May 26 23:36:19 2021 +0300
@@ -115,6 +115,8 @@
      ngx_http_log_op_t *op);
  static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf,
      ngx_http_log_op_t *op);
+static u_char *ngx_http_log_time_short(ngx_http_request_t *r, u_char *buf,
+    ngx_http_log_op_t *op);
  static u_char *ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf,
      ngx_http_log_op_t *op);
  static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf,
@@ -234,6 +236,8 @@
      { ngx_string("pipe"), 1, ngx_http_log_pipe },
      { ngx_string("time_local"), sizeof("28/Sep/1970:12:00:00 +0600") - 1,
                            ngx_http_log_time },
+    { ngx_string("time_short"), sizeof("1970/09/28 12:00:00") - 1,
+                          ngx_http_log_time_short },
      { ngx_string("time_iso8601"), sizeof("1970-09-28T12:00:00+06:00") - 1,
                            ngx_http_log_iso8601 },
      { ngx_string("msec"), NGX_TIME_T_LEN + 4, ngx_http_log_msec },
@@ -817,6 +821,13 @@
  }

  static u_char *
+ngx_http_log_time_short(ngx_http_request_t *r, u_char *buf, 
ngx_http_log_op_t *op)
+{
+    return ngx_cpymem(buf, ngx_cached_err_log_time.data,
+                      ngx_cached_err_log_time.len);
+}
+
+static u_char *
  ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf, 
ngx_http_log_op_t *op)
  {
      return ngx_cpymem(buf, ngx_cached_http_log_iso8601.data,
diff -r f5de03f308a6 -r b3c942ec8a13 src/http/ngx_http_variables.c
--- a/src/http/ngx_http_variables.c	Tue May 25 15:28:56 2021 +0300
+++ b/src/http/ngx_http_variables.c	Wed May 26 23:36:19 2021 +0300
@@ -142,6 +142,8 @@
      ngx_http_variable_value_t *v, uintptr_t data);
  static ngx_int_t ngx_http_variable_time_iso8601(ngx_http_request_t *r,
      ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_http_variable_time_short(ngx_http_request_t *r,
+    ngx_http_variable_value_t *v, uintptr_t data);
  static ngx_int_t ngx_http_variable_time_local(ngx_http_request_t *r,
      ngx_http_variable_value_t *v, uintptr_t data);

@@ -362,6 +364,9 @@
      { ngx_string("time_iso8601"), NULL, ngx_http_variable_time_iso8601,
        0, NGX_HTTP_VAR_NOCACHEABLE, 0 },

+    { ngx_string("time_short"), NULL, ngx_http_variable_time_short,
+      0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
+
      { ngx_string("time_local"), NULL, ngx_http_variable_time_local,
        0, NGX_HTTP_VAR_NOCACHEABLE, 0 },

@@ -2380,6 +2385,29 @@


  static ngx_int_t
+ngx_http_variable_time_short(ngx_http_request_t *r,
+    ngx_http_variable_value_t *v, uintptr_t data)
+{
+    u_char  *p;
+
+    p = ngx_pnalloc(r->pool, ngx_cached_err_log_time.len);
+    if (p == NULL) {
+        return NGX_ERROR;
+    }
+
+    ngx_memcpy(p, ngx_cached_err_log_time.data, 
ngx_cached_err_log_time.len);
+
+    v->len = ngx_cached_err_log_time.len;
+    v->valid = 1;
+    v->no_cacheable = 0;
+    v->not_found = 0;
+    v->data = p;
+
+    return NGX_OK;
+}
+
+
+static ngx_int_t
  ngx_http_variable_time_local(ngx_http_request_t *r,
      ngx_http_variable_value_t *v, uintptr_t data)
  {
diff -r f5de03f308a6 -r b3c942ec8a13 src/stream/ngx_stream_variables.c
--- a/src/stream/ngx_stream_variables.c	Tue May 25 15:28:56 2021 +0300
+++ b/src/stream/ngx_stream_variables.c	Wed May 26 23:36:19 2021 +0300
@@ -46,6 +46,8 @@
      ngx_stream_variable_value_t *v, uintptr_t data);
  static ngx_int_t ngx_stream_variable_time_iso8601(ngx_stream_session_t *s,
      ngx_stream_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_stream_variable_time_short(ngx_stream_session_t *s,
+    ngx_stream_variable_value_t *v, uintptr_t data);
  static ngx_int_t ngx_stream_variable_time_local(ngx_stream_session_t *s,
      ngx_stream_variable_value_t *v, uintptr_t data);
  static ngx_int_t ngx_stream_variable_protocol(ngx_stream_session_t *s,
@@ -115,6 +117,9 @@
      { ngx_string("time_iso8601"), NULL, ngx_stream_variable_time_iso8601,
        0, NGX_STREAM_VAR_NOCACHEABLE, 0 },

+    { ngx_string("time_short"), NULL, ngx_stream_variable_time_short,
+      0, NGX_STREAM_VAR_NOCACHEABLE, 0 },
+
      { ngx_string("time_local"), NULL, ngx_stream_variable_time_local,
        0, NGX_STREAM_VAR_NOCACHEABLE, 0 },

@@ -875,6 +880,29 @@


  static ngx_int_t
+ngx_stream_variable_time_short(ngx_stream_session_t *s,
+    ngx_stream_variable_value_t *v, uintptr_t data)
+{
+    u_char  *p;
+
+    p = ngx_pnalloc(s->connection->pool, ngx_cached_err_log_time.len);
+    if (p == NULL) {
+        return NGX_ERROR;
+    }
+
+    ngx_memcpy(p, ngx_cached_err_log_time.data, 
ngx_cached_err_log_time.len);
+
+    v->len = ngx_cached_err_log_time.len;
+    v->valid = 1;
+    v->no_cacheable = 0;
+    v->not_found = 0;
+    v->data = p;
+
+    return NGX_OK;
+}
+
+
+static ngx_int_t
  ngx_stream_variable_time_local(ngx_stream_session_t *s,
      ngx_stream_variable_value_t *v, uintptr_t data)
  {



More information about the nginx-devel mailing list