Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1 | |
| 2 | #include <ngx_config.h> |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 3 | #include <ngx_core.h> |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 4 | #include <ngx_event.h> |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 5 | #include <ngx_http.h> |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 6 | #include <nginx.h> |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 7 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 8 | |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 9 | static void ngx_http_phase_event_handler(ngx_event_t *rev); |
| 10 | static void ngx_http_run_phases(ngx_http_request_t *r); |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 11 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 12 | static void *ngx_http_core_create_main_conf(ngx_conf_t *cf); |
| 13 | static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf); |
| 14 | static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf); |
| 15 | static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 16 | void *parent, void *child); |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 17 | static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf); |
| 18 | static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 19 | void *parent, void *child); |
Igor Sysoev | dc479b4 | 2003-03-20 16:09:44 +0000 | [diff] [blame] | 20 | |
Igor Sysoev | 340b03b | 2003-07-04 15:10:33 +0000 | [diff] [blame] | 21 | static int ngx_http_core_init(ngx_cycle_t *cycle); |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 22 | static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy); |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 23 | static int ngx_cmp_locations(const void *first, const void *second); |
Igor Sysoev | dc479b4 | 2003-03-20 16:09:44 +0000 | [diff] [blame] | 24 | static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 25 | void *dummy); |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 26 | static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 27 | static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf); |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 28 | static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 29 | static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 30 | void *conf); |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 31 | static char *ngx_set_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 32 | static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 33 | static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 34 | |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 35 | static char *ngx_http_lowat_check(ngx_conf_t *cf, void *post, void *data); |
| 36 | |
| 37 | static ngx_conf_post_t ngx_http_lowat_post = { ngx_http_lowat_check } ; |
| 38 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 39 | |
| 40 | static ngx_command_t ngx_http_core_commands[] = { |
| 41 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 42 | { ngx_string("server"), |
| 43 | NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, |
| 44 | ngx_server_block, |
| 45 | 0, |
| 46 | 0, |
| 47 | NULL }, |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 48 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 49 | { ngx_string("connection_pool_size"), |
| 50 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
| 51 | ngx_conf_set_size_slot, |
| 52 | NGX_HTTP_SRV_CONF_OFFSET, |
| 53 | offsetof(ngx_http_core_srv_conf_t, connection_pool_size), |
| 54 | NULL }, |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 55 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 56 | { ngx_string("post_accept_timeout"), |
| 57 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
| 58 | ngx_conf_set_msec_slot, |
| 59 | NGX_HTTP_SRV_CONF_OFFSET, |
| 60 | offsetof(ngx_http_core_srv_conf_t, post_accept_timeout), |
| 61 | NULL }, |
Igor Sysoev | 187fcd8 | 2003-05-23 11:53:01 +0000 | [diff] [blame] | 62 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 63 | { ngx_string("request_pool_size"), |
| 64 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
| 65 | ngx_conf_set_size_slot, |
| 66 | NGX_HTTP_SRV_CONF_OFFSET, |
| 67 | offsetof(ngx_http_core_srv_conf_t, request_pool_size), |
| 68 | NULL }, |
Igor Sysoev | 187fcd8 | 2003-05-23 11:53:01 +0000 | [diff] [blame] | 69 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 70 | { ngx_string("client_header_timeout"), |
| 71 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
| 72 | ngx_conf_set_msec_slot, |
| 73 | NGX_HTTP_SRV_CONF_OFFSET, |
| 74 | offsetof(ngx_http_core_srv_conf_t, client_header_timeout), |
| 75 | NULL }, |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 76 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 77 | { ngx_string("client_header_buffer_size"), |
| 78 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
| 79 | ngx_conf_set_size_slot, |
| 80 | NGX_HTTP_SRV_CONF_OFFSET, |
| 81 | offsetof(ngx_http_core_srv_conf_t, client_header_buffer_size), |
| 82 | NULL }, |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 83 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 84 | { ngx_string("large_client_header"), |
| 85 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG, |
| 86 | ngx_conf_set_flag_slot, |
| 87 | NGX_HTTP_SRV_CONF_OFFSET, |
| 88 | offsetof(ngx_http_core_srv_conf_t, large_client_header), |
| 89 | NULL }, |
Igor Sysoev | 6a644c6 | 2003-03-04 06:33:48 +0000 | [diff] [blame] | 90 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 91 | { ngx_string("location"), |
| 92 | NGX_HTTP_SRV_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12, |
| 93 | ngx_location_block, |
| 94 | NGX_HTTP_SRV_CONF_OFFSET, |
| 95 | 0, |
| 96 | NULL }, |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 97 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 98 | { ngx_string("listen"), |
Igor Sysoev | 7578ec9 | 2003-06-02 15:24:30 +0000 | [diff] [blame] | 99 | #if 0 |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 100 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
Igor Sysoev | 7578ec9 | 2003-06-02 15:24:30 +0000 | [diff] [blame] | 101 | #else |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 102 | NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
Igor Sysoev | 7578ec9 | 2003-06-02 15:24:30 +0000 | [diff] [blame] | 103 | #endif |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 104 | ngx_set_listen, |
| 105 | NGX_HTTP_SRV_CONF_OFFSET, |
| 106 | 0, |
| 107 | NULL }, |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 108 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 109 | { ngx_string("server_name"), |
| 110 | NGX_HTTP_SRV_CONF|NGX_CONF_1MORE, |
| 111 | ngx_set_server_name, |
| 112 | NGX_HTTP_SRV_CONF_OFFSET, |
| 113 | 0, |
| 114 | NULL }, |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 115 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 116 | { ngx_string("types"), |
| 117 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF |
| 118 | |NGX_CONF_BLOCK|NGX_CONF_NOARGS, |
| 119 | ngx_types_block, |
| 120 | NGX_HTTP_LOC_CONF_OFFSET, |
| 121 | 0, |
| 122 | NULL }, |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 123 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 124 | { ngx_string("default_type"), |
| 125 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
| 126 | ngx_conf_set_str_slot, |
| 127 | NGX_HTTP_LOC_CONF_OFFSET, |
| 128 | offsetof(ngx_http_core_loc_conf_t, default_type), |
| 129 | NULL }, |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 130 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 131 | { ngx_string("root"), |
| 132 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 133 | ngx_set_root, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 134 | NGX_HTTP_LOC_CONF_OFFSET, |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 135 | 0, |
| 136 | NULL }, |
| 137 | |
| 138 | { ngx_string("alias"), |
| 139 | NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
| 140 | ngx_set_root, |
| 141 | NGX_HTTP_LOC_CONF_OFFSET, |
| 142 | 0, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 143 | NULL }, |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 144 | |
Igor Sysoev | ae02c19 | 2004-03-19 05:25:53 +0000 | [diff] [blame] | 145 | { ngx_string("client_max_body_size"), |
| 146 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
| 147 | ngx_conf_set_size_slot, |
| 148 | NGX_HTTP_LOC_CONF_OFFSET, |
| 149 | offsetof(ngx_http_core_loc_conf_t, client_max_body_size), |
| 150 | NULL }, |
| 151 | |
Igor Sysoev | dbb2776 | 2004-04-01 16:20:53 +0000 | [diff] [blame] | 152 | { ngx_string("client_body_buffer_size"), |
| 153 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
| 154 | ngx_conf_set_size_slot, |
| 155 | NGX_HTTP_LOC_CONF_OFFSET, |
| 156 | offsetof(ngx_http_core_loc_conf_t, client_body_buffer_size), |
| 157 | NULL }, |
| 158 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 159 | { ngx_string("client_body_timeout"), |
| 160 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
| 161 | ngx_conf_set_msec_slot, |
| 162 | NGX_HTTP_LOC_CONF_OFFSET, |
| 163 | offsetof(ngx_http_core_loc_conf_t, client_body_timeout), |
| 164 | NULL }, |
Igor Sysoev | 2b0c76c | 2003-10-27 21:01:00 +0000 | [diff] [blame] | 165 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 166 | { ngx_string("sendfile"), |
| 167 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
| 168 | ngx_conf_set_flag_slot, |
| 169 | NGX_HTTP_LOC_CONF_OFFSET, |
| 170 | offsetof(ngx_http_core_loc_conf_t, sendfile), |
| 171 | NULL }, |
Igor Sysoev | 5bf3d25 | 2003-10-22 07:05:29 +0000 | [diff] [blame] | 172 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 173 | { ngx_string("tcp_nopush"), |
| 174 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
| 175 | ngx_conf_set_flag_slot, |
| 176 | NGX_HTTP_LOC_CONF_OFFSET, |
| 177 | offsetof(ngx_http_core_loc_conf_t, tcp_nopush), |
| 178 | NULL }, |
| 179 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 180 | { ngx_string("send_timeout"), |
| 181 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
| 182 | ngx_conf_set_msec_slot, |
| 183 | NGX_HTTP_LOC_CONF_OFFSET, |
| 184 | offsetof(ngx_http_core_loc_conf_t, send_timeout), |
| 185 | NULL }, |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 186 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 187 | { ngx_string("send_lowat"), |
| 188 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
| 189 | ngx_conf_set_size_slot, |
| 190 | NGX_HTTP_LOC_CONF_OFFSET, |
| 191 | offsetof(ngx_http_core_loc_conf_t, send_lowat), |
| 192 | &ngx_http_lowat_post }, |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 193 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 194 | { ngx_string("keepalive_timeout"), |
| 195 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
| 196 | ngx_conf_set_msec_slot, |
| 197 | NGX_HTTP_LOC_CONF_OFFSET, |
| 198 | offsetof(ngx_http_core_loc_conf_t, keepalive_timeout), |
| 199 | NULL }, |
Igor Sysoev | fa73aac | 2003-05-21 13:28:21 +0000 | [diff] [blame] | 200 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 201 | { ngx_string("lingering_time"), |
| 202 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
| 203 | ngx_conf_set_msec_slot, |
| 204 | NGX_HTTP_LOC_CONF_OFFSET, |
| 205 | offsetof(ngx_http_core_loc_conf_t, lingering_time), |
| 206 | NULL }, |
Igor Sysoev | b738757 | 2003-03-11 20:38:13 +0000 | [diff] [blame] | 207 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 208 | { ngx_string("lingering_timeout"), |
| 209 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
| 210 | ngx_conf_set_msec_slot, |
| 211 | NGX_HTTP_LOC_CONF_OFFSET, |
| 212 | offsetof(ngx_http_core_loc_conf_t, lingering_timeout), |
| 213 | NULL }, |
Igor Sysoev | b738757 | 2003-03-11 20:38:13 +0000 | [diff] [blame] | 214 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 215 | { ngx_string("msie_padding"), |
| 216 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
| 217 | ngx_conf_set_flag_slot, |
| 218 | NGX_HTTP_LOC_CONF_OFFSET, |
| 219 | offsetof(ngx_http_core_loc_conf_t, msie_padding), |
| 220 | NULL }, |
Igor Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 221 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 222 | { ngx_string("error_page"), |
| 223 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE, |
| 224 | ngx_set_error_page, |
| 225 | NGX_HTTP_LOC_CONF_OFFSET, |
| 226 | 0, |
| 227 | NULL }, |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 228 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 229 | { ngx_string("error_log"), |
Igor Sysoev | 03420a6 | 2004-01-20 20:40:08 +0000 | [diff] [blame] | 230 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 231 | ngx_set_error_log, |
| 232 | NGX_HTTP_LOC_CONF_OFFSET, |
| 233 | 0, |
| 234 | NULL }, |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 235 | |
Igor Sysoev | 67f88e9 | 2004-03-12 16:57:08 +0000 | [diff] [blame] | 236 | #if (NGX_HTTP_CACHE) |
| 237 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 238 | { ngx_string("open_file_cache"), |
| 239 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE4, |
| 240 | ngx_http_set_cache_slot, |
| 241 | NGX_HTTP_LOC_CONF_OFFSET, |
| 242 | offsetof(ngx_http_core_loc_conf_t, open_files), |
| 243 | NULL }, |
| 244 | |
Igor Sysoev | 67f88e9 | 2004-03-12 16:57:08 +0000 | [diff] [blame] | 245 | #endif |
| 246 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 247 | ngx_null_command |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 248 | }; |
| 249 | |
| 250 | |
| 251 | ngx_http_module_t ngx_http_core_module_ctx = { |
Igor Sysoev | 7832933 | 2003-11-10 17:17:31 +0000 | [diff] [blame] | 252 | NULL, /* pre conf */ |
| 253 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 254 | ngx_http_core_create_main_conf, /* create main configuration */ |
| 255 | ngx_http_core_init_main_conf, /* init main configuration */ |
Igor Sysoev | dc479b4 | 2003-03-20 16:09:44 +0000 | [diff] [blame] | 256 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 257 | ngx_http_core_create_srv_conf, /* create server configuration */ |
| 258 | ngx_http_core_merge_srv_conf, /* merge server configuration */ |
| 259 | |
| 260 | ngx_http_core_create_loc_conf, /* create location configuration */ |
| 261 | ngx_http_core_merge_loc_conf /* merge location configuration */ |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | |
| 265 | ngx_module_t ngx_http_core_module = { |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 266 | NGX_MODULE, |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 267 | &ngx_http_core_module_ctx, /* module context */ |
| 268 | ngx_http_core_commands, /* module directives */ |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 269 | NGX_HTTP_MODULE, /* module type */ |
Igor Sysoev | 96c56c9 | 2003-07-02 14:41:17 +0000 | [diff] [blame] | 270 | ngx_http_core_init, /* init module */ |
Igor Sysoev | 340b03b | 2003-07-04 15:10:33 +0000 | [diff] [blame] | 271 | NULL /* init child */ |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 272 | }; |
| 273 | |
| 274 | |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 275 | void ngx_http_handler(ngx_http_request_t *r) |
| 276 | { |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 277 | ngx_http_log_ctx_t *lcx; |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 278 | |
| 279 | r->connection->unexpected_eof = 0; |
| 280 | |
Igor Sysoev | 7578ec9 | 2003-06-02 15:24:30 +0000 | [diff] [blame] | 281 | lcx = r->connection->log->data; |
| 282 | lcx->action = NULL; |
| 283 | |
Igor Sysoev | 419f9ac | 2003-10-21 16:49:56 +0000 | [diff] [blame] | 284 | switch (r->headers_in.connection_type) { |
| 285 | case 0: |
| 286 | if (r->http_version > NGX_HTTP_VERSION_10) { |
| 287 | r->keepalive = 1; |
| 288 | } else { |
Igor Sysoev | 9760a13 | 2003-10-21 07:47:21 +0000 | [diff] [blame] | 289 | r->keepalive = 0; |
| 290 | } |
Igor Sysoev | 419f9ac | 2003-10-21 16:49:56 +0000 | [diff] [blame] | 291 | break; |
| 292 | |
| 293 | case NGX_HTTP_CONNECTION_CLOSE: |
| 294 | r->keepalive = 0; |
| 295 | break; |
| 296 | |
| 297 | case NGX_HTTP_CONNECTION_KEEP_ALIVE: |
| 298 | r->keepalive = 1; |
| 299 | break; |
Igor Sysoev | 9760a13 | 2003-10-21 07:47:21 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Igor Sysoev | 10fc9ef | 2003-10-27 08:53:49 +0000 | [diff] [blame] | 302 | #if 0 |
Igor Sysoev | dc9dd43 | 2003-10-22 16:38:26 +0000 | [diff] [blame] | 303 | /* TEST STUB */ r->http_version = NGX_HTTP_VERSION_10; |
Igor Sysoev | 9760a13 | 2003-10-21 07:47:21 +0000 | [diff] [blame] | 304 | /* TEST STUB */ r->keepalive = 0; |
| 305 | #endif |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 306 | |
| 307 | if (r->headers_in.content_length_n > 0) { |
| 308 | r->lingering_close = 1; |
Igor Sysoev | 9760a13 | 2003-10-21 07:47:21 +0000 | [diff] [blame] | 309 | |
| 310 | } else { |
| 311 | r->lingering_close = 0; |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Igor Sysoev | 9760a13 | 2003-10-21 07:47:21 +0000 | [diff] [blame] | 314 | #if 0 |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 315 | /* TEST STUB */ r->lingering_close = 1; |
Igor Sysoev | 9760a13 | 2003-10-21 07:47:21 +0000 | [diff] [blame] | 316 | #endif |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 317 | |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 318 | r->connection->write->event_handler = ngx_http_phase_event_handler; |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 319 | |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 320 | ngx_http_run_phases(r); |
| 321 | |
| 322 | return; |
| 323 | } |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 324 | |
| 325 | |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 326 | static void ngx_http_phase_event_handler(ngx_event_t *ev) |
| 327 | { |
| 328 | ngx_connection_t *c; |
| 329 | ngx_http_request_t *r; |
| 330 | |
| 331 | c = ev->data; |
| 332 | r = c->data; |
| 333 | |
Igor Sysoev | 54498db | 2004-02-11 17:08:49 +0000 | [diff] [blame] | 334 | ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, "phase event handler"); |
Igor Sysoev | 0a280a3 | 2003-10-12 16:49:16 +0000 | [diff] [blame] | 335 | |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 336 | ngx_http_run_phases(r); |
| 337 | |
| 338 | return; |
| 339 | } |
| 340 | |
| 341 | |
| 342 | static void ngx_http_run_phases(ngx_http_request_t *r) |
| 343 | { |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 344 | char *path; |
| 345 | ngx_int_t rc; |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 346 | ngx_http_handler_pt *h; |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 347 | ngx_http_core_loc_conf_t *clcf; |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 348 | ngx_http_core_main_conf_t *cmcf; |
| 349 | |
| 350 | cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); |
| 351 | |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 352 | for (/* void */; r->phase < NGX_HTTP_LAST_PHASE; r->phase++) { |
| 353 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 354 | if (r->phase == NGX_HTTP_CONTENT_PHASE && r->content_handler) { |
| 355 | r->connection->write->event_handler = ngx_http_empty_handler; |
| 356 | rc = r->content_handler(r); |
| 357 | ngx_http_finalize_request(r, rc); |
| 358 | return; |
| 359 | } |
| 360 | |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 361 | h = cmcf->phases[r->phase].handlers.elts; |
| 362 | for (r->phase_handler = cmcf->phases[r->phase].handlers.nelts - 1; |
| 363 | r->phase_handler >= 0; |
| 364 | r->phase_handler--) |
| 365 | { |
| 366 | rc = h[r->phase_handler](r); |
| 367 | |
Igor Sysoev | 9760a13 | 2003-10-21 07:47:21 +0000 | [diff] [blame] | 368 | if (rc == NGX_DONE) { |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 369 | |
| 370 | /* |
| 371 | * we should never use r here because |
| 372 | * it could point to already freed data |
| 373 | */ |
| 374 | |
Igor Sysoev | 9760a13 | 2003-10-21 07:47:21 +0000 | [diff] [blame] | 375 | return; |
| 376 | } |
| 377 | |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 378 | if (rc == NGX_DECLINED) { |
| 379 | continue; |
| 380 | } |
| 381 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 382 | if (rc >= NGX_HTTP_SPECIAL_RESPONSE || rc == NGX_ERROR) { |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 383 | ngx_http_finalize_request(r, rc); |
| 384 | return; |
| 385 | } |
| 386 | |
Igor Sysoev | e3466a4 | 2003-12-15 13:57:13 +0000 | [diff] [blame] | 387 | if (r->phase == NGX_HTTP_CONTENT_PHASE) { |
| 388 | ngx_http_finalize_request(r, rc); |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | if (rc == NGX_AGAIN) { |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 393 | return; |
| 394 | } |
| 395 | |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 396 | if (rc == NGX_OK && cmcf->phases[r->phase].type == NGX_OK) { |
| 397 | break; |
| 398 | } |
| 399 | } |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 402 | |
| 403 | if (r->uri.data[r->uri.len - 1] == '/') { |
| 404 | |
| 405 | clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
| 406 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 407 | if (!(path = ngx_palloc(r->pool, clcf->root.len + r->uri.len))) { |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 408 | ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
| 409 | return; |
| 410 | } |
| 411 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 412 | ngx_cpystrn(ngx_cpymem(path, clcf->root.data, clcf->root.len), |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 413 | r->uri.data, r->uri.len + 1); |
| 414 | |
| 415 | ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
| 416 | "directory index of \"%s\" is forbidden", path); |
| 417 | |
| 418 | ngx_http_finalize_request(r, NGX_HTTP_FORBIDDEN); |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 419 | return; |
| 420 | } |
| 421 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 422 | ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no handler found"); |
| 423 | |
| 424 | ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND); |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 425 | return; |
| 426 | } |
| 427 | |
| 428 | |
| 429 | int ngx_http_find_location_config(ngx_http_request_t *r) |
| 430 | { |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 431 | int rc; |
Igor Sysoev | 11dbe97 | 2004-03-29 17:43:58 +0000 | [diff] [blame] | 432 | ngx_uint_t i; |
Igor Sysoev | 1b138ed | 2003-11-18 21:34:08 +0000 | [diff] [blame] | 433 | ngx_str_t *auto_redirect; |
Igor Sysoev | 419f9ac | 2003-10-21 16:49:56 +0000 | [diff] [blame] | 434 | ngx_http_core_loc_conf_t *clcf, **clcfp; |
| 435 | ngx_http_core_srv_conf_t *cscf; |
Igor Sysoev | 11dbe97 | 2004-03-29 17:43:58 +0000 | [diff] [blame] | 436 | #if (HAVE_PCRE) |
| 437 | ngx_uint_t exact; |
| 438 | #endif |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 439 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 440 | cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
Igor Sysoev | 1b138ed | 2003-11-18 21:34:08 +0000 | [diff] [blame] | 441 | auto_redirect = NULL; |
Igor Sysoev | 11dbe97 | 2004-03-29 17:43:58 +0000 | [diff] [blame] | 442 | #if (HAVE_PCRE) |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 443 | exact = 0; |
Igor Sysoev | 11dbe97 | 2004-03-29 17:43:58 +0000 | [diff] [blame] | 444 | #endif |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 445 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 446 | clcfp = cscf->locations.elts; |
| 447 | for (i = 0; i < cscf->locations.nelts; i++) { |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 448 | |
Igor Sysoev | dc867cd | 2003-12-14 20:10:27 +0000 | [diff] [blame] | 449 | #if (HAVE_PCRE) |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 450 | |
| 451 | if (clcfp[i]->regex) { |
| 452 | break; |
| 453 | } |
Igor Sysoev | dc867cd | 2003-12-14 20:10:27 +0000 | [diff] [blame] | 454 | #endif |
| 455 | |
| 456 | ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
| 457 | "find location: %s\"%s\"", |
| 458 | clcfp[i]->exact_match ? "= " : "", |
| 459 | clcfp[i]->name.data); |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 460 | |
Igor Sysoev | 1b138ed | 2003-11-18 21:34:08 +0000 | [diff] [blame] | 461 | if (clcfp[i]->auto_redirect |
| 462 | && r->uri.len == clcfp[i]->name.len - 1 |
| 463 | && ngx_strncmp(r->uri.data, clcfp[i]->name.data, |
| 464 | clcfp[i]->name.len - 1) == 0) |
| 465 | { |
| 466 | auto_redirect = &clcfp[i]->name; |
| 467 | continue; |
| 468 | } |
| 469 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 470 | if (r->uri.len < clcfp[i]->name.len) { |
| 471 | continue; |
| 472 | } |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 473 | |
Igor Sysoev | 6597749 | 2003-11-02 22:56:18 +0000 | [diff] [blame] | 474 | rc = ngx_strncmp(r->uri.data, clcfp[i]->name.data, clcfp[i]->name.len); |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 475 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 476 | if (rc < 0) { |
Igor Sysoev | 1b138ed | 2003-11-18 21:34:08 +0000 | [diff] [blame] | 477 | /* locations are lexicographically sorted */ |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 478 | break; |
| 479 | } |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 480 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 481 | if (rc == 0) { |
| 482 | r->loc_conf = clcfp[i]->loc_conf; |
| 483 | clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
| 484 | r->connection->log->file = clcf->err_log->file; |
Igor Sysoev | fff3232 | 2004-04-08 15:58:25 +0000 | [diff] [blame] | 485 | if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { |
| 486 | r->connection->log->log_level = clcf->err_log->log_level; |
| 487 | } |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 488 | |
| 489 | if (clcfp[i]->exact_match && r->uri.len == clcfp[i]->name.len) { |
Igor Sysoev | 11dbe97 | 2004-03-29 17:43:58 +0000 | [diff] [blame] | 490 | #if (HAVE_PCRE) |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 491 | exact = 1; |
Igor Sysoev | 11dbe97 | 2004-03-29 17:43:58 +0000 | [diff] [blame] | 492 | #endif |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 493 | break; |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
Igor Sysoev | dc867cd | 2003-12-14 20:10:27 +0000 | [diff] [blame] | 498 | #if (HAVE_PCRE) |
| 499 | |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 500 | if (!exact && !auto_redirect) { |
| 501 | /* regex matches */ |
| 502 | |
| 503 | for (/* void */; i < cscf->locations.nelts; i++) { |
| 504 | |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 505 | if (!clcfp[i]->regex) { |
| 506 | continue; |
| 507 | } |
| 508 | |
Igor Sysoev | dc867cd | 2003-12-14 20:10:27 +0000 | [diff] [blame] | 509 | ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
| 510 | "find location: %s\"%s\"", |
| 511 | clcfp[i]->exact_match ? "= " : |
| 512 | clcfp[i]->regex ? "~ " : "", |
| 513 | clcfp[i]->name.data); |
| 514 | |
Igor Sysoev | 3b30a90 | 2003-12-25 20:26:58 +0000 | [diff] [blame] | 515 | rc = ngx_regex_exec(clcfp[i]->regex, &r->uri, NULL, 0); |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 516 | |
| 517 | if (rc == NGX_DECLINED) { |
| 518 | continue; |
| 519 | } |
| 520 | |
| 521 | if (rc < 0) { |
| 522 | ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
| 523 | ngx_regex_exec_n |
| 524 | " failed: %d on \"%s\" using \"%s\"", |
| 525 | rc, r->uri.data, clcfp[i]->name.data); |
| 526 | return NGX_HTTP_INTERNAL_SERVER_ERROR; |
| 527 | } |
| 528 | |
| 529 | /* match */ |
| 530 | |
| 531 | r->loc_conf = clcfp[i]->loc_conf; |
| 532 | clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
| 533 | r->connection->log->file = clcf->err_log->file; |
Igor Sysoev | fff3232 | 2004-04-08 15:58:25 +0000 | [diff] [blame] | 534 | if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) { |
| 535 | r->connection->log->log_level = clcf->err_log->log_level; |
| 536 | } |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 537 | |
| 538 | break; |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 539 | } |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 540 | } |
| 541 | |
Igor Sysoev | dc867cd | 2003-12-14 20:10:27 +0000 | [diff] [blame] | 542 | #endif /* HAVE_PCRE */ |
| 543 | |
Igor Sysoev | 419f9ac | 2003-10-21 16:49:56 +0000 | [diff] [blame] | 544 | clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
| 545 | |
Igor Sysoev | 5bf3d25 | 2003-10-22 07:05:29 +0000 | [diff] [blame] | 546 | if (!(ngx_io.flags & NGX_IO_SENDFILE) || !clcf->sendfile) { |
| 547 | r->sendfile = 0; |
| 548 | |
| 549 | } else { |
| 550 | r->sendfile = 1; |
| 551 | } |
| 552 | |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 553 | if (!clcf->tcp_nopush) { |
| 554 | /* disable TCP_NOPUSH/TCP_CORK use */ |
| 555 | r->connection->tcp_nopush = -1; |
| 556 | } |
| 557 | |
Igor Sysoev | 89690bf | 2004-03-23 06:01:52 +0000 | [diff] [blame] | 558 | |
| 559 | ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
| 560 | "http cl: " SIZE_T_FMT " max: " SIZE_T_FMT, |
| 561 | r->headers_in.content_length_n, |
| 562 | clcf->client_max_body_size); |
| 563 | |
| 564 | if (r->headers_in.content_length_n != -1 |
| 565 | && clcf->client_max_body_size |
| 566 | && clcf->client_max_body_size < (size_t) r->headers_in.content_length_n) |
| 567 | { |
| 568 | ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
| 569 | "client intented to send too large body: " |
| 570 | SIZE_T_FMT " bytes", |
| 571 | r->headers_in.content_length_n); |
| 572 | |
| 573 | return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE; |
| 574 | } |
| 575 | |
| 576 | |
Igor Sysoev | 1b138ed | 2003-11-18 21:34:08 +0000 | [diff] [blame] | 577 | if (auto_redirect) { |
| 578 | if (!(r->headers_out.location = |
| 579 | ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) |
| 580 | { |
| 581 | return NGX_HTTP_INTERNAL_SERVER_ERROR; |
| 582 | } |
| 583 | |
Igor Sysoev | 1b138ed | 2003-11-18 21:34:08 +0000 | [diff] [blame] | 584 | r->headers_out.location->value = *auto_redirect; |
| 585 | |
| 586 | return NGX_HTTP_MOVED_PERMANENTLY; |
| 587 | } |
| 588 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 589 | if (clcf->handler) { |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 590 | r->content_handler = clcf->handler; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 593 | return NGX_OK; |
| 594 | } |
| 595 | |
| 596 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 597 | ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r) |
| 598 | { |
| 599 | uint32_t key; |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 600 | ngx_uint_t i; |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 601 | ngx_http_type_t *type; |
| 602 | ngx_http_core_loc_conf_t *clcf; |
| 603 | |
| 604 | if (!(r->headers_out.content_type = |
| 605 | ngx_http_add_header(&r->headers_out, ngx_http_headers_out))) |
| 606 | { |
| 607 | return NGX_HTTP_INTERNAL_SERVER_ERROR; |
| 608 | } |
| 609 | |
| 610 | r->headers_out.content_type->key.len = 0; |
| 611 | r->headers_out.content_type->key.data = NULL; |
| 612 | r->headers_out.content_type->value.len = 0; |
| 613 | r->headers_out.content_type->value.data = NULL; |
| 614 | |
| 615 | clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
| 616 | |
| 617 | if (r->exten.len) { |
| 618 | #if 0 |
| 619 | key = ngx_crc(r->exten.data, r->exten.key); |
| 620 | #endif |
| 621 | ngx_http_types_hash_key(key, r->exten); |
| 622 | |
| 623 | type = clcf->types[key].elts; |
| 624 | for (i = 0; i < clcf->types[key].nelts; i++) { |
| 625 | if (r->exten.len != type[i].exten.len) { |
| 626 | continue; |
| 627 | } |
| 628 | |
| 629 | if (ngx_memcmp(r->exten.data, type[i].exten.data, r->exten.len) |
| 630 | == 0) |
| 631 | { |
| 632 | r->headers_out.content_type->value = type[i].type; |
| 633 | break; |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | if (r->headers_out.content_type->value.len == 0) { |
| 639 | r->headers_out.content_type->value = clcf->default_type; |
| 640 | } |
| 641 | |
| 642 | return NGX_OK; |
| 643 | } |
| 644 | |
| 645 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 646 | int ngx_http_send_header(ngx_http_request_t *r) |
| 647 | { |
Igor Sysoev | 10fc9ef | 2003-10-27 08:53:49 +0000 | [diff] [blame] | 648 | if (r->main) { |
| 649 | return NGX_OK; |
| 650 | } |
| 651 | |
Igor Sysoev | 27c30f9 | 2003-11-11 18:13:43 +0000 | [diff] [blame] | 652 | if (r->err_ctx) { |
Igor Sysoev | d59a047 | 2003-11-10 21:09:22 +0000 | [diff] [blame] | 653 | r->headers_out.status = r->err_status; |
| 654 | r->headers_out.status_line.len = 0; |
| 655 | } |
| 656 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 657 | return (*ngx_http_top_header_filter)(r); |
| 658 | } |
| 659 | |
| 660 | |
| 661 | int ngx_http_redirect(ngx_http_request_t *r, int redirect) |
| 662 | { |
| 663 | /* STUB */ |
| 664 | |
| 665 | /* log request */ |
| 666 | |
Igor Sysoev | d581fd5 | 2003-05-13 16:02:32 +0000 | [diff] [blame] | 667 | ngx_http_close_request(r, 0); |
| 668 | return NGX_OK; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | |
Igor Sysoev | 3b30a90 | 2003-12-25 20:26:58 +0000 | [diff] [blame] | 672 | ngx_int_t ngx_http_set_exten(ngx_http_request_t *r) |
| 673 | { |
| 674 | ngx_int_t i; |
| 675 | |
| 676 | r->exten.len = 0; |
| 677 | r->exten.data = NULL; |
| 678 | |
| 679 | for (i = r->uri.len - 1; i > 1; i--) { |
| 680 | if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') { |
| 681 | r->exten.len = r->uri.len - i - 1; |
| 682 | |
| 683 | if (r->exten.len > 0) { |
| 684 | if (!(r->exten.data = ngx_palloc(r->pool, r->exten.len + 1))) { |
| 685 | return NGX_ERROR; |
| 686 | } |
| 687 | |
| 688 | ngx_cpystrn(r->exten.data, &r->uri.data[i + 1], |
| 689 | r->exten.len + 1); |
| 690 | } |
| 691 | |
| 692 | break; |
| 693 | |
| 694 | } else if (r->uri.data[i] == '/') { |
| 695 | break; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | return NGX_OK; |
| 700 | } |
| 701 | |
| 702 | |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 703 | int ngx_http_internal_redirect(ngx_http_request_t *r, |
| 704 | ngx_str_t *uri, ngx_str_t *args) |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 705 | { |
Igor Sysoev | dc867cd | 2003-12-14 20:10:27 +0000 | [diff] [blame] | 706 | ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
| 707 | "internal redirect: \"%s\"", uri->data); |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 708 | |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 709 | r->uri.len = uri->len; |
| 710 | r->uri.data = uri->data; |
| 711 | |
| 712 | if (args) { |
| 713 | r->args.len = args->len; |
| 714 | r->args.data = args->data; |
| 715 | } |
| 716 | |
Igor Sysoev | 3b30a90 | 2003-12-25 20:26:58 +0000 | [diff] [blame] | 717 | if (ngx_http_set_exten(r) != NGX_OK) { |
| 718 | return NGX_HTTP_INTERNAL_SERVER_ERROR; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 719 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 720 | |
Igor Sysoev | 27c30f9 | 2003-11-11 18:13:43 +0000 | [diff] [blame] | 721 | if (r->err_ctx) { |
Igor Sysoev | d59a047 | 2003-11-10 21:09:22 +0000 | [diff] [blame] | 722 | |
Igor Sysoev | 27c30f9 | 2003-11-11 18:13:43 +0000 | [diff] [blame] | 723 | /* allocate the new modules contexts */ |
| 724 | |
Igor Sysoev | d59a047 | 2003-11-10 21:09:22 +0000 | [diff] [blame] | 725 | r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module); |
| 726 | if (r->ctx == NULL) { |
| 727 | return NGX_HTTP_INTERNAL_SERVER_ERROR; |
| 728 | } |
| 729 | |
| 730 | } else { |
Igor Sysoev | 27c30f9 | 2003-11-11 18:13:43 +0000 | [diff] [blame] | 731 | |
| 732 | /* clear the modules contexts */ |
| 733 | |
Igor Sysoev | d59a047 | 2003-11-10 21:09:22 +0000 | [diff] [blame] | 734 | ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module); |
| 735 | } |
Igor Sysoev | 0a280a3 | 2003-10-12 16:49:16 +0000 | [diff] [blame] | 736 | |
| 737 | r->phase = 0; |
| 738 | r->phase_handler = 0; |
| 739 | |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 740 | ngx_http_handler(r); |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 741 | |
Igor Sysoev | 9760a13 | 2003-10-21 07:47:21 +0000 | [diff] [blame] | 742 | return NGX_DONE; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | |
Igor Sysoev | 0a280a3 | 2003-10-12 16:49:16 +0000 | [diff] [blame] | 746 | #if 1 /* STUB: test the delay http handler */ |
| 747 | |
| 748 | int ngx_http_delay_handler(ngx_http_request_t *r) |
| 749 | { |
| 750 | static int on; |
| 751 | |
| 752 | if (on++ == 0) { |
Igor Sysoev | 54498db | 2004-02-11 17:08:49 +0000 | [diff] [blame] | 753 | ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
| 754 | "http set delay"); |
Igor Sysoev | 0a280a3 | 2003-10-12 16:49:16 +0000 | [diff] [blame] | 755 | ngx_add_timer(r->connection->write, 10000); |
| 756 | return NGX_AGAIN; |
| 757 | } |
| 758 | |
| 759 | r->connection->write->timedout = 0; |
Igor Sysoev | 54498db | 2004-02-11 17:08:49 +0000 | [diff] [blame] | 760 | ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
| 761 | "http reset delay"); |
Igor Sysoev | 0a280a3 | 2003-10-12 16:49:16 +0000 | [diff] [blame] | 762 | return NGX_DECLINED; |
| 763 | } |
| 764 | |
| 765 | #endif |
| 766 | |
| 767 | |
Igor Sysoev | 340b03b | 2003-07-04 15:10:33 +0000 | [diff] [blame] | 768 | static int ngx_http_core_init(ngx_cycle_t *cycle) |
Igor Sysoev | dc479b4 | 2003-03-20 16:09:44 +0000 | [diff] [blame] | 769 | { |
Igor Sysoev | d404c97 | 2003-10-16 20:19:16 +0000 | [diff] [blame] | 770 | #if 0 |
Igor Sysoev | 9d9f58f | 2003-07-02 18:51:41 +0000 | [diff] [blame] | 771 | ngx_http_handler_pt *h; |
| 772 | ngx_http_conf_ctx_t *ctx; |
| 773 | ngx_http_core_main_conf_t *cmcf; |
Igor Sysoev | dc479b4 | 2003-03-20 16:09:44 +0000 | [diff] [blame] | 774 | |
Igor Sysoev | 9d9f58f | 2003-07-02 18:51:41 +0000 | [diff] [blame] | 775 | ctx = (ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index]; |
| 776 | cmcf = ctx->main_conf[ngx_http_core_module.ctx_index]; |
| 777 | |
Igor Sysoev | 0a280a3 | 2003-10-12 16:49:16 +0000 | [diff] [blame] | 778 | ngx_test_null(h, ngx_push_array( |
| 779 | &cmcf->phases[NGX_HTTP_TRANSLATE_PHASE].handlers), |
| 780 | NGX_ERROR); |
| 781 | *h = ngx_http_delay_handler; |
| 782 | #endif |
| 783 | |
Igor Sysoev | dc479b4 | 2003-03-20 16:09:44 +0000 | [diff] [blame] | 784 | return NGX_OK; |
| 785 | } |
| 786 | |
| 787 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 788 | static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 789 | { |
Igor Sysoev | 1c13c66 | 2003-05-20 15:37:55 +0000 | [diff] [blame] | 790 | int m; |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 791 | char *rv; |
| 792 | ngx_http_module_t *module; |
| 793 | ngx_conf_t pcf; |
Igor Sysoev | 11dbe97 | 2004-03-29 17:43:58 +0000 | [diff] [blame] | 794 | ngx_http_conf_ctx_t *ctx, *hctx; |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 795 | ngx_http_core_main_conf_t *cmcf; |
| 796 | ngx_http_core_srv_conf_t *cscf, **cscfp; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 797 | |
| 798 | ngx_test_null(ctx, |
| 799 | ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)), |
| 800 | NGX_CONF_ERROR); |
| 801 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 802 | hctx = (ngx_http_conf_ctx_t *) cf->ctx; |
| 803 | ctx->main_conf = hctx->main_conf; |
Igor Sysoev | bb4ec5c | 2003-05-16 15:27:48 +0000 | [diff] [blame] | 804 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 805 | /* the server{}'s srv_conf */ |
Igor Sysoev | bb4ec5c | 2003-05-16 15:27:48 +0000 | [diff] [blame] | 806 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 807 | ngx_test_null(ctx->srv_conf, |
| 808 | ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), |
| 809 | NGX_CONF_ERROR); |
| 810 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 811 | /* the server{}'s loc_conf */ |
Igor Sysoev | bb4ec5c | 2003-05-16 15:27:48 +0000 | [diff] [blame] | 812 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 813 | ngx_test_null(ctx->loc_conf, |
| 814 | ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module), |
| 815 | NGX_CONF_ERROR); |
| 816 | |
Igor Sysoev | 1c13c66 | 2003-05-20 15:37:55 +0000 | [diff] [blame] | 817 | for (m = 0; ngx_modules[m]; m++) { |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 818 | if (ngx_modules[m]->type != NGX_HTTP_MODULE) { |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 819 | continue; |
| 820 | } |
| 821 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 822 | module = ngx_modules[m]->ctx; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 823 | |
| 824 | if (module->create_srv_conf) { |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 825 | ngx_test_null(ctx->srv_conf[ngx_modules[m]->ctx_index], |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 826 | module->create_srv_conf(cf), |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 827 | NGX_CONF_ERROR); |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | if (module->create_loc_conf) { |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 831 | ngx_test_null(ctx->loc_conf[ngx_modules[m]->ctx_index], |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 832 | module->create_loc_conf(cf), |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 833 | NGX_CONF_ERROR); |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 834 | } |
| 835 | } |
| 836 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 837 | /* create links of the srv_conf's */ |
| 838 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 839 | cscf = ctx->srv_conf[ngx_http_core_module.ctx_index]; |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 840 | cscf->ctx = ctx; |
| 841 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 842 | cmcf = ctx->main_conf[ngx_http_core_module.ctx_index]; |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 843 | ngx_test_null(cscfp, ngx_push_array(&cmcf->servers), NGX_CONF_ERROR); |
| 844 | *cscfp = cscf; |
| 845 | |
| 846 | /* parse inside server{} */ |
| 847 | |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 848 | pcf = *cf; |
Igor Sysoev | 11dbe97 | 2004-03-29 17:43:58 +0000 | [diff] [blame] | 849 | #if 0 |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 850 | pctx = cf->ctx; |
Igor Sysoev | 11dbe97 | 2004-03-29 17:43:58 +0000 | [diff] [blame] | 851 | #endif |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 852 | cf->ctx = ctx; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 853 | cf->cmd_type = NGX_HTTP_SRV_CONF; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 854 | rv = ngx_conf_parse(cf, NULL); |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 855 | *cf = pcf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 856 | |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 857 | if (rv != NGX_CONF_OK) { |
| 858 | return rv; |
| 859 | } |
| 860 | |
Igor Sysoev | d9d0ca1 | 2003-11-21 06:30:49 +0000 | [diff] [blame] | 861 | ngx_qsort(cscf->locations.elts, (size_t) cscf->locations.nelts, |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 862 | sizeof(void *), ngx_cmp_locations); |
| 863 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 864 | return rv; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 868 | static int ngx_cmp_locations(const void *one, const void *two) |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 869 | { |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 870 | ngx_http_core_loc_conf_t *first = *(ngx_http_core_loc_conf_t **) one; |
| 871 | ngx_http_core_loc_conf_t *second = *(ngx_http_core_loc_conf_t **) two; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 872 | |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 873 | ngx_int_t rc; |
| 874 | |
Igor Sysoev | dc867cd | 2003-12-14 20:10:27 +0000 | [diff] [blame] | 875 | #if (HAVE_PCRE) |
| 876 | |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 877 | if (first->regex && !second->regex) { |
| 878 | /* shift regex matches to the end */ |
| 879 | return 1; |
| 880 | } |
| 881 | |
| 882 | if (first->regex || second->regex) { |
| 883 | /* do not sort regex matches */ |
| 884 | return 0; |
| 885 | } |
| 886 | |
Igor Sysoev | dc867cd | 2003-12-14 20:10:27 +0000 | [diff] [blame] | 887 | #endif |
| 888 | |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 889 | rc = ngx_strcmp(first->name.data, second->name.data); |
| 890 | |
| 891 | if (rc == 0 && second->exact_match) { |
| 892 | /* an exact match must be before the same inclusive one */ |
| 893 | return 1; |
| 894 | } |
| 895 | |
| 896 | return rc; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 900 | static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 901 | { |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 902 | char *rv; |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 903 | ngx_int_t m; |
Igor Sysoev | fc5a10a | 2004-03-09 19:47:07 +0000 | [diff] [blame] | 904 | ngx_str_t *value; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 905 | ngx_http_module_t *module; |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 906 | ngx_conf_t pvcf; |
| 907 | ngx_http_conf_ctx_t *ctx, *pvctx; |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 908 | ngx_http_core_srv_conf_t *cscf; |
| 909 | ngx_http_core_loc_conf_t *clcf, **clcfp; |
Igor Sysoev | fc5a10a | 2004-03-09 19:47:07 +0000 | [diff] [blame] | 910 | #if (HAVE_PCRE) |
| 911 | ngx_str_t err; |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 912 | u_char errstr[NGX_MAX_CONF_ERRSTR]; |
Igor Sysoev | fc5a10a | 2004-03-09 19:47:07 +0000 | [diff] [blame] | 913 | #endif |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 914 | |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 915 | if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) { |
| 916 | return NGX_CONF_ERROR; |
| 917 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 918 | |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 919 | pvctx = (ngx_http_conf_ctx_t *) cf->ctx; |
| 920 | ctx->main_conf = pvctx->main_conf; |
| 921 | ctx->srv_conf = pvctx->srv_conf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 922 | |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 923 | ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); |
| 924 | if (ctx->loc_conf == NULL) { |
| 925 | return NGX_CONF_ERROR; |
| 926 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 927 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 928 | for (m = 0; ngx_modules[m]; m++) { |
| 929 | if (ngx_modules[m]->type != NGX_HTTP_MODULE) { |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 930 | continue; |
| 931 | } |
| 932 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 933 | module = ngx_modules[m]->ctx; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 934 | |
| 935 | if (module->create_loc_conf) { |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 936 | ctx->loc_conf[ngx_modules[m]->ctx_index] = |
| 937 | module->create_loc_conf(cf); |
| 938 | if (ctx->loc_conf[ngx_modules[m]->ctx_index] == NULL) { |
| 939 | return NGX_CONF_ERROR; |
| 940 | } |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 941 | } |
| 942 | } |
| 943 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 944 | clcf = ctx->loc_conf[ngx_http_core_module.ctx_index]; |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 945 | clcf->loc_conf = ctx->loc_conf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 946 | |
Igor Sysoev | 3b30a90 | 2003-12-25 20:26:58 +0000 | [diff] [blame] | 947 | value = cf->args->elts; |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 948 | |
| 949 | if (cf->args->nelts == 3) { |
| 950 | if (value[1].len == 1 && value[1].data[0] == '=') { |
| 951 | clcf->name.len = value[2].len; |
| 952 | clcf->name.data = value[2].data; |
| 953 | clcf->exact_match = 1; |
| 954 | |
| 955 | } else if ((value[1].len == 1 && value[1].data[0] == '~') |
| 956 | || (value[1].len == 2 |
| 957 | && value[1].data[0] == '~' |
| 958 | && value[1].data[1] == '*')) |
| 959 | { |
Igor Sysoev | dc867cd | 2003-12-14 20:10:27 +0000 | [diff] [blame] | 960 | #if (HAVE_PCRE) |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 961 | err.len = NGX_MAX_CONF_ERRSTR; |
| 962 | err.data = errstr; |
| 963 | |
| 964 | clcf->regex = ngx_regex_compile(&value[2], |
| 965 | value[1].len == 2 ? NGX_REGEX_CASELESS: 0, |
| 966 | cf->pool, &err); |
| 967 | |
| 968 | if (clcf->regex == NULL) { |
| 969 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); |
| 970 | return NGX_CONF_ERROR; |
| 971 | } |
| 972 | |
Igor Sysoev | 3b30a90 | 2003-12-25 20:26:58 +0000 | [diff] [blame] | 973 | clcf->name = value[2]; |
Igor Sysoev | dc867cd | 2003-12-14 20:10:27 +0000 | [diff] [blame] | 974 | #else |
| 975 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 976 | "the using of the regex \"%s\" " |
| 977 | "requires PCRE library", |
| 978 | value[2].data); |
| 979 | return NGX_CONF_ERROR; |
| 980 | #endif |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 981 | |
| 982 | } else { |
| 983 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 984 | "invalid location modifier \"%s\"", |
| 985 | value[1].data); |
| 986 | return NGX_CONF_ERROR; |
| 987 | } |
| 988 | |
| 989 | } else { |
| 990 | clcf->name.len = value[1].len; |
| 991 | clcf->name.data = value[1].data; |
| 992 | } |
| 993 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 994 | cscf = ctx->srv_conf[ngx_http_core_module.ctx_index]; |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 995 | if (!(clcfp = ngx_push_array(&cscf->locations))) { |
| 996 | return NGX_CONF_ERROR; |
| 997 | } |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 998 | *clcfp = clcf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 999 | |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 1000 | pvcf = *cf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1001 | cf->ctx = ctx; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1002 | cf->cmd_type = NGX_HTTP_LOC_CONF; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1003 | rv = ngx_conf_parse(cf, NULL); |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 1004 | *cf = pvcf; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1005 | |
| 1006 | return rv; |
| 1007 | } |
| 1008 | |
| 1009 | |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1010 | static char *ngx_types_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1011 | { |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1012 | char *rv; |
| 1013 | ngx_conf_t pcf; |
| 1014 | |
| 1015 | pcf = *cf; |
| 1016 | cf->handler = ngx_set_type; |
| 1017 | cf->handler_conf = conf; |
| 1018 | rv = ngx_conf_parse(cf, NULL); |
| 1019 | *cf = pcf; |
| 1020 | |
| 1021 | return rv; |
| 1022 | } |
| 1023 | |
| 1024 | |
| 1025 | static char *ngx_set_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) |
| 1026 | { |
| 1027 | ngx_http_core_loc_conf_t *lcf = conf; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1028 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1029 | uint32_t key; |
| 1030 | ngx_uint_t i; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1031 | ngx_str_t *args; |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 1032 | ngx_http_type_t *type; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1033 | |
| 1034 | if (lcf->types == NULL) { |
| 1035 | ngx_test_null(lcf->types, |
| 1036 | ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME |
| 1037 | * sizeof(ngx_array_t)), |
| 1038 | NGX_CONF_ERROR); |
| 1039 | |
| 1040 | for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) { |
| 1041 | ngx_init_array(lcf->types[i], cf->pool, 5, sizeof(ngx_http_type_t), |
| 1042 | NGX_CONF_ERROR); |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | args = (ngx_str_t *) cf->args->elts; |
| 1047 | |
| 1048 | for (i = 1; i < cf->args->nelts; i++) { |
| 1049 | ngx_http_types_hash_key(key, args[i]); |
| 1050 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 1051 | ngx_test_null(type, ngx_push_array(&lcf->types[key]), NGX_CONF_ERROR); |
| 1052 | type->exten = args[i]; |
| 1053 | type->type = args[0]; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | return NGX_CONF_OK; |
| 1057 | } |
| 1058 | |
| 1059 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1060 | static void *ngx_http_core_create_main_conf(ngx_conf_t *cf) |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1061 | { |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1062 | ngx_http_core_main_conf_t *cmcf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1063 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1064 | ngx_test_null(cmcf, |
Igor Sysoev | b3e73d8 | 2003-10-10 15:10:50 +0000 | [diff] [blame] | 1065 | ngx_pcalloc(cf->pool, sizeof(ngx_http_core_main_conf_t)), |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1066 | NGX_CONF_ERROR); |
| 1067 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1068 | ngx_init_array(cmcf->servers, cf->pool, |
| 1069 | 5, sizeof(ngx_http_core_srv_conf_t *), |
Igor Sysoev | ad22e01 | 2003-01-15 07:02:27 +0000 | [diff] [blame] | 1070 | NGX_CONF_ERROR); |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1071 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1072 | return cmcf; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1076 | static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf) |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1077 | { |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1078 | #if 0 |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 1079 | ngx_http_core_main_conf_t *cmcf = conf; |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1080 | |
Igor Sysoev | 239baac | 2003-06-11 15:28:34 +0000 | [diff] [blame] | 1081 | /* TODO: remove it if no directives */ |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1082 | #endif |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1083 | |
| 1084 | return NGX_CONF_OK; |
| 1085 | } |
| 1086 | |
| 1087 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1088 | static void *ngx_http_core_create_srv_conf(ngx_conf_t *cf) |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1089 | { |
| 1090 | ngx_http_core_srv_conf_t *cscf; |
| 1091 | |
| 1092 | ngx_test_null(cscf, |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1093 | ngx_pcalloc(cf->pool, sizeof(ngx_http_core_srv_conf_t)), |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1094 | NGX_CONF_ERROR); |
| 1095 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1096 | ngx_init_array(cscf->locations, cf->pool, |
| 1097 | 5, sizeof(void *), NGX_CONF_ERROR); |
| 1098 | ngx_init_array(cscf->listen, cf->pool, 5, sizeof(ngx_http_listen_t), |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1099 | NGX_CONF_ERROR); |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1100 | ngx_init_array(cscf->server_names, cf->pool, |
| 1101 | 5, sizeof(ngx_http_server_name_t), NGX_CONF_ERROR); |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1102 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1103 | cscf->connection_pool_size = NGX_CONF_UNSET_SIZE; |
| 1104 | cscf->post_accept_timeout = NGX_CONF_UNSET_MSEC; |
| 1105 | cscf->request_pool_size = NGX_CONF_UNSET_SIZE; |
| 1106 | cscf->client_header_timeout = NGX_CONF_UNSET_MSEC; |
| 1107 | cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE; |
Igor Sysoev | 187fcd8 | 2003-05-23 11:53:01 +0000 | [diff] [blame] | 1108 | cscf->large_client_header = NGX_CONF_UNSET; |
| 1109 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1110 | return cscf; |
| 1111 | } |
| 1112 | |
| 1113 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1114 | static char *ngx_http_core_merge_srv_conf(ngx_conf_t *cf, |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1115 | void *parent, void *child) |
| 1116 | { |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1117 | ngx_http_core_srv_conf_t *prev = parent; |
| 1118 | ngx_http_core_srv_conf_t *conf = child; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1119 | |
| 1120 | ngx_http_listen_t *l; |
Igor Sysoev | ad22e01 | 2003-01-15 07:02:27 +0000 | [diff] [blame] | 1121 | ngx_http_server_name_t *n; |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1122 | |
Igor Sysoev | 7578ec9 | 2003-06-02 15:24:30 +0000 | [diff] [blame] | 1123 | /* TODO: it does not merge, it inits only */ |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1124 | |
| 1125 | if (conf->listen.nelts == 0) { |
| 1126 | ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR); |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1127 | l->addr = INADDR_ANY; |
Igor Sysoev | 1c10462 | 2003-06-03 15:42:58 +0000 | [diff] [blame] | 1128 | #if (WIN32) |
| 1129 | l->port = 80; |
| 1130 | #else |
Igor Sysoev | 7578ec9 | 2003-06-02 15:24:30 +0000 | [diff] [blame] | 1131 | /* STUB: getuid() should be cached */ |
| 1132 | l->port = (getuid() == 0) ? 80 : 8000; |
Igor Sysoev | 1c10462 | 2003-06-03 15:42:58 +0000 | [diff] [blame] | 1133 | #endif |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1134 | l->family = AF_INET; |
| 1135 | } |
| 1136 | |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1137 | if (conf->server_names.nelts == 0) { |
| 1138 | ngx_test_null(n, ngx_push_array(&conf->server_names), NGX_CONF_ERROR); |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1139 | ngx_test_null(n->name.data, ngx_palloc(cf->pool, NGX_MAXHOSTNAMELEN), |
Igor Sysoev | ad22e01 | 2003-01-15 07:02:27 +0000 | [diff] [blame] | 1140 | NGX_CONF_ERROR); |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1141 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1142 | if (gethostname((char *) n->name.data, NGX_MAXHOSTNAMELEN) == -1) { |
Igor Sysoev | 8e1fbe6 | 2003-07-18 14:44:05 +0000 | [diff] [blame] | 1143 | ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, |
| 1144 | "gethostname() failed"); |
| 1145 | return NGX_CONF_ERROR; |
Igor Sysoev | ad22e01 | 2003-01-15 07:02:27 +0000 | [diff] [blame] | 1146 | } |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1147 | |
Igor Sysoev | ad22e01 | 2003-01-15 07:02:27 +0000 | [diff] [blame] | 1148 | n->name.len = ngx_strlen(n->name.data); |
| 1149 | n->core_srv_conf = conf; |
| 1150 | } |
| 1151 | |
Igor Sysoev | 239baac | 2003-06-11 15:28:34 +0000 | [diff] [blame] | 1152 | ngx_conf_merge_size_value(conf->connection_pool_size, |
| 1153 | prev->connection_pool_size, 16384); |
| 1154 | ngx_conf_merge_msec_value(conf->post_accept_timeout, |
| 1155 | prev->post_accept_timeout, 30000); |
Igor Sysoev | 187fcd8 | 2003-05-23 11:53:01 +0000 | [diff] [blame] | 1156 | ngx_conf_merge_size_value(conf->request_pool_size, |
| 1157 | prev->request_pool_size, 16384); |
| 1158 | ngx_conf_merge_msec_value(conf->client_header_timeout, |
| 1159 | prev->client_header_timeout, 60000); |
| 1160 | ngx_conf_merge_size_value(conf->client_header_buffer_size, |
| 1161 | prev->client_header_buffer_size, 1024); |
| 1162 | ngx_conf_merge_value(conf->large_client_header, |
| 1163 | prev->large_client_header, 1); |
| 1164 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1165 | return NGX_CONF_OK; |
| 1166 | } |
| 1167 | |
| 1168 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1169 | static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf) |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1170 | { |
| 1171 | ngx_http_core_loc_conf_t *lcf; |
| 1172 | |
| 1173 | ngx_test_null(lcf, |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1174 | ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)), |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1175 | NGX_CONF_ERROR); |
| 1176 | |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 1177 | /* set by ngx_pcalloc(): |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1178 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1179 | lcf->root.len = 0; |
| 1180 | lcf->root.data = NULL; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1181 | lcf->types = NULL; |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 1182 | lcf->default_type.len = 0; |
| 1183 | lcf->default_type.data = NULL; |
Igor Sysoev | 9d63952 | 2003-07-07 06:11:50 +0000 | [diff] [blame] | 1184 | lcf->err_log = NULL; |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 1185 | lcf->error_pages = NULL; |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 1186 | |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 1187 | lcf->regex = NULL; |
| 1188 | lcf->exact_match = 0; |
| 1189 | lcf->auto_redirect = 0; |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1190 | lcf->alias = 0; |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 1191 | |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 1192 | */ |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1193 | |
Igor Sysoev | ae02c19 | 2004-03-19 05:25:53 +0000 | [diff] [blame] | 1194 | lcf->client_max_body_size = NGX_CONF_UNSET_SIZE; |
Igor Sysoev | dbb2776 | 2004-04-01 16:20:53 +0000 | [diff] [blame] | 1195 | lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE; |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1196 | lcf->client_body_timeout = NGX_CONF_UNSET_MSEC; |
Igor Sysoev | 5bf3d25 | 2003-10-22 07:05:29 +0000 | [diff] [blame] | 1197 | lcf->sendfile = NGX_CONF_UNSET; |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 1198 | lcf->tcp_nopush = NGX_CONF_UNSET; |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1199 | lcf->send_timeout = NGX_CONF_UNSET_MSEC; |
| 1200 | lcf->send_lowat = NGX_CONF_UNSET_SIZE; |
| 1201 | lcf->discarded_buffer_size = NGX_CONF_UNSET_SIZE; |
| 1202 | lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC; |
| 1203 | lcf->lingering_time = NGX_CONF_UNSET_MSEC; |
| 1204 | lcf->lingering_timeout = NGX_CONF_UNSET_MSEC; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1205 | |
Igor Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 1206 | lcf->msie_padding = NGX_CONF_UNSET; |
| 1207 | |
Igor Sysoev | 4e9393a | 2003-01-09 05:36:00 +0000 | [diff] [blame] | 1208 | return lcf; |
| 1209 | } |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 1210 | |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1211 | |
| 1212 | static ngx_http_type_t default_types[] = { |
| 1213 | { ngx_string("html"), ngx_string("text/html") }, |
| 1214 | { ngx_string("gif"), ngx_string("image/gif") }, |
| 1215 | { ngx_string("jpg"), ngx_string("image/jpeg") }, |
| 1216 | { ngx_null_string, ngx_null_string } |
| 1217 | }; |
| 1218 | |
| 1219 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1220 | static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf, |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 1221 | void *parent, void *child) |
| 1222 | { |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1223 | ngx_http_core_loc_conf_t *prev = parent; |
| 1224 | ngx_http_core_loc_conf_t *conf = child; |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1225 | |
| 1226 | int i, key; |
| 1227 | ngx_http_type_t *t; |
| 1228 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1229 | ngx_conf_merge_str_value(conf->root, prev->root, "html"); |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1230 | |
| 1231 | if (conf->types == NULL) { |
| 1232 | if (prev->types) { |
| 1233 | conf->types = prev->types; |
| 1234 | |
| 1235 | } else { |
| 1236 | ngx_test_null(conf->types, |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1237 | ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1238 | * sizeof(ngx_array_t)), |
| 1239 | NGX_CONF_ERROR); |
| 1240 | |
| 1241 | for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) { |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1242 | ngx_init_array(conf->types[i], cf->pool, |
| 1243 | 5, sizeof(ngx_http_type_t), NGX_CONF_ERROR); |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | for (i = 0; default_types[i].exten.len; i++) { |
| 1247 | ngx_http_types_hash_key(key, default_types[i].exten); |
| 1248 | |
| 1249 | ngx_test_null(t, ngx_push_array(&conf->types[key]), |
| 1250 | NGX_CONF_ERROR); |
| 1251 | t->exten.len = default_types[i].exten.len; |
| 1252 | t->exten.data = default_types[i].exten.data; |
| 1253 | t->type.len = default_types[i].type.len; |
| 1254 | t->type.data = default_types[i].type.data; |
| 1255 | } |
| 1256 | } |
| 1257 | } |
| 1258 | |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1259 | if (conf->err_log == NULL) { |
| 1260 | if (prev->err_log) { |
| 1261 | conf->err_log = prev->err_log; |
| 1262 | } else { |
Igor Sysoev | 630ad0c | 2004-04-16 05:14:16 +0000 | [diff] [blame^] | 1263 | conf->err_log = cf->cycle->new_log; |
Igor Sysoev | 890fc96 | 2003-07-20 21:15:59 +0000 | [diff] [blame] | 1264 | } |
| 1265 | } |
| 1266 | |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 1267 | if (conf->error_pages == NULL && prev->error_pages) { |
| 1268 | conf->error_pages = prev->error_pages; |
| 1269 | } |
| 1270 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 1271 | ngx_conf_merge_str_value(conf->default_type, |
| 1272 | prev->default_type, "text/plain"); |
| 1273 | |
Igor Sysoev | ae02c19 | 2004-03-19 05:25:53 +0000 | [diff] [blame] | 1274 | ngx_conf_merge_size_value(conf->client_max_body_size, |
| 1275 | prev->client_max_body_size, 10 * 1024 * 1024); |
Igor Sysoev | dbb2776 | 2004-04-01 16:20:53 +0000 | [diff] [blame] | 1276 | ngx_conf_merge_size_value(conf->client_body_buffer_size, |
| 1277 | prev->client_body_buffer_size, 8192); |
Igor Sysoev | 2b0c76c | 2003-10-27 21:01:00 +0000 | [diff] [blame] | 1278 | ngx_conf_merge_msec_value(conf->client_body_timeout, |
Igor Sysoev | 7af6b16 | 2004-02-09 07:46:43 +0000 | [diff] [blame] | 1279 | prev->client_body_timeout, 60000); |
Igor Sysoev | 5bf3d25 | 2003-10-22 07:05:29 +0000 | [diff] [blame] | 1280 | ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0); |
Igor Sysoev | 3c3ca17 | 2004-01-05 20:55:48 +0000 | [diff] [blame] | 1281 | ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0); |
Igor Sysoev | 7af6b16 | 2004-02-09 07:46:43 +0000 | [diff] [blame] | 1282 | ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000); |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 1283 | ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0); |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1284 | ngx_conf_merge_size_value(conf->discarded_buffer_size, |
| 1285 | prev->discarded_buffer_size, 1500); |
Igor Sysoev | 187fcd8 | 2003-05-23 11:53:01 +0000 | [diff] [blame] | 1286 | ngx_conf_merge_msec_value(conf->keepalive_timeout, |
| 1287 | prev->keepalive_timeout, 70000); |
| 1288 | ngx_conf_merge_msec_value(conf->lingering_time, |
| 1289 | prev->lingering_time, 30000); |
| 1290 | ngx_conf_merge_msec_value(conf->lingering_timeout, |
| 1291 | prev->lingering_timeout, 5000); |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1292 | |
Igor Sysoev | 12b4b00 | 2003-10-24 06:53:41 +0000 | [diff] [blame] | 1293 | ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1); |
| 1294 | |
Igor Sysoev | 865c150 | 2003-11-30 20:03:18 +0000 | [diff] [blame] | 1295 | if (conf->open_files == NULL) { |
| 1296 | conf->open_files = prev->open_files; |
| 1297 | } |
| 1298 | |
Igor Sysoev | e2a3154 | 2003-04-08 15:40:10 +0000 | [diff] [blame] | 1299 | return NGX_CONF_OK; |
| 1300 | } |
| 1301 | |
Igor Sysoev | 79a8048 | 2003-05-14 17:13:13 +0000 | [diff] [blame] | 1302 | |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 1303 | static char *ngx_set_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 1304 | { |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1305 | ngx_http_core_srv_conf_t *scf = conf; |
Igor Sysoev | a983011 | 2003-05-19 16:39:14 +0000 | [diff] [blame] | 1306 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1307 | u_char *addr; |
Igor Sysoev | 1c13c66 | 2003-05-20 15:37:55 +0000 | [diff] [blame] | 1308 | u_int p; |
Igor Sysoev | 6253ca1 | 2003-05-27 12:18:54 +0000 | [diff] [blame] | 1309 | struct hostent *h; |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 1310 | ngx_str_t *args; |
| 1311 | ngx_http_listen_t *ls; |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 1312 | |
Igor Sysoev | 239baac | 2003-06-11 15:28:34 +0000 | [diff] [blame] | 1313 | /* TODO: check duplicate 'listen' directives, |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1314 | add resolved name to server names ??? */ |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 1315 | |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 1316 | ngx_test_null(ls, ngx_push_array(&scf->listen), NGX_CONF_ERROR); |
| 1317 | |
| 1318 | /* AF_INET only */ |
| 1319 | |
| 1320 | ls->family = AF_INET; |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1321 | ls->default_server = 0; |
Igor Sysoev | fe5cb6b | 2003-01-29 07:25:51 +0000 | [diff] [blame] | 1322 | ls->file_name = cf->conf_file->file.name; |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 1323 | ls->line = cf->conf_file->line; |
| 1324 | |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1325 | args = cf->args->elts; |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 1326 | addr = args[1].data; |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 1327 | |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 1328 | for (p = 0; p < args[1].len; p++) { |
| 1329 | if (addr[p] == ':') { |
| 1330 | addr[p++] = '\0'; |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 1331 | break; |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | if (p == args[1].len) { |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1336 | /* no ":" in the "listen" */ |
Igor Sysoev | 6ddfbf0 | 2003-05-15 15:42:53 +0000 | [diff] [blame] | 1337 | p = 0; |
| 1338 | } |
| 1339 | |
| 1340 | ls->port = ngx_atoi(&addr[p], args[1].len - p); |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1341 | if (ls->port == NGX_ERROR && p == 0) { |
| 1342 | |
| 1343 | /* "listen host" */ |
| 1344 | ls->port = 80; |
| 1345 | |
| 1346 | } else if ((ls->port == NGX_ERROR && p != 0) /* "listen host:NONNUMBER" */ |
| 1347 | || (ls->port < 1 || ls->port > 65536)) { /* "listen 99999" */ |
| 1348 | |
Igor Sysoev | 8e1fbe6 | 2003-07-18 14:44:05 +0000 | [diff] [blame] | 1349 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 1350 | "invalid port \"%s\" in \"%s\" directive, " |
| 1351 | "it must be a number between 1 and 65535", |
| 1352 | &addr[p], cmd->name.data); |
| 1353 | |
| 1354 | return NGX_CONF_ERROR; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1355 | |
| 1356 | } else if (p == 0) { |
| 1357 | ls->addr = INADDR_ANY; |
| 1358 | return NGX_CONF_OK; |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 1359 | } |
| 1360 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1361 | ls->addr = inet_addr((const char *) addr); |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1362 | if (ls->addr == INADDR_NONE) { |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1363 | h = gethostbyname((const char *) addr); |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1364 | |
| 1365 | if (h == NULL || h->h_addr_list[0] == NULL) { |
Igor Sysoev | 8e1fbe6 | 2003-07-18 14:44:05 +0000 | [diff] [blame] | 1366 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 1367 | "can not resolve host \"%s\" " |
| 1368 | "in \"%s\" directive", addr, cmd->name.data); |
| 1369 | return NGX_CONF_ERROR; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
Igor Sysoev | a8fa0a6 | 2003-11-25 20:44:56 +0000 | [diff] [blame] | 1372 | ls->addr = *(in_addr_t *)(h->h_addr_list[0]); |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | return NGX_CONF_OK; |
| 1376 | } |
| 1377 | |
| 1378 | |
| 1379 | static char *ngx_set_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 1380 | { |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1381 | ngx_http_core_srv_conf_t *scf = conf; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1382 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1383 | ngx_uint_t i; |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1384 | ngx_str_t *value; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1385 | ngx_http_server_name_t *sn; |
| 1386 | |
| 1387 | /* TODO: several names */ |
| 1388 | /* TODO: warn about duplicate 'server_name' directives */ |
| 1389 | |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1390 | value = cf->args->elts; |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1391 | |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1392 | for (i = 1; i < cf->args->nelts; i++) { |
| 1393 | if (value[i].len == 0) { |
Igor Sysoev | 8e1fbe6 | 2003-07-18 14:44:05 +0000 | [diff] [blame] | 1394 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 1395 | "server name \"%s\" is invalid " |
| 1396 | "in \"%s\" directive", |
| 1397 | value[i].data, cmd->name.data); |
| 1398 | return NGX_CONF_ERROR; |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1399 | } |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1400 | |
Igor Sysoev | aa3436c | 2003-05-30 14:27:59 +0000 | [diff] [blame] | 1401 | ngx_test_null(sn, ngx_push_array(&scf->server_names), NGX_CONF_ERROR); |
| 1402 | |
| 1403 | sn->name.len = value[i].len; |
| 1404 | sn->name.data = value[i].data; |
| 1405 | sn->core_srv_conf = scf; |
| 1406 | } |
Igor Sysoev | 1393325 | 2003-05-29 13:02:09 +0000 | [diff] [blame] | 1407 | |
Igor Sysoev | a19a85e | 2003-01-28 15:56:37 +0000 | [diff] [blame] | 1408 | return NGX_CONF_OK; |
| 1409 | } |
Igor Sysoev | 9d63952 | 2003-07-07 06:11:50 +0000 | [diff] [blame] | 1410 | |
| 1411 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1412 | static char *ngx_set_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 1413 | { |
| 1414 | ngx_http_core_loc_conf_t *lcf = conf; |
| 1415 | |
| 1416 | ngx_uint_t alias; |
| 1417 | ngx_str_t *value; |
| 1418 | |
| 1419 | alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0; |
| 1420 | |
| 1421 | if (lcf->root.data) { |
Igor Sysoev | a741f8d | 2004-03-30 20:31:58 +0000 | [diff] [blame] | 1422 | |
| 1423 | /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */ |
| 1424 | |
| 1425 | if ((ngx_uint_t) lcf->alias == alias) { |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1426 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 1427 | "\"%s\" directive is duplicate", |
| 1428 | cmd->name.data); |
| 1429 | } else { |
| 1430 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 1431 | "\"%s\" directive is duplicate, " |
| 1432 | "\"%s\" directive is specified before", |
| 1433 | cmd->name.data, lcf->alias ? "alias" : "root"); |
| 1434 | } |
| 1435 | |
| 1436 | return NGX_CONF_ERROR; |
| 1437 | } |
| 1438 | |
| 1439 | value = cf->args->elts; |
| 1440 | |
| 1441 | lcf->alias = alias; |
| 1442 | lcf->root = value[1]; |
| 1443 | |
| 1444 | return NGX_CONF_OK; |
| 1445 | } |
| 1446 | |
| 1447 | |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 1448 | static char *ngx_set_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 1449 | { |
| 1450 | ngx_http_core_loc_conf_t *lcf = conf; |
| 1451 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1452 | ngx_uint_t i; |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 1453 | ngx_str_t *value; |
| 1454 | ngx_http_err_page_t *err; |
| 1455 | |
| 1456 | if (lcf->error_pages == NULL) { |
| 1457 | lcf->error_pages = ngx_create_array(cf->pool, 5, |
| 1458 | sizeof(ngx_http_err_page_t)); |
| 1459 | if (lcf->error_pages == NULL) { |
| 1460 | return NGX_CONF_ERROR; |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | value = cf->args->elts; |
| 1465 | |
| 1466 | for (i = 1; i < cf->args->nelts - 1; i++) { |
| 1467 | ngx_test_null(err, ngx_push_array(lcf->error_pages), NGX_CONF_ERROR); |
| 1468 | err->code = ngx_atoi(value[i].data, value[i].len); |
| 1469 | if (err->code == NGX_ERROR) { |
| 1470 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 1471 | "invalid value \"%s\"", value[i].data); |
| 1472 | return NGX_CONF_ERROR; |
| 1473 | } |
| 1474 | |
| 1475 | if (err->code < 400 || err->code > 599) { |
| 1476 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 1477 | "value \"%s\" must be between 400 and 599", |
| 1478 | value[i].data); |
| 1479 | return NGX_CONF_ERROR; |
| 1480 | } |
| 1481 | |
| 1482 | err->uri = value[cf->args->nelts - 1]; |
| 1483 | } |
| 1484 | |
| 1485 | return NGX_CONF_OK; |
| 1486 | } |
| 1487 | |
| 1488 | |
Igor Sysoev | 9d63952 | 2003-07-07 06:11:50 +0000 | [diff] [blame] | 1489 | static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
| 1490 | { |
| 1491 | ngx_http_core_loc_conf_t *lcf = conf; |
| 1492 | |
Igor Sysoev | 03420a6 | 2004-01-20 20:40:08 +0000 | [diff] [blame] | 1493 | if (!(lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args))) { |
| 1494 | return NGX_CONF_ERROR; |
| 1495 | } |
Igor Sysoev | 9d63952 | 2003-07-07 06:11:50 +0000 | [diff] [blame] | 1496 | |
Igor Sysoev | 03420a6 | 2004-01-20 20:40:08 +0000 | [diff] [blame] | 1497 | return ngx_set_error_log_levels(cf, lcf->err_log); |
Igor Sysoev | 9d63952 | 2003-07-07 06:11:50 +0000 | [diff] [blame] | 1498 | } |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 1499 | |
| 1500 | |
| 1501 | static char *ngx_http_lowat_check(ngx_conf_t *cf, void *post, void *data) |
| 1502 | { |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 1503 | #if (HAVE_LOWAT_EVENT) |
| 1504 | |
Igor Sysoev | 10a543a | 2004-03-16 07:10:12 +0000 | [diff] [blame] | 1505 | ssize_t *np = data; |
Igor Sysoev | 74e95c2 | 2003-11-09 20:03:38 +0000 | [diff] [blame] | 1506 | |
Igor Sysoev | b5faed2 | 2003-10-29 08:30:44 +0000 | [diff] [blame] | 1507 | if (*np >= ngx_freebsd_net_inet_tcp_sendspace) { |
| 1508 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 1509 | "\"send_lowat\" must be less than %d " |
| 1510 | "(sysctl net.inet.tcp.sendspace)", |
| 1511 | ngx_freebsd_net_inet_tcp_sendspace); |
| 1512 | |
| 1513 | return NGX_CONF_ERROR; |
| 1514 | } |
| 1515 | |
| 1516 | #else |
| 1517 | |
| 1518 | ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
| 1519 | "\"send_lowat\" is not supported, ignored"); |
| 1520 | |
| 1521 | #endif |
| 1522 | |
| 1523 | return NGX_CONF_OK; |
| 1524 | } |