Class: NginxModuleSourceGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ngxmodgen/srcgen.rb

Instance Method Summary collapse

Constructor Details

#initialize(module_name) ⇒ NginxModuleSourceGenerator

Returns a new instance of NginxModuleSourceGenerator.



3
4
5
# File 'lib/ngxmodgen/srcgen.rb', line 3

def initialize(module_name)
  @module_name = module_name
end

Instance Method Details

#filter_generateObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ngxmodgen/srcgen.rb', line 60

def filter_generate
  <<"EOS"

#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>

static ngx_int_t ngx_http_#{@module_name}_filter_init(ngx_conf_t *cf);

static ngx_http_module_t  ngx_http_#{@module_name}_filter_module_ctx = {
  NULL,                                  /* preconfiguration */
  ngx_http_#{@module_name}_filter_init,  /* postconfiguration */

  NULL,                                  /* create main configuration */
  NULL,                                  /* init main configuration */

  NULL,                                  /* create server configuration */
  NULL,                                  /* merge server configuration */

  NULL,                                  /* create location configuration */
  NULL                                   /* merge location configuration */
};

ngx_module_t  ngx_http_#{@module_name}_filter_module = {
  NGX_MODULE_V1,
  &ngx_http_#{@module_name}_filter_module_ctx, /* module context */
  NULL,                                        /* module directives */
  NGX_HTTP_MODULE,                             /* module type */
  NULL,                                        /* init master */
  NULL,                                        /* init module */
  NULL,                                        /* init process */
  NULL,                                        /* init thread */
  NULL,                                        /* exit thread */
  NULL,                                        /* exit process */
  NULL,                                        /* exit master */
  NGX_MODULE_V1_PADDING
};

static ngx_http_output_header_filter_pt  ngx_http_next_header_filter;
static ngx_http_output_body_filter_pt    ngx_http_next_body_filter;

static ngx_int_t ngx_http_#{@module_name}_header_filter(ngx_http_request_t *r)
{
  return ngx_http_next_header_filter(r);
}


static ngx_int_t ngx_http_#{@module_name}_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
  return ngx_http_next_body_filter(r, in);
}

static ngx_int_t ngx_http_#{@module_name}_filter_init(ngx_conf_t *cf)
{
  ngx_http_next_header_filter = ngx_http_top_header_filter;
  ngx_http_top_header_filter = ngx_http_#{@module_name}_header_filter;

  ngx_http_next_body_filter = ngx_http_top_body_filter;
  ngx_http_top_body_filter = ngx_http_#{@module_name}_body_filter;

  return NGX_OK;
}

EOS
end

#filter_module_nameObject



130
131
132
# File 'lib/ngxmodgen/srcgen.rb', line 130

def filter_module_name
  "ngx_http_#{@module_name}_filter_module"
end

#generateObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ngxmodgen/srcgen.rb', line 7

def generate
  <<"EOS"

#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>

static ngx_command_t ngx_http_#{@module_name}_commands[] = {
  /*
  {
      ngx_string("command_name"),
      NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
      NULL,
      0,
      0,
      NULL
  },
  */
  ngx_null_command
};

static ngx_http_module_t ngx_http_#{@module_name}_module_ctx = {
  NULL,                              /* preconfiguration */
  NULL,                              /* postconfiguration */

  NULL,                              /* create main configuration */
  NULL,                              /* init main configuration */

  NULL,                              /* create server configuration */
  NULL,                              /* merge server configuration */

  NULL,                              /* create location configuration */
  NULL                               /* merge location configuration */
};

ngx_module_t ngx_http_#{@module_name}_module = {
  NGX_MODULE_V1,
  &ngx_http_#{@module_name}_module_ctx, /* module context */
  ngx_http_#{@module_name}_commands,    /* module directives */
  NGX_HTTP_MODULE,                      /* module type */
  NULL,                                 /* init master */
  NULL,                                 /* init module */
  NULL,                                 /* init process */
  NULL,                                 /* init thread */
  NULL,                                 /* exit thread */
  NULL,                                 /* exit process */
  NULL,                                 /* exit master */
  NGX_MODULE_V1_PADDING
};

EOS
end

#module_nameObject



126
127
128
# File 'lib/ngxmodgen/srcgen.rb', line 126

def module_name
  "ngx_http_#{@module_name}_module"
end