ngx_http_variables.h revision e18a033b
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
5 */
6
7
8#ifndef _NGX_HTTP_VARIABLES_H_INCLUDED_
9#define _NGX_HTTP_VARIABLES_H_INCLUDED_
10
11
12#include <ngx_config.h>
13#include <ngx_core.h>
14#include <ngx_http.h>
15
16
17typedef ngx_variable_value_t  ngx_http_variable_value_t;
18
19#define ngx_http_variable(v)     { sizeof(v) - 1, 1, 0, 0, 0, (u_char *) v }
20
21typedef struct ngx_http_variable_s  ngx_http_variable_t;
22
23typedef void (*ngx_http_set_variable_pt) (ngx_http_request_t *r,
24    ngx_http_variable_value_t *v, uintptr_t data);
25typedef ngx_int_t (*ngx_http_get_variable_pt) (ngx_http_request_t *r,
26    ngx_http_variable_value_t *v, uintptr_t data);
27
28
29#define NGX_HTTP_VAR_CHANGEABLE   1
30#define NGX_HTTP_VAR_NOCACHEABLE  2
31#define NGX_HTTP_VAR_INDEXED      4
32#define NGX_HTTP_VAR_NOHASH       8
33#define NGX_HTTP_VAR_WEAK         16
34#define NGX_HTTP_VAR_PREFIX       32
35
36
37struct ngx_http_variable_s {
38    ngx_str_t                     name;   /* must be first to build the hash */
39    ngx_http_set_variable_pt      set_handler;
40    ngx_http_get_variable_pt      get_handler;
41    uintptr_t                     data;
42    ngx_uint_t                    flags;
43    ngx_uint_t                    index;
44};
45
46
47ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name,
48    ngx_uint_t flags);
49ngx_int_t ngx_http_get_variable_index(ngx_conf_t *cf, ngx_str_t *name);
50ngx_http_variable_value_t *ngx_http_get_indexed_variable(ngx_http_request_t *r,
51    ngx_uint_t index);
52ngx_http_variable_value_t *ngx_http_get_flushed_variable(ngx_http_request_t *r,
53    ngx_uint_t index);
54
55ngx_http_variable_value_t *ngx_http_get_variable(ngx_http_request_t *r,
56    ngx_str_t *name, ngx_uint_t key);
57
58ngx_int_t ngx_http_variable_unknown_header(ngx_http_variable_value_t *v,
59    ngx_str_t *var, ngx_list_part_t *part, size_t prefix);
60
61
62#if (NGX_PCRE)
63
64typedef struct {
65    ngx_uint_t                    capture;
66    ngx_int_t                     index;
67} ngx_http_regex_variable_t;
68
69
70typedef struct {
71    ngx_regex_t                  *regex;
72    ngx_uint_t                    ncaptures;
73    ngx_http_regex_variable_t    *variables;
74    ngx_uint_t                    nvariables;
75    ngx_str_t                     name;
76} ngx_http_regex_t;
77
78
79typedef struct {
80    ngx_http_regex_t             *regex;
81    void                         *value;
82} ngx_http_map_regex_t;
83
84
85ngx_http_regex_t *ngx_http_regex_compile(ngx_conf_t *cf,
86    ngx_regex_compile_t *rc);
87ngx_int_t ngx_http_regex_exec(ngx_http_request_t *r, ngx_http_regex_t *re,
88    ngx_str_t *s);
89
90#endif
91
92
93typedef struct {
94    ngx_hash_combined_t           hash;
95#if (NGX_PCRE)
96    ngx_http_map_regex_t         *regex;
97    ngx_uint_t                    nregex;
98#endif
99} ngx_http_map_t;
100
101
102void *ngx_http_map_find(ngx_http_request_t *r, ngx_http_map_t *map,
103    ngx_str_t *match);
104
105
106ngx_int_t ngx_http_variables_add_core_vars(ngx_conf_t *cf);
107ngx_int_t ngx_http_variables_init_vars(ngx_conf_t *cf);
108
109
110extern ngx_http_variable_value_t  ngx_http_variable_null_value;
111extern ngx_http_variable_value_t  ngx_http_variable_true_value;
112
113
114#endif /* _NGX_HTTP_VARIABLES_H_INCLUDED_ */
115