Welcome! Log In Create A New Profile

Advanced

Re: [PATCH] export variables from the log module

Vladimir Shebordaev
September 30, 2012 01:12AM
On 30.09.2012 07:55, Vladimir Shebordaev wrote:
> Index: src/http/ngx_http_variables.c
> ===================================================================
> --- src/http/ngx_http_variables.c (revision 4872)
> +++ src/http/ngx_http_variables.c (working copy)
> @@ -487,12 +487,14 @@
> } else {
>
> vv = ngx_palloc(r->pool,
> sizeof(ngx_http_variable_value_t));
> -
> - if (vv && v->get_handler(r, vv, v->data) == NGX_OK) {
> - return vv;
> + if (vv) {
> +
> + vv->len = 0;

The idea behind this is to indicate unallocated value data to the
getter. Probably, zero vv-data field would be cleaner solution,
since the getter can just do nothing that gives zero value length
while the space has been actually allocated.

> + if (v->get_handler(r, vv, v->data) != NGX_OK) {
> + vv = NULL;
> + }
> }
> -
> - return NULL;
> + return vv;
> }
> }
>
> Index: src/http/modules/ngx_http_log_module.c
> ===================================================================
> --- src/http/modules/ngx_http_log_module.c (revision 4872)
> +++ src/http/modules/ngx_http_log_module.c (working copy)
> @@ -114,6 +114,7 @@
> static void *ngx_http_log_create_loc_conf(ngx_conf_t *cf);
> static char *ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void
> *parent,
> void *child);
> +static ngx_int_t ngx_http_log_add_variables(ngx_conf_t *cf);
> static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t
> *cmd,
> void *conf);
> static char *ngx_http_log_set_format(ngx_conf_t *cf,
> ngx_command_t *cmd,
> @@ -154,7 +155,7 @@
>
>
> static ngx_http_module_t ngx_http_log_module_ctx = {
> - NULL, /* preconfiguration */
> + ngx_http_log_add_variables, /* preconfiguration */
> ngx_http_log_init, /* postconfiguration */
>
> ngx_http_log_create_main_conf, /* create main
> configuration */
> @@ -1338,6 +1339,70 @@
>
>
> static ngx_int_t
> +ngx_http_log_get_variable(ngx_http_request_t *r,
> ngx_variable_value_t *value, uintptr_t data)
> +{
> + ngx_http_log_var_t *v;
> +
> + v = (ngx_http_log_var_t *)data;
> +
> + if (!value->len) {

The same field should be checked here.

Regards,
Vladimir

> + value->data = ngx_pnalloc(r->pool, v->len);
> + if (value->data == NULL) {
> + return NGX_ERROR;
> + }
> + }
> +
> + value->len = v->run(r, value->data, NULL) - value->data;
> +
> + value->not_found = 0;
> + value->valid = 1;
> +
> + return NGX_OK;
> +}
> +
> +
> +static ngx_int_t
> +ngx_http_log_add_variables(ngx_conf_t *cf)
> +{
> + ngx_http_log_var_t *v;
> + ngx_http_variable_t *var;
> + ngx_http_core_main_conf_t *cmcf;
> +
> + ngx_int_t rc;
> +
> + cmcf = ngx_http_conf_get_module_main_conf(cf,
> ngx_http_core_module);
> +
> + var = NULL;
> +
> + for (v = ngx_http_log_vars; v->name.len; v++) {
> +
> + if (var == NULL) {
> + var = ngx_pcalloc(cf->pool,
> sizeof(ngx_http_variable_t));
> + if (var == NULL) {
> + return NGX_ERROR;
> + }
> + }
> +
> + var->name = v->name;
> +
> + rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, var,
> + NGX_HASH_READONLY_KEY);
> +
> + if (rc == NGX_BUSY) {
> + continue;
> + }
> +
> + var->get_handler = ngx_http_log_get_variable;
> + var->data = (uintptr_t)v;
> + var->flags =
> NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE;
> +
> + var = NULL;
> + }
> +
> + return NGX_OK;
> +}
> +
> +static ngx_int_t
> ngx_http_log_init(ngx_conf_t *cf)
> {
> ngx_str_t *value;
>
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] export variables from the log module

Vladimir Shebordaev 1103 September 29, 2012 11:58PM

Re: [PATCH] export variables from the log module

Vladimir Shebordaev 432 September 30, 2012 01:12AM

Re: [PATCH] export variables from the log module

Maxim Dounin 508 September 30, 2012 02:56PM

Re: [PATCH] export variables from the log module

Vladimir Shebordaev 504 September 30, 2012 07:04PM

Re: [PATCH] export variables from the log module Attachments

Benjamin Grössing 486 September 30, 2012 07:22PM

Re: [PATCH] export variables from the log module

Vladimir Shebordaev 631 September 30, 2012 07:48PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 308
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready