LCOV - code coverage report
Current view: top level - home/agentz/git/echo-nginx-module/src - ngx_http_echo_var.c (source / functions) Hit Total Coverage
Test: foo.info Lines: 7 22 31.8 %
Date: 2011-05-12 Functions: 1 2 50.0 %
Branches: 3 8 37.5 %

           Branch data     Line data    Source code
       1                 :            : #define DDEBUG 0
       2                 :            : #include "ddebug.h"
       3                 :            : 
       4                 :            : #include "ngx_http_echo_var.h"
       5                 :            : #include "ngx_http_echo_timer.h"
       6                 :            : #include "ngx_http_echo_request_info.h"
       7                 :            : #include "ngx_http_echo_foreach.h"
       8                 :            : 
       9                 :            : 
      10                 :            : static ngx_int_t ngx_http_echo_incr_variable(ngx_http_request_t *r,
      11                 :            :         ngx_http_variable_value_t *v, uintptr_t data);
      12                 :            : 
      13                 :            : 
      14                 :            : static ngx_http_variable_t ngx_http_echo_variables[] = {
      15                 :            : 
      16                 :            :     { ngx_string("echo_timer_elapsed"), NULL,
      17                 :            :       ngx_http_echo_timer_elapsed_variable, 0,
      18                 :            :       NGX_HTTP_VAR_NOCACHEABLE, 0 },
      19                 :            : 
      20                 :            :     { ngx_string("echo_request_method"), NULL,
      21                 :            :       ngx_http_echo_request_method_variable, 0,
      22                 :            :       NGX_HTTP_VAR_NOCACHEABLE, 0 },
      23                 :            : 
      24                 :            :     { ngx_string("echo_cacheable_request_uri"), NULL,
      25                 :            :       ngx_http_echo_cacheable_request_uri_variable, 0,
      26                 :            :       0, 0 },
      27                 :            : 
      28                 :            :     { ngx_string("echo_request_uri"), NULL,
      29                 :            :       ngx_http_echo_request_uri_variable, 0,
      30                 :            :       0, 0 },
      31                 :            : 
      32                 :            :     { ngx_string("echo_client_request_method"), NULL,
      33                 :            :       ngx_http_echo_client_request_method_variable, 0,
      34                 :            :       NGX_HTTP_VAR_NOCACHEABLE, 0 },
      35                 :            : 
      36                 :            :     { ngx_string("echo_request_body"), NULL,
      37                 :            :       ngx_http_echo_request_body_variable, 0,
      38                 :            :       NGX_HTTP_VAR_NOCACHEABLE, 0 },
      39                 :            : 
      40                 :            :     { ngx_string("echo_client_request_headers"), NULL,
      41                 :            :       ngx_http_echo_client_request_headers_variable, 0,
      42                 :            :       NGX_HTTP_VAR_NOCACHEABLE, 0 },
      43                 :            : 
      44                 :            :     { ngx_string("echo_it"), NULL,
      45                 :            :       ngx_http_echo_it_variable, 0,
      46                 :            :       NGX_HTTP_VAR_NOCACHEABLE, 0 },
      47                 :            : 
      48                 :            :     { ngx_string("echo_incr"), NULL,
      49                 :            :       ngx_http_echo_incr_variable, 0,
      50                 :            :       NGX_HTTP_VAR_NOCACHEABLE, 0 },
      51                 :            : 
      52                 :            :     { ngx_string("echo_response_status"), NULL,
      53                 :            :       ngx_http_echo_response_status_variable, 0,
      54                 :            :       NGX_HTTP_VAR_NOCACHEABLE, 0 },
      55                 :            : 
      56                 :            :     { ngx_null_string, NULL, NULL, 0, 0, 0 }
      57                 :            : };
      58                 :            : 
      59                 :            : 
      60                 :            : ngx_int_t
      61                 :         88 : ngx_http_echo_add_variables(ngx_conf_t *cf)
      62                 :            : {
      63                 :            :     ngx_http_variable_t *var, *v;
      64                 :            : 
      65         [ +  + ]:        968 :     for (v = ngx_http_echo_variables; v->name.len; v++) {
      66                 :        880 :         var = ngx_http_add_variable(cf, &v->name, v->flags);
      67         [ -  + ]:        880 :         if (var == NULL) {
      68                 :          0 :             return NGX_ERROR;
      69                 :            :         }
      70                 :            : 
      71                 :        880 :         var->get_handler = v->get_handler;
      72                 :        880 :         var->data = v->data;
      73                 :            :     }
      74                 :            : 
      75                 :         88 :     return NGX_OK;
      76                 :            : }
      77                 :            : 
      78                 :            : 
      79                 :            : static ngx_int_t
      80                 :          0 : ngx_http_echo_incr_variable(ngx_http_request_t *r,
      81                 :            :         ngx_http_variable_value_t *v, uintptr_t data)
      82                 :            : {
      83                 :            :     ngx_http_echo_ctx_t         *ctx;
      84                 :            :     u_char                      *p;
      85                 :            : 
      86                 :          0 :     ctx = ngx_http_get_module_ctx(r->main, ngx_http_echo_module);
      87                 :            : 
      88         [ #  # ]:          0 :     if (ctx == NULL) {
      89                 :          0 :         return NGX_ERROR;
      90                 :            :     }
      91                 :            : 
      92                 :          0 :     ctx->counter++;
      93                 :            : 
      94                 :          0 :     p = ngx_palloc(r->pool, NGX_INT_T_LEN);
      95         [ #  # ]:          0 :     if (p == NULL) {
      96                 :          0 :         return NGX_ERROR;
      97                 :            :     }
      98                 :            : 
      99                 :          0 :     v->len = ngx_sprintf(p, "%ui", ctx->counter) - p;
     100                 :          0 :     v->data = p;
     101                 :            : 
     102                 :          0 :     v->valid = 1;
     103                 :          0 :     v->not_found = 0;
     104                 :          0 :     v->no_cacheable = 1;
     105                 :            : 
     106                 :          0 :     return NGX_OK;
     107                 :            : }
     108                 :            : 

Generated by: LCOV version 1.9