comparison ngx_http_compose_filter_module.c @ 0:6535d94ae07d

Compose filter module skeleton, currently does nothing.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 12 Jul 2008 19:23:17 +0400
parents
children ba5471a3c988
comparison
equal deleted inserted replaced
-1:000000000000 0:6535d94ae07d
1
2 /*
3 * Copyright (C) Maxim Dounin
4 */
5
6 #include <ngx_config.h>
7 #include <ngx_core.h>
8 #include <ngx_http.h>
9
10
11 typedef struct {
12 ngx_flag_t enable;
13 } ngx_http_compose_conf_t;
14
15
16 static void *ngx_http_compose_create_conf(ngx_conf_t *cf);
17 static char *ngx_http_compose_merge_conf(ngx_conf_t *cf, void *parent,
18 void *child);
19 static ngx_int_t ngx_http_compose_init(ngx_conf_t *cf);
20
21
22 static ngx_command_t ngx_http_compose_commands[] = {
23
24 { ngx_string("compose"),
25 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
26 ngx_conf_set_flag_slot,
27 NGX_HTTP_LOC_CONF_OFFSET,
28 offsetof(ngx_http_compose_conf_t, enable),
29 NULL },
30
31 ngx_null_command
32 };
33
34
35 static ngx_http_module_t ngx_http_compose_module_ctx = {
36 NULL, /* preconfiguration */
37 ngx_http_compose_init, /* postconfiguration */
38
39 NULL, /* create main configuration */
40 NULL, /* init main configuration */
41
42 NULL, /* create server configuration */
43 NULL, /* merge server configuration */
44
45 ngx_http_compose_create_conf, /* create location configuration */
46 ngx_http_compose_merge_conf /* merge location configuration */
47 };
48
49
50 ngx_module_t ngx_http_compose_filter_module = {
51 NGX_MODULE_V1,
52 &ngx_http_compose_module_ctx, /* module context */
53 ngx_http_compose_commands, /* module directives */
54 NGX_HTTP_MODULE, /* module type */
55 NULL, /* init master */
56 NULL, /* init module */
57 NULL, /* init process */
58 NULL, /* init thread */
59 NULL, /* exit thread */
60 NULL, /* exit process */
61 NULL, /* exit master */
62 NGX_MODULE_V1_PADDING
63 };
64
65
66 static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
67 static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
68
69
70 static ngx_int_t
71 ngx_http_compose_header_filter(ngx_http_request_t *r)
72 {
73 ngx_http_compose_conf_t *conf;
74
75 conf = ngx_http_get_module_loc_conf(r, ngx_http_compose_filter_module);
76
77 if (!conf->enable) {
78 return ngx_http_next_header_filter(r);
79 }
80
81 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
82 "compose header filter");
83
84 return ngx_http_next_header_filter(r);
85 }
86
87
88 static ngx_int_t
89 ngx_http_compose_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
90 {
91 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
92 "compose body filter");
93
94 return ngx_http_next_body_filter(r, in);
95 }
96
97
98 static void *
99 ngx_http_compose_create_conf(ngx_conf_t *cf)
100 {
101 ngx_http_compose_conf_t *conf;
102
103 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_compose_conf_t));
104 if (conf == NULL) {
105 return NGX_CONF_ERROR;
106 }
107
108 conf->enable = NGX_CONF_UNSET;
109
110 return conf;
111 }
112
113
114 static char *
115 ngx_http_compose_merge_conf(ngx_conf_t *cf, void *parent, void *child)
116 {
117 ngx_http_compose_conf_t *prev = parent;
118 ngx_http_compose_conf_t *conf = child;
119
120 ngx_conf_merge_value(conf->enable, prev->enable, 0);
121
122 return NGX_CONF_OK;
123 }
124
125
126 static ngx_int_t
127 ngx_http_compose_init(ngx_conf_t *cf)
128 {
129 ngx_http_next_header_filter = ngx_http_top_header_filter;
130 ngx_http_top_header_filter = ngx_http_compose_header_filter;
131
132 ngx_http_next_body_filter = ngx_http_top_body_filter;
133 ngx_http_top_body_filter = ngx_http_compose_body_filter;
134
135 return NGX_OK;
136 }