1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
5 */
6
7
8#ifndef _NGX_STREAM_SCRIPT_H_INCLUDED_
9#define _NGX_STREAM_SCRIPT_H_INCLUDED_
10
11
12#include <ngx_config.h>
13#include <ngx_core.h>
14#include <ngx_stream.h>
15
16
17typedef struct {
18    u_char                       *ip;
19    u_char                       *pos;
20    ngx_stream_variable_value_t  *sp;
21
22    ngx_str_t                     buf;
23    ngx_str_t                     line;
24
25    unsigned                      flushed:1;
26    unsigned                      skip:1;
27
28    ngx_stream_session_t         *session;
29} ngx_stream_script_engine_t;
30
31
32typedef struct {
33    ngx_conf_t                   *cf;
34    ngx_str_t                    *source;
35
36    ngx_array_t                 **flushes;
37    ngx_array_t                 **lengths;
38    ngx_array_t                 **values;
39
40    ngx_uint_t                    variables;
41    ngx_uint_t                    ncaptures;
42    ngx_uint_t                    size;
43
44    void                         *main;
45
46    unsigned                      complete_lengths:1;
47    unsigned                      complete_values:1;
48    unsigned                      zero:1;
49    unsigned                      conf_prefix:1;
50    unsigned                      root_prefix:1;
51} ngx_stream_script_compile_t;
52
53
54typedef struct {
55    ngx_str_t                     value;
56    ngx_uint_t                   *flushes;
57    void                         *lengths;
58    void                         *values;
59} ngx_stream_complex_value_t;
60
61
62typedef struct {
63    ngx_conf_t                   *cf;
64    ngx_str_t                    *value;
65    ngx_stream_complex_value_t   *complex_value;
66
67    unsigned                      zero:1;
68    unsigned                      conf_prefix:1;
69    unsigned                      root_prefix:1;
70} ngx_stream_compile_complex_value_t;
71
72
73typedef void (*ngx_stream_script_code_pt) (ngx_stream_script_engine_t *e);
74typedef size_t (*ngx_stream_script_len_code_pt) (ngx_stream_script_engine_t *e);
75
76
77typedef struct {
78    ngx_stream_script_code_pt     code;
79    uintptr_t                     len;
80} ngx_stream_script_copy_code_t;
81
82
83typedef struct {
84    ngx_stream_script_code_pt     code;
85    uintptr_t                     index;
86} ngx_stream_script_var_code_t;
87
88
89typedef struct {
90    ngx_stream_script_code_pt     code;
91    uintptr_t                     n;
92} ngx_stream_script_copy_capture_code_t;
93
94
95typedef struct {
96    ngx_stream_script_code_pt     code;
97    uintptr_t                     conf_prefix;
98} ngx_stream_script_full_name_code_t;
99
100
101void ngx_stream_script_flush_complex_value(ngx_stream_session_t *s,
102    ngx_stream_complex_value_t *val);
103ngx_int_t ngx_stream_complex_value(ngx_stream_session_t *s,
104    ngx_stream_complex_value_t *val, ngx_str_t *value);
105ngx_int_t ngx_stream_compile_complex_value(
106    ngx_stream_compile_complex_value_t *ccv);
107char *ngx_stream_set_complex_value_slot(ngx_conf_t *cf, ngx_command_t *cmd,
108    void *conf);
109
110
111ngx_uint_t ngx_stream_script_variables_count(ngx_str_t *value);
112ngx_int_t ngx_stream_script_compile(ngx_stream_script_compile_t *sc);
113u_char *ngx_stream_script_run(ngx_stream_session_t *s, ngx_str_t *value,
114    void *code_lengths, size_t reserved, void *code_values);
115void ngx_stream_script_flush_no_cacheable_variables(ngx_stream_session_t *s,
116    ngx_array_t *indices);
117
118void *ngx_stream_script_add_code(ngx_array_t *codes, size_t size, void *code);
119
120size_t ngx_stream_script_copy_len_code(ngx_stream_script_engine_t *e);
121void ngx_stream_script_copy_code(ngx_stream_script_engine_t *e);
122size_t ngx_stream_script_copy_var_len_code(ngx_stream_script_engine_t *e);
123void ngx_stream_script_copy_var_code(ngx_stream_script_engine_t *e);
124size_t ngx_stream_script_copy_capture_len_code(ngx_stream_script_engine_t *e);
125void ngx_stream_script_copy_capture_code(ngx_stream_script_engine_t *e);
126
127#endif /* _NGX_STREAM_SCRIPT_H_INCLUDED_ */
128