Mercurial > hg > nginx
comparison src/http/ngx_http_config.c @ 42:cd035a94e0b6
nginx-0.0.1-2002-12-27-10:27:47 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 27 Dec 2002 07:27:47 +0000 |
parents | 59e7c7f30d49 |
children | 53cd05892261 |
comparison
equal
deleted
inserted
replaced
41:59e7c7f30d49 | 42:cd035a94e0b6 |
---|---|
14 void **ngx_srv_conf; | 14 void **ngx_srv_conf; |
15 void **ngx_loc_conf; | 15 void **ngx_loc_conf; |
16 /**/ | 16 /**/ |
17 | 17 |
18 | 18 |
19 static int ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy); | 19 static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy); |
20 | 20 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy); |
21 | 21 |
22 void *null_loc_conf; | 22 |
23 void **null_loc_conf; | |
23 | 24 |
24 | 25 |
25 static ngx_command_t ngx_http_commands[] = { | 26 static ngx_command_t ngx_http_commands[] = { |
26 | 27 |
27 {ngx_string("http"), | 28 {ngx_string("http"), |
32 | 33 |
33 {ngx_string(""), 0, NULL, 0, 0} | 34 {ngx_string(""), 0, NULL, 0, 0} |
34 }; | 35 }; |
35 | 36 |
36 | 37 |
37 static ngx_http_module_t ngx_http_module_ctx = { | 38 ngx_module_t ngx_http_module = { |
39 NULL, /* module context */ | |
40 ngx_http_commands, /* module directives */ | |
41 0, /* module type */ | |
42 NULL /* init module */ | |
43 }; | |
44 | |
45 static ngx_command_t ngx_http_core_commands[] = { | |
46 | |
47 {ngx_string("server"), | |
48 NGX_CONF_BLOCK|NGX_CONF_NOARGS, | |
49 ngx_server_block, | |
50 NGX_HTTP_MODULE_TYPE, | |
51 0}, | |
52 | |
53 {ngx_string(""), 0, NULL, 0, 0} | |
54 }; | |
55 | |
56 | |
57 static ngx_http_module_t ngx_http_core_module_ctx = { | |
38 NGX_HTTP_MODULE, | 58 NGX_HTTP_MODULE, |
39 | 59 |
40 NULL, /* create server config */ | 60 NULL, /* create server config */ |
61 NULL, /* init server config */ | |
41 NULL, /* create location config */ | 62 NULL, /* create location config */ |
63 NULL, /* merge location config */ | |
42 | 64 |
43 NULL, /* translate handler */ | 65 NULL, /* translate handler */ |
44 | 66 |
45 NULL, /* output header filter */ | 67 NULL, /* output header filter */ |
46 NULL, /* next output header filter */ | 68 NULL, /* next output header filter */ |
47 NULL, /* output body filter */ | 69 NULL, /* output body filter */ |
48 NULL /* next output body filter */ | 70 NULL /* next output body filter */ |
49 }; | 71 }; |
50 | 72 |
51 | 73 |
52 ngx_module_t ngx_http_module = { | 74 ngx_module_t ngx_http_core_module = { |
53 &ngx_http_module_ctx, /* module context */ | 75 &ngx_http_core_module_ctx, /* module context */ |
54 ngx_http_commands, /* module directives */ | 76 ngx_http_core_commands, /* module directives */ |
55 0, /* module type */ | 77 NGX_HTTP_MODULE_TYPE, /* module type */ |
56 NULL /* init module */ | 78 NULL /* init module */ |
57 }; | 79 }; |
58 | 80 |
59 | 81 |
60 static int ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy) | 82 static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy) |
61 { | 83 { |
62 int i, j; | 84 int i; |
63 ngx_http_module_t *module; | 85 ngx_http_module_t *module; |
64 ngx_http_conf_ctx_t *ctx; | 86 ngx_http_conf_ctx_t *ctx; |
65 | 87 |
66 for (i = 0; ngx_modules[i]; i++) { | 88 for (i = 0; ngx_modules[i]; i++) { |
67 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { | 89 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { |
68 continue; | 90 continue; |
69 } | 91 } |
70 | 92 |
71 module = (ngx_http_module_t *) ngx_modules[i]->ctx; | 93 module = (ngx_http_module_t *) ngx_modules[i]->ctx; |
72 module->index = i; | 94 module->index = ngx_http_max_module++; |
73 } | 95 } |
74 | |
75 ngx_http_max_module = i; | |
76 | 96 |
77 ngx_test_null(null_loc_conf, | 97 ngx_test_null(null_loc_conf, |
78 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), | 98 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), |
79 NGX_ERROR); | 99 NGX_CONF_ERROR); |
80 | 100 |
81 ctx->srv_conf = NULL; | 101 ctx->srv_conf = NULL; |
82 ctx->loc_conf = null_loc_conf; | 102 ctx->loc_conf = null_loc_conf; |
83 | 103 ctx->locations = NULL; |
84 for (i = 0, j = 0; ngx_modules[i]; i++) { | 104 |
105 for (i = 0; ngx_modules[i]; i++) { | |
85 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { | 106 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { |
86 continue; | 107 continue; |
87 } | 108 } |
88 | 109 |
89 module = (ngx_http_module_t *) ngx_modules[i]->ctx; | 110 module = (ngx_http_module_t *) ngx_modules[i]->ctx; |
90 module->index = i; | 111 |
91 if (module->create_loc_conf) { | 112 if (module->create_loc_conf) { |
92 ngx_test_null(null_loc_conf, | 113 ngx_test_null(null_loc_conf[module->index], |
93 module->create_loc_conf(cf->pool), | 114 module->create_loc_conf(cf->pool), |
94 NGX_ERROR); | 115 NGX_CONF_ERROR); |
95 j++; | |
96 } | 116 } |
97 } | 117 } |
98 | 118 |
99 cf->ctx = ctx; | 119 cf->ctx = ctx; |
100 cf->type = NGX_HTTP_MODULE_TYPE; | 120 cf->type = NGX_HTTP_MODULE_TYPE; |
101 return ngx_conf_parse(cf, NULL); | 121 return ngx_conf_parse(cf, NULL); |
102 } | 122 } |
103 | 123 |
104 | 124 |
105 #if 0 | 125 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy) |
106 int ngx_server_block(ngx_conf_t *cf) | 126 { |
107 { | 127 int i, j; |
108 ngx_http_conf_ctx_t *ctx, *prev; | 128 char *rv; |
129 void ***loc_conf; /* YES! 3 stars */ | |
130 ngx_http_module_t *module; | |
131 ngx_http_conf_ctx_t *ctx, *prev; | |
109 | 132 |
110 ngx_test_null(ctx, | 133 ngx_test_null(ctx, |
111 ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), | 134 ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), |
112 NGX_ERROR); | 135 NGX_CONF_ERROR); |
113 | 136 |
114 /* server config */ | 137 /* server config */ |
115 ngx_test_null(ctx->srv_conf, | 138 ngx_test_null(ctx->srv_conf, |
116 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_max_module), | 139 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), |
117 NGX_ERROR); | 140 NGX_CONF_ERROR); |
118 | 141 |
119 /* server location config */ | 142 /* server location config */ |
120 ngx_test_null(ctx->loc_conf, | 143 ngx_test_null(ctx->loc_conf, |
121 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_max_module), | 144 ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), |
122 NGX_ERROR); | 145 NGX_CONF_ERROR); |
123 | 146 |
124 | 147 for (i = 0; ngx_modules[i]; i++) { |
125 for (i = 0; modules[i]; i++) { | 148 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { |
126 if (modules[i]->create_srv_conf) | 149 continue; |
127 ngx_test_null(ctx->srv_conf[i], | 150 } |
128 modules[i]->create_srv_conf(cf->pool), | 151 |
129 NGX_ERROR); | 152 module = (ngx_http_module_t *) ngx_modules[i]->ctx; |
130 | 153 |
131 if (modules[i]->create_loc_conf) | 154 if (module->create_srv_conf) { |
132 ngx_test_null(ctx->loc_conf[i], | 155 ngx_test_null(ctx->srv_conf[module->index], |
133 modules[i]->create_loc_conf(cf->pool), | 156 module->create_srv_conf(cf->pool), |
134 NGX_ERROR); | 157 NGX_CONF_ERROR); |
158 } | |
159 | |
160 if (module->create_loc_conf) { | |
161 ngx_test_null(ctx->loc_conf[module->index], | |
162 module->create_loc_conf(cf->pool), | |
163 NGX_CONF_ERROR); | |
164 } | |
135 } | 165 } |
136 | 166 |
137 prev = cf->ctx; | 167 prev = cf->ctx; |
138 cf->ctx = ctx; | 168 cf->ctx = ctx; |
139 rc = ngx_conf_parse(cf); | 169 rv = ngx_conf_parse(cf, NULL); |
140 cf->ctx = prev; | 170 cf->ctx = prev; |
141 | 171 |
142 if (loc == NGX_ERROR) | 172 if (rv != NULL) |
143 return NGX_ERROR; | 173 return rv; |
144 | 174 |
145 for (i = 0; modules[i]; i++) { | 175 for (i = 0; ngx_modules[i]; i++) { |
176 if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) { | |
177 continue; | |
178 } | |
179 | |
180 module = (ngx_http_module_t *) ngx_modules[i]->ctx; | |
181 | |
182 if (module->init_srv_conf) { | |
183 if (module->init_srv_conf(cf->pool, | |
184 ctx->srv_conf[module->index]) | |
185 == NGX_CONF_ERROR) { | |
186 return NGX_CONF_ERROR; | |
187 } | |
188 } | |
189 | |
190 if (module->merge_loc_conf) { | |
191 if (module->merge_loc_conf(cf->pool, | |
192 prev->loc_conf[module->index], | |
193 ctx->loc_conf[module->index]) | |
194 == NGX_CONF_ERROR) { | |
195 return NGX_CONF_ERROR; | |
196 } | |
197 | |
198 loc_conf = (void ***)ctx->locations->elts; | |
199 for (j = 0; j < ctx->locations->nelts; j++) { | |
200 if (module->merge_loc_conf(cf->pool, | |
201 ctx->loc_conf[module->index], | |
202 loc_conf[j][module->index]) | |
203 == NGX_CONF_ERROR) { | |
204 return NGX_CONF_ERROR; | |
205 } | |
206 } | |
207 } | |
208 } | |
209 | |
210 return NULL; | |
211 } | |
212 | |
213 | |
146 #if 0 | 214 #if 0 |
147 if (modules[i]->merge_srv_conf) | |
148 if (modules[i]->merge_srv_conf(cf->pool, | |
149 prev->srv_conf, ctx->srv_conf) | |
150 == NGX_ERROR) | |
151 return NGX_ERROR; | |
152 #endif | |
153 | |
154 if (modules[i]->init_srv_conf) | |
155 if (modules[i]->init_srv_conf(cf->pool, ctx->srv_conf) == NGX_ERROR) | |
156 return NGX_ERROR; | |
157 | |
158 if (modules[i]->merge_loc_conf) | |
159 if (modules[i]->merge_loc_conf(cf->pool, | |
160 prev->loc_conf, ctx->loc_conf) | |
161 == NGX_ERROR) | |
162 return NGX_ERROR; | |
163 | |
164 for (array) { | |
165 if (modules[i]->merge_loc_conf(cf->pool, | |
166 ctx->loc_conf, loc->loc_conf) | |
167 == NGX_ERROR) | |
168 return NGX_ERROR; | |
169 } | |
170 } | |
171 } | |
172 | |
173 return NGX_OK; | |
174 } | |
175 | |
176 int ngx_location_block(ngx_conf_t *cf) | 215 int ngx_location_block(ngx_conf_t *cf) |
177 { | 216 { |
178 ngx_http_conf_ctx_t *ctx, *prev; | 217 ngx_http_conf_ctx_t *ctx, *prev; |
179 | 218 |
180 ngx_test_null(ctx, ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), | 219 ngx_test_null(ctx, ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), |