Klaus Demo nginx / 59cf56c
nginx-0.0.10-2004-09-07-19:29:22 import Igor Sysoev 17 years ago
30 changed file(s) with 666 addition(s) and 293 deletion(s). Raw diff Collapse all Expand all
00
11 mkdir -p $OBJS/src/core $OBJS/src/event $OBJS/src/event/modules \
22 $OBJS/src/os/unix $OBJS/src/os/win32 \
3 $OBJS/src/http $OBJS/src/http/modules $OBJS/src/http/modules/proxy
3 $OBJS/src/http $OBJS/src/http/modules $OBJS/src/http/modules/proxy \
4 $OBJS/src/imap
45
56
67 echo "CC = $CC" > $MAKEFILE
1718 echo >> $MAKEFILE
1819 fi
1920
20 all_inc="$CORE_INCS $OBJS $HTTP_INCS"
21 all_inc="$CORE_INCS $OBJS $HTTP_INCS $IMAP_INCS"
2122 all_inc=`echo " $all_inc" | sed -e "s/ \([^ ]\)/ $INCOPT\1/g"`
2223 all_inc=`echo $all_inc | sed -e "s/\//$DIRSEP/g"`
2324
2425 echo "ALL_INCS = $all_inc" >> $MAKEFILE
2526 echo >> $MAKEFILE
2627
28 all_srcs="$CORE_SRCS"
29
2730
2831 # CORE_DEPS
2932
5962 echo >> $MAKEFILE
6063
6164
62 # HTTP_DEPS
63
64 if [ $MAKE_SL = YES ]; then
65 echo $ngx_n "HTTP_DEPS =" $ngx_c >> $MAKEFILE
66 else
67 echo "HTTP_DEPS = \\" >> $MAKEFILE
68 fi
69
70 for dep in $HTTP_DEPS
71 do
72 dep=`echo $dep | sed -e "s/\//$DIRSEP/g"`
73
74 if [ $MAKE_SL = YES ]; then
75 echo $ngx_n " $dep" $ngx_c >> $MAKEFILE
76 else
77 echo " $dep \\" >> $MAKEFILE
78 fi
79 done
80 echo >> $MAKEFILE
81
82
83 # HTTP_INCS
84
85 if [ $MAKE_SL = YES ]; then
86 echo >> $MAKEFILE
87 fi
88
89 inc="$HTTP_INCS $OBJS"
90 inc=`echo " $inc" | sed -e "s/ \([^ ]\)/ $INCOPT\1/g" -e "s/\//$DIRSEP/g"`
91
92 echo "HTTP_INCS = $inc" >> $MAKEFILE
93 echo >> $MAKEFILE
65 if [ $HTTP = YES ]; then
66
67 all_srcs="$all_srcs $HTTP_SRCS"
68
69 # HTTP_DEPS
70
71 if [ $MAKE_SL = YES ]; then
72 echo $ngx_n "HTTP_DEPS =" $ngx_c >> $MAKEFILE
73 else
74 echo "HTTP_DEPS = \\" >> $MAKEFILE
75 fi
76
77 for dep in $HTTP_DEPS
78 do
79 dep=`echo $dep | sed -e "s/\//$DIRSEP/g"`
80
81 if [ $MAKE_SL = YES ]; then
82 echo $ngx_n " $dep" $ngx_c >> $MAKEFILE
83 else
84 echo " $dep \\" >> $MAKEFILE
85 fi
86 done
87 echo >> $MAKEFILE
88
89
90 # HTTP_INCS
91
92 if [ $MAKE_SL = YES ]; then
93 echo >> $MAKEFILE
94 fi
95
96 inc="$HTTP_INCS $OBJS"
97 inc=`echo " $inc" | sed -e "s/ \([^ ]\)/ $INCOPT\1/g" -e "s/\//$DIRSEP/g"`
98
99 echo "HTTP_INCS = $inc" >> $MAKEFILE
100 echo >> $MAKEFILE
101
102 fi
103
104
105 if [ $IMAP = YES ]; then
106
107 all_srcs="$all_srcs $IMAP_SRCS"
108
109 # IMAP_DEPS
110
111 if [ $MAKE_SL = YES ]; then
112 echo $ngx_n "IMAP_DEPS =" $ngx_c >> $MAKEFILE
113 else
114 echo "IMAP_DEPS = \\" >> $MAKEFILE
115 fi
116
117 for dep in $IMAP_DEPS
118 do
119 dep=`echo $dep | sed -e "s/\//$DIRSEP/g"`
120
121 if [ $MAKE_SL = YES ]; then
122 echo $ngx_n " $dep" $ngx_c >> $MAKEFILE
123 else
124 echo " $dep \\" >> $MAKEFILE
125 fi
126 done
127 echo >> $MAKEFILE
128
129
130 # IMAP_INCS
131
132 if [ $MAKE_SL = YES ]; then
133 echo >> $MAKEFILE
134 fi
135
136 inc="$IMAP_INCS $OBJS"
137 inc=`echo " $inc" | sed -e "s/ \([^ ]\)/ $INCOPT\1/g" -e "s/\//$DIRSEP/g"`
138
139 echo "IMAP_INCS = $inc" >> $MAKEFILE
140 echo >> $MAKEFILE
141
142 fi
94143
95144
96145 # nginx
104153
105154 # nginx deps
106155
107 for src in $CORE_SRCS $HTTP_SRCS
156 for src in $all_srcs
108157 do
109158 obj=`echo $src | sed -e "s/\.c\$/.$OBJEXT/" -e "s/\.S\$/.$OBJEXT/"`
110159 obj=`echo $OBJS/$obj | sed -e "s/\//$DIRSEP/g"`
141190
142191 # nginx build sources
143192
144 for src in $CORE_SRCS $HTTP_SRCS
193 for src in $all_srcs
145194 do
146195 obj=`echo $src | sed -e "s/\.c\$/.$OBJEXT/" -e "s/\.S\$/.$OBJEXT/"`
147196 obj=`echo $OBJS/$obj | sed -e "s/\//$DIRSEP/g"`
222271
223272 # http sources
224273
225 deps="\$(CORE_DEPS) \$(HTTP_DEPS)"
226
227 if [ $PCH != NO ]; then
228 args="\$(CFLAGS) $USEPCH \$(ALL_INCS)"
229 else
230 args="\$(CFLAGS) $USEPCH \$(CORE_INCS) \$(HTTP_INCS)"
231 fi
232
233 for src in $HTTP_SRCS
234 do
235 obj=`echo $src | sed -e "s/\.c\$/.$OBJEXT/"`
236 obj=`echo $OBJS/$obj | sed -e "s/\//$DIRSEP/g"`
237 src=`echo $src | sed -e "s/\//$DIRSEP/g"`
238
239 if [ $MAKE_SL = YES ]; then
240 echo "$obj: $src $deps" >> $MAKEFILE
241 echo " \$(CC) $COMPOPT $args $OBJOUT$obj $src" >> $MAKEFILE
242 echo >> $MAKEFILE
243 else
244 echo "$obj: \\" >> $MAKEFILE
245 echo " $src $deps" >> $MAKEFILE
246 echo " \$(CC) $COMPOPT $args \\" >> $MAKEFILE
247 echo " $OBJOUT$obj \\" >> $MAKEFILE
248 echo " $src" >> $MAKEFILE
249 echo >> $MAKEFILE
250 fi
251 done
274 if [ $HTTP = YES ]; then
275
276 deps="\$(CORE_DEPS) \$(HTTP_DEPS)"
277
278 if [ $PCH != NO ]; then
279 args="\$(CFLAGS) $USEPCH \$(ALL_INCS)"
280 else
281 args="\$(CFLAGS) $USEPCH \$(CORE_INCS) \$(HTTP_INCS)"
282 fi
283
284 for src in $HTTP_SRCS
285 do
286 obj=`echo $src | sed -e "s/\.c\$/.$OBJEXT/"`
287 obj=`echo $OBJS/$obj | sed -e "s/\//$DIRSEP/g"`
288 src=`echo $src | sed -e "s/\//$DIRSEP/g"`
289
290 if [ $MAKE_SL = YES ]; then
291 echo "$obj: $src $deps" >> $MAKEFILE
292 echo " \$(CC) $COMPOPT $args $OBJOUT$obj $src" >> $MAKEFILE
293 echo >> $MAKEFILE
294 else
295 echo "$obj: \\" >> $MAKEFILE
296 echo " $src $deps" >> $MAKEFILE
297 echo " \$(CC) $COMPOPT $args \\" >> $MAKEFILE
298 echo " $OBJOUT$obj \\" >> $MAKEFILE
299 echo " $src" >> $MAKEFILE
300 echo >> $MAKEFILE
301 fi
302 done
303
304 fi
305
306
307 # imap sources
308
309 if [ $IMAP = YES ]; then
310
311 deps="\$(CORE_DEPS) \$(IMAP_DEPS)"
312
313 if [ $PCH != NO ]; then
314 args="\$(CFLAGS) $USEPCH \$(ALL_INCS)"
315 else
316 args="\$(CFLAGS) $USEPCH \$(CORE_INCS) \$(IMAP_INCS)"
317 fi
318
319 for src in $IMAP_SRCS
320 do
321 obj=`echo $src | sed -e "s/\.c\$/.$OBJEXT/"`
322 obj=`echo $OBJS/$obj | sed -e "s/\//$DIRSEP/g"`
323 src=`echo $src | sed -e "s/\//$DIRSEP/g"`
324
325 if [ $MAKE_SL = YES ]; then
326 echo "$obj: $src $deps" >> $MAKEFILE
327 echo " \$(CC) $COMPOPT $args $OBJOUT$obj $src" >> $MAKEFILE
328 echo >> $MAKEFILE
329 else
330 echo "$obj: \\" >> $MAKEFILE
331 echo " $src $deps" >> $MAKEFILE
332 echo " \$(CC) $COMPOPT $args \\" >> $MAKEFILE
333 echo " $OBJOUT$obj \\" >> $MAKEFILE
334 echo " $src" >> $MAKEFILE
335 echo >> $MAKEFILE
336 fi
337 done
338
339 fi
252340
253341
254342 # precompiled headers
135135 $HTTP_NOT_MODIFIED_FILTER_MODULE"
136136 fi
137137
138 IMAP_MODULES=$IMAP_MODULE
139
140 if [ $IMAP = YES ]; then
141 modules="$modules $IMAP_MODULES"
142 fi
143
138144
139145 echo "#include <ngx_config.h>" > $NGX_MODULES_C
140146 echo "#include <ngx_core.h>" >> $NGX_MODULES_C
3838 HTTP_STATUS=YES
3939 HTTP_REWRITE=YES
4040 HTTP_PROXY=YES
41
42 IMAP=NO
4143
4244 USE_PCRE=NO
4345 PCRE=NONE
99101 --without-http_status_module) HTTP_STATUS=NO ;;
100102 --without-http_rewrite_module) HTTP_REWRITE=NO ;;
101103 --without-http_proxy_module) HTTP_PROXY=NO ;;
104
105 --with-imap) IMAP=YES ;;
102106
103107 --with-cc=*) CC="$value" ;;
104108 --with-cpp=*) CPP="$value" ;;
33 CORE_INCS="src/core"
44
55 CORE_DEPS="src/core/nginx.h \
6 src/core/ngx_config.h \
7 src/core/ngx_core.h \
8 src/core/ngx_log.h \
9 src/core/ngx_palloc.h \
10 src/core/ngx_array.h \
11 src/core/ngx_list.h \
12 src/core/ngx_table.h \
13 src/core/ngx_buf.h \
14 src/core/ngx_string.h \
15 src/core/ngx_parse.h \
16 src/core/ngx_inet.h \
17 src/core/ngx_file.h \
18 src/core/ngx_crc.h \
19 src/core/ngx_rbtree.h \
20 src/core/ngx_radix_tree.h \
21 src/core/ngx_times.h \
22 src/core/ngx_connection.h \
23 src/core/ngx_cycle.h \
24 src/core/ngx_conf_file.h \
25 src/core/ngx_garbage_collector.h"
6 src/core/ngx_config.h \
7 src/core/ngx_core.h \
8 src/core/ngx_log.h \
9 src/core/ngx_palloc.h \
10 src/core/ngx_array.h \
11 src/core/ngx_list.h \
12 src/core/ngx_table.h \
13 src/core/ngx_buf.h \
14 src/core/ngx_string.h \
15 src/core/ngx_parse.h \
16 src/core/ngx_inet.h \
17 src/core/ngx_file.h \
18 src/core/ngx_crc.h \
19 src/core/ngx_rbtree.h \
20 src/core/ngx_radix_tree.h \
21 src/core/ngx_times.h \
22 src/core/ngx_connection.h \
23 src/core/ngx_cycle.h \
24 src/core/ngx_conf_file.h \
25 src/core/ngx_garbage_collector.h"
2626
2727 CORE_SRCS="src/core/nginx.c \
28 src/core/ngx_log.c \
29 src/core/ngx_palloc.c \
30 src/core/ngx_array.c \
31 src/core/ngx_list.c \
32 src/core/ngx_buf.c \
33 src/core/ngx_output_chain.c \
34 src/core/ngx_string.c \
35 src/core/ngx_parse.c \
36 src/core/ngx_inet.c \
37 src/core/ngx_file.c \
38 src/core/ngx_rbtree.c \
39 src/core/ngx_radix_tree.c \
40 src/core/ngx_times.c \
41 src/core/ngx_connection.c \
42 src/core/ngx_cycle.c \
43 src/core/ngx_spinlock.c \
44 src/core/ngx_conf_file.c \
45 src/core/ngx_garbage_collector.c"
28 src/core/ngx_log.c \
29 src/core/ngx_palloc.c \
30 src/core/ngx_array.c \
31 src/core/ngx_list.c \
32 src/core/ngx_buf.c \
33 src/core/ngx_output_chain.c \
34 src/core/ngx_string.c \
35 src/core/ngx_parse.c \
36 src/core/ngx_inet.c \
37 src/core/ngx_file.c \
38 src/core/ngx_rbtree.c \
39 src/core/ngx_radix_tree.c \
40 src/core/ngx_times.c \
41 src/core/ngx_connection.c \
42 src/core/ngx_cycle.c \
43 src/core/ngx_spinlock.c \
44 src/core/ngx_conf_file.c \
45 src/core/ngx_garbage_collector.c"
4646
4747
4848 REGEX_DEPS=src/core/ngx_regex.h
127127 src/os/unix/ngx_socket.c \
128128 src/os/unix/ngx_recv.c \
129129 src/os/unix/ngx_readv_chain.c \
130 src/os/unix/ngx_send.c \
130131 src/os/unix/ngx_writev_chain.c \
131132 src/os/unix/ngx_channel.c \
132133 src/os/unix/ngx_shared.c \
190191
191192
192193 HTTP_MODULES="ngx_http_module \
193 ngx_http_core_module \
194 ngx_http_log_module"
194 ngx_http_core_module \
195 ngx_http_log_module"
195196
196197 HTTP_FILE_CACHE_MODULE=ngx_http_cache_module
197198
213214 HTTP_INCS="src/http src/http/modules"
214215
215216 HTTP_DEPS="src/http/ngx_http.h \
216 src/http/ngx_http_request.h \
217 src/http/ngx_http_config.h \
218 src/http/ngx_http_core_module.h \
219 src/http/ngx_http_cache.h \
220 src/http/ngx_http_busy_lock.h \
221 src/http/ngx_http_log_handler.h"
217 src/http/ngx_http_request.h \
218 src/http/ngx_http_config.h \
219 src/http/ngx_http_core_module.h \
220 src/http/ngx_http_cache.h \
221 src/http/ngx_http_busy_lock.h \
222 src/http/ngx_http_log_handler.h"
222223
223224 HTTP_SRCS="src/http/ngx_http.c \
224 src/http/ngx_http_core_module.c \
225 src/http/ngx_http_special_response.c \
226 src/http/ngx_http_request.c \
227 src/http/ngx_http_parse.c \
228 src/http/ngx_http_header_filter.c \
229 src/http/ngx_http_write_filter.c \
230 src/http/ngx_http_copy_filter.c \
231 src/http/ngx_http_log_handler.c \
232 src/http/ngx_http_request_body.c \
233 src/http/ngx_http_parse_time.c \
234 src/http/modules/ngx_http_static_handler.c \
235 src/http/modules/ngx_http_index_handler.c \
236 src/http/modules/ngx_http_chunked_filter.c \
237 src/http/modules/ngx_http_range_filter.c \
238 src/http/modules/ngx_http_headers_filter.c \
239 src/http/modules/ngx_http_not_modified_filter.c"
225 src/http/ngx_http_core_module.c \
226 src/http/ngx_http_special_response.c \
227 src/http/ngx_http_request.c \
228 src/http/ngx_http_parse.c \
229 src/http/ngx_http_header_filter.c \
230 src/http/ngx_http_write_filter.c \
231 src/http/ngx_http_copy_filter.c \
232 src/http/ngx_http_log_handler.c \
233 src/http/ngx_http_request_body.c \
234 src/http/ngx_http_parse_time.c \
235 src/http/modules/ngx_http_static_handler.c \
236 src/http/modules/ngx_http_index_handler.c \
237 src/http/modules/ngx_http_chunked_filter.c \
238 src/http/modules/ngx_http_range_filter.c \
239 src/http/modules/ngx_http_headers_filter.c \
240 src/http/modules/ngx_http_not_modified_filter.c"
240241
241242 # STUB
242243 HTTP_SRCS="$HTTP_SRCS src/http/ngx_http_busy_lock.c"
282283 HTTP_PROXY_INCS="src/http/modules/proxy"
283284 HTTP_PROXY_DEPS=src/http/modules/proxy/ngx_http_proxy_handler.h
284285 HTTP_PROXY_SRCS="src/http/modules/proxy/ngx_http_proxy_handler.c \
285 src/http/modules/proxy/ngx_http_proxy_upstream.c \
286 src/http/modules/proxy/ngx_http_proxy_parse.c \
287 src/http/modules/proxy/ngx_http_proxy_header.c"
286 src/http/modules/proxy/ngx_http_proxy_upstream.c \
287 src/http/modules/proxy/ngx_http_proxy_parse.c \
288 src/http/modules/proxy/ngx_http_proxy_header.c"
288289
289290 # STUB
290 # src/http/modules/proxy/ngx_http_proxy_cache.c \
291 # src/http/modules/proxy/ngx_http_proxy_cache.c \
292
293
294 IMAP_INCS="src/imap"
295
296 IMAP_DEPS="src/imap/ngx_imap.h"
297
298 IMAP_MODULE=ngx_imap_module
299 IMAP_SRCS="src/imap/ngx_imap.c \
300 src/imap/ngx_imap_handler.c"
3030 ngx_type="socklen_t"; ngx_types="uint32_t"; . auto/types/typedef
3131
3232 ngx_type="in_addr_t"; ngx_types="uint32_t"; . auto/types/typedef
33
34 ngx_type="in_port_t"; ngx_types="u_short"; . auto/types/typedef
3335
3436 ngx_type="rlim_t"; ngx_types="int"; . auto/types/typedef
3537
4040 ngx_test_null(a.elts, ngx_palloc(p, n * s), rc); \
4141 a.nelts = 0; a.size = s; a.nalloc = n; a.pool = p;
4242
43 #define ngx_array_push ngx_push_array
44
4345
4446 #endif /* _NGX_ARRAY_H_INCLUDED_ */
44
55
66 ngx_os_io_t ngx_io;
7
8
9 ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
10 in_addr_t addr,
11 in_port_t port)
12 {
13 size_t len;
14 ngx_listening_t *ls;
15 struct sockaddr_in *addr_in;
16
17 if (!(ls = ngx_array_push(&cf->cycle->listening))) {
18 return NULL;
19 }
20
21 ngx_memzero(ls, sizeof(ngx_listening_t));
22
23 if (!(addr_in = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in)))) {
24 return NULL;
25 }
26
27 #if (HAVE_SIN_LEN)
28 addr_in->sin_len = sizeof(struct sockaddr_in);
29 #endif
30 addr_in->sin_family = AF_INET;
31 addr_in->sin_addr.s_addr = addr;
32 addr_in->sin_port = htons(port);
33
34 if (!(ls->addr_text.data = ngx_palloc(cf->pool, INET_ADDRSTRLEN + 6))) {
35 return NULL;
36 }
37
38 len = ngx_inet_ntop(AF_INET, &addr, ls->addr_text.data, INET_ADDRSTRLEN);
39 ls->addr_text.len = ngx_snprintf((char *) ls->addr_text.data + len,
40 6, ":%d", port);
41
42 ls->fd = (ngx_socket_t) -1;
43 ls->family = AF_INET;
44 ls->type = SOCK_STREAM;
45 ls->protocol = IPPROTO_IP;
46 #if (WIN32)
47 ls->flags = WSA_FLAG_OVERLAPPED;
48 #endif
49 ls->sockaddr = (struct sockaddr *) addr_in;
50 ls->socklen = sizeof(struct sockaddr_in);
51 ls->addr = offsetof(struct sockaddr_in, sin_addr);
52 ls->addr_text_max_len = INET_ADDRSTRLEN;
53
54 return ls;
55 }
756
857
958 ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle)
250299 }
251300
252301
302 void ngx_close_connection(ngx_connection_t *c)
303 {
304 ngx_socket_t fd;
305
306 if (c->pool == NULL) {
307 ngx_log_error(NGX_LOG_ALERT, c->log, 0, "connection already closed");
308 return;
309 }
310
311 #if (NGX_OPENSSL)
312
313 if (c->ssl) {
314 if (ngx_ssl_shutdown(c) == NGX_AGAIN) {
315 c->read->event_handler = ngx_ssl_close_handler;
316 c->write->event_handler = ngx_ssl_close_handler;
317 return;
318 }
319 }
320
321 #endif
322
323 if (c->read->timer_set) {
324 ngx_del_timer(c->read);
325 }
326
327 if (c->write->timer_set) {
328 ngx_del_timer(c->write);
329 }
330
331 if (ngx_del_conn) {
332 ngx_del_conn(c, NGX_CLOSE_EVENT);
333
334 } else {
335 if (c->read->active || c->read->disabled) {
336 ngx_del_event(c->read, NGX_READ_EVENT, NGX_CLOSE_EVENT);
337 }
338
339 if (c->write->active || c->write->disabled) {
340 ngx_del_event(c->write, NGX_WRITE_EVENT, NGX_CLOSE_EVENT);
341 }
342 }
343
344 #if (NGX_THREADS)
345
346 /*
347 * we have to clean the connection information before the closing
348 * because another thread may reopen the same file descriptor
349 * before we clean the connection
350 */
351
352 if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_OK) {
353
354 if (c->read->prev) {
355 ngx_delete_posted_event(c->read);
356 }
357
358 if (c->write->prev) {
359 ngx_delete_posted_event(c->write);
360 }
361
362 c->read->closed = 1;
363 c->write->closed = 1;
364
365 if (c->single_connection) {
366 ngx_unlock(&c->lock);
367 c->read->locked = 0;
368 c->write->locked = 0;
369 }
370
371 ngx_mutex_unlock(ngx_posted_events_mutex);
372 }
373
374 #else
375
376 if (c->read->prev) {
377 ngx_delete_posted_event(c->read);
378 }
379
380 if (c->write->prev) {
381 ngx_delete_posted_event(c->write);
382 }
383
384 c->read->closed = 1;
385 c->write->closed = 1;
386
387 #endif
388
389 fd = c->fd;
390 c->fd = (ngx_socket_t) -1;
391 c->data = NULL;
392
393 ngx_destroy_pool(c->pool);
394
395 if (ngx_close_socket(fd) == -1) {
396
397 /* we use ngx_cycle->log because c->log was in c->pool */
398
399 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
400 ngx_close_socket_n " failed");
401 }
402 }
403
404
405
253406 ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
254407 {
255408 ngx_uint_t level;
128128 #endif
129129
130130
131 ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
132 in_addr_t addr,
133 in_port_t port);
131134 ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle);
132135 ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle);
133136 void ngx_close_listening_sockets(ngx_cycle_t *cycle);
137 void ngx_close_connection(ngx_connection_t *c);
134138 ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text);
135139
136140
4646 };
4747
4848 static const char *debug_levels[] = {
49 "debug_core", "debug_alloc", "debug_mutex", "debug_event", "debug_http"
49 "debug_core", "debug_alloc", "debug_mutex", "debug_event",
50 "debug_http", "debug_imap"
5051 };
5152
5253
2020 #define NGX_LOG_DEBUG_MUTEX 0x040
2121 #define NGX_LOG_DEBUG_EVENT 0x080
2222 #define NGX_LOG_DEBUG_HTTP 0x100
23 #define NGX_LOG_DEBUG_IMAP 0x200
24
25 /*
26 * after the adding a new debug level do not forget to update
27 * debug_levels[] in src/core/ngx_log.c
28 */
2329
2430 #define NGX_LOG_DEBUG_FIRST NGX_LOG_DEBUG_CORE
25 #define NGX_LOG_DEBUG_LAST NGX_LOG_DEBUG_HTTP
31 #define NGX_LOG_DEBUG_LAST NGX_LOG_DEBUG_IMAP
2632 #define NGX_LOG_DEBUG_CONNECTION 0x80000000
2733 #define NGX_LOG_DEBUG_ALL 0x7ffffff0
2834
387387
388388 #define ngx_recv ngx_io.recv
389389 #define ngx_recv_chain ngx_io.recv_chain
390 #define ngx_send ngx_io.send
390391 #define ngx_send_chain ngx_io.send_chain
391392
392393
251251 ngx_memzero(&addr, sizeof(struct sockaddr_in));
252252
253253 addr.sin_family = AF_INET;
254 addr.sin_port = (u_short) peer->port;
254 addr.sin_port = peer->port;
255255 addr.sin_addr.s_addr = peer->addr;
256256
257257 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pc->log, 0,
280280 size_t len;
281281 socklen_t slen;
282282 struct sockaddr_in addr_in;
283 uint32_t service;
284283 ngx_str_t src, dst;
285284 ngx_table_elt_t *set_cookie;
286285
541540
542541 if (domain->len == 4 && ngx_strcmp(domain->data, "none") == 0) {
543542 domain->len = 1;
544 domain->data = ".";
543 domain->data = (u_char *) ".";
545544 }
546545
547546 return NGX_CONF_OK;
12331233 u->default_port = 1;
12341234 }
12351235
1236 u->port = htons((u_short) u->port);
1236 u->port = htons(u->port);
12371237 return NULL;
12381238 }
12391239 }
12641264 if (u->port_text.len > 0) {
12651265 u->port = ngx_atoi(u->port_text.data, u->port_text.len);
12661266 if (u->port > 0) {
1267 u->port = htons((u_short) u->port);
1267 u->port = htons(u->port);
12681268 return NULL;
12691269 }
12701270 }
4040 ngx_str_t port_text;
4141 ngx_str_t *location;
4242
43 ngx_int_t port;
43 in_port_t port;
4444
4545 unsigned default_port:1;
4646 } ngx_http_proxy_upstream_conf_t;
499499 in_addr = in_port[p].addrs.elts;
500500 while (a < in_port[p].addrs.nelts) {
501501
502 if (!(ls = ngx_push_array(&cf->cycle->listening))) {
502 ls = ngx_listening_inet_stream_socket(cf, in_addr[a].addr,
503 in_port[p].port);
504 if (ls == NULL) {
503505 return NGX_CONF_ERROR;
504506 }
505507
506 ngx_memzero(ls, sizeof(ngx_listening_t));
507
508 addr_in = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
509 if (addr_in == NULL) {
510 return NGX_CONF_ERROR;
511 }
512
513 #if (HAVE_SIN_LEN)
514 addr_in->sin_len = sizeof(struct sockaddr_in);
515 #endif
516 addr_in->sin_family = AF_INET;
517 addr_in->sin_addr.s_addr = in_addr[a].addr;
518 addr_in->sin_port = htons((u_short) in_port[p].port);
519
520 ls->addr_text.data = ngx_palloc(cf->pool, INET_ADDRSTRLEN + 6);
521 if (ls->addr_text.data == NULL) {
522 return NGX_CONF_ERROR;
523 }
524
525 ls->addr_text.len = ngx_inet_ntop(AF_INET, &in_addr[a].addr,
526 ls->addr_text.data,
527 INET_ADDRSTRLEN),
528
529 ls->addr_text.len += ngx_snprintf((char *) ls->addr_text.data
530 + ls->addr_text.len,
531 6, ":%d", in_port[p].port);
532
533 ls->fd = (ngx_socket_t) -1;
534 ls->family = AF_INET;
535 ls->type = SOCK_STREAM;
536 ls->protocol = IPPROTO_IP;
537 #if (WIN32)
538 ls->flags = WSA_FLAG_OVERLAPPED;
539 #endif
540 ls->sockaddr = (struct sockaddr *) addr_in;
541 ls->socklen = sizeof(struct sockaddr_in);
542 ls->addr = offsetof(struct sockaddr_in, sin_addr);
543 ls->addr_text_max_len = INET_ADDRSTRLEN;
544508 ls->backlog = -1;
545509 #if 0
546510 #if 0
14721472 ngx_http_core_srv_conf_t *scf = conf;
14731473
14741474 u_char *addr;
1475 u_int p;
1475 ngx_int_t port;
1476 ngx_uint_t p;
14761477 struct hostent *h;
14771478 ngx_str_t *args;
14781479 ngx_http_listen_t *ls;
15041505 p = 0;
15051506 }
15061507
1507 ls->port = ngx_atoi(&addr[p], args[1].len - p);
1508 if (ls->port == NGX_ERROR && p == 0) {
1508 port = ngx_atoi(&addr[p], args[1].len - p);
1509 if (port == NGX_ERROR && p == 0) {
15091510
15101511 /* "listen host" */
15111512 ls->port = 80;
15121513
1513 } else if ((ls->port == NGX_ERROR && p != 0) /* "listen host:NONNUMBER" */
1514 || (ls->port < 1 || ls->port > 65536)) { /* "listen 99999" */
1514 } else if ((port == NGX_ERROR && p != 0) /* "listen host:NONNUMBER" */
1515 || (port < 1 || port > 65536)) { /* "listen 99999" */
15151516
15161517 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
15171518 "invalid port \"%s\" in \"%s\" directive, "
15221523
15231524 } else if (p == 0) {
15241525 ls->addr = INADDR_ANY;
1526 ls->port = (in_port_t) port;
15251527 return NGX_CONF_OK;
15261528 }
15271529
88
99 typedef struct {
1010 in_addr_t addr;
11 int port;
11 in_port_t port;
1212 int family;
1313 ngx_str_t file_name;
1414 int line;
7777 /* list of structures to find core_srv_conf quickly at run time */
7878
7979 typedef struct {
80 int port;
80 in_port_t port;
8181 ngx_str_t port_name;
8282 ngx_array_t addrs; /* array of ngx_http_in_addr_t */
8383 } ngx_http_in_port_t;
11 #include <ngx_config.h>
22 #include <ngx_core.h>
33 #include <ngx_http.h>
4
45
56 ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r)
67 {
18981898
18991899 void ngx_http_close_connection(ngx_connection_t *c)
19001900 {
1901 ngx_socket_t fd;
1902
19031901 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
19041902 "close http connection: %d", c->fd);
19051903
1906 if (c->pool == NULL) {
1907 ngx_log_error(NGX_LOG_ALERT, c->log, 0, "connection already closed");
1908 return;
1909 }
1910
1911 #if (NGX_HTTP_SSL)
1912
1913 if (c->ssl) {
1914 if (ngx_ssl_shutdown(c) == NGX_AGAIN) {
1915 c->read->event_handler = ngx_ssl_close_handler;
1916 c->write->event_handler = ngx_ssl_close_handler;
1917 return;
1918 }
1919 }
1920
1921 #endif
1922
1923 if (c->read->timer_set) {
1924 ngx_del_timer(c->read);
1925 }
1926
1927 if (c->write->timer_set) {
1928 ngx_del_timer(c->write);
1929 }
1930
1931 if (ngx_del_conn) {
1932 ngx_del_conn(c, NGX_CLOSE_EVENT);
1933
1934 } else {
1935 if (c->read->active || c->read->disabled) {
1936 ngx_del_event(c->read, NGX_READ_EVENT, NGX_CLOSE_EVENT);
1937 }
1938
1939 if (c->write->active || c->write->disabled) {
1940 ngx_del_event(c->write, NGX_WRITE_EVENT, NGX_CLOSE_EVENT);
1941 }
1942 }
1943
1944 /*
1945 * we have to clean the connection information before the closing
1946 * because another thread may reopen the same file descriptor
1947 * before we clean the connection
1948 */
1949
1950 #if (NGX_THREADS)
1951
1952 if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_OK) {
1953
1954 if (c->read->prev) {
1955 ngx_delete_posted_event(c->read);
1956 }
1957
1958 if (c->write->prev) {
1959 ngx_delete_posted_event(c->write);
1960 }
1961
1962 c->read->closed = 1;
1963 c->write->closed = 1;
1964
1965 if (c->single_connection) {
1966 ngx_unlock(&c->lock);
1967 c->read->locked = 0;
1968 c->write->locked = 0;
1969 }
1970
1971 ngx_mutex_unlock(ngx_posted_events_mutex);
1972 }
1973
1974 #else
1975
1976 if (c->read->prev) {
1977 ngx_delete_posted_event(c->read);
1978 }
1979
1980 if (c->write->prev) {
1981 ngx_delete_posted_event(c->write);
1982 }
1983
1984 c->read->closed = 1;
1985 c->write->closed = 1;
1986
1987 #endif
1988
1989 fd = c->fd;
1990 c->fd = (ngx_socket_t) -1;
1991 c->data = NULL;
1992
1993 ngx_destroy_pool(c->pool);
1994
1995 if (ngx_close_socket(fd) == -1) {
1996
1997 /* we use ngx_cycle->log because c->log was in c->pool */
1998
1999 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
2000 ngx_close_socket_n " failed");
2001 }
2002
2003 return;
1904 ngx_close_connection(c);
20041905 }
20051906
20061907
11 #include <ngx_config.h>
22 #include <ngx_core.h>
33 #include <ngx_event.h>
4 #include <ngx_imap.h>
5
6
7 static char *ngx_imap_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
48
59
610 static ngx_command_t ngx_imap_commands[] = {
2933 ngx_imap_commands, /* module directives */
3034 NGX_CORE_MODULE, /* module type */
3135 NULL, /* init module */
32 NULL /* init child */
36 NULL /* init process */
3337 };
38
39
40 static char *ngx_imap_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
41 {
42 ngx_listening_t *ls;
43
44 /* STUB */
45
46 ls = ngx_listening_inet_stream_socket(cf, 0, 8110);
47 if (ls == NULL) {
48 return NGX_CONF_ERROR;
49 }
50
51 ls->backlog = -1;
52 ls->handler = ngx_imap_init_connection;
53 ls->pool_size = 16384;
54 /* ls->post_accept_timeout = 0; */
55 ls->log = cf->cycle->new_log;
56
57 /* */
58
59 return NGX_CONF_OK;
60 }
0 #ifndef _NGX_IMAP_H_INCLUDED_
1 #define _NGX_IMAP_H_INCLUDED_
2
3
4 #include <ngx_config.h>
5 #include <ngx_core.h>
6
7
8 typedef struct {
9 ngx_chain_t *send;
10 } ngx_imap_request_t;
11
12
13 #define NGX_POP3_USER 1
14 #define NGX_POP3_PASS 2
15 #define NGX_POP3_APOP 3
16 #define NGX_POP3_STAT 4
17 #define NGX_POP3_LIST 5
18 #define NGX_POP3_RETR 6
19 #define NGX_POP3_DELE 7
20 #define NGX_POP3_NOOP 8
21 #define NGX_POP3_RSET 9
22 #define NGX_POP3_TOP 10
23 #define NGX_POP3_UIDL 11
24 #define NGX_POP3_QUIT 12
25
26
27 void ngx_imap_init_connection(ngx_connection_t *c);
28 void ngx_imap_close_connection(ngx_connection_t *c);
29
30
31 #endif /* _NGX_IMAP_H_INCLUDED_ */
11 #include <ngx_config.h>
22 #include <ngx_core.h>
33 #include <ngx_event.h>
4 #include <ngx_imap.h>
5 #include <nginx.h>
6
7
8 static void ngx_imap_auth_state(ngx_event_t *rev);
9
10
11 static char pop3_greeting[] = "+OK " NGINX_VER " ready" CRLF;
12 static char imap_greeting[] = "* OK " NGINX_VER " ready" CRLF;
413
514
615 void ngx_imap_init_connection(ngx_connection_t *c)
716 {
17 ngx_int_t rc;
18
819 ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0,
920 "imap init connection");
1021
11 if (ngx_close_socket(c->fd) == -1) {
22 c->log_error = NGX_ERROR_INFO;
1223
13 /* we use ngx_cycle->log because c->log was in c->pool */
24 rc = ngx_send(c, pop3_greeting, sizeof(pop3_greeting) - 1);
1425
15 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
16 ngx_close_socket_n " failed");
26 if (rc == NGX_ERROR) {
27 ngx_imap_close_connection(c);
28 return;
29 }
30
31 c->read->event_handler = ngx_imap_auth_state;
32
33 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
34 ngx_imap_close_connection(c);
35 return;
1736 }
1837 }
38
39
40 static void ngx_imap_auth_state(ngx_event_t *rev)
41 {
42 ngx_connection_t *c;
43
44 c = rev->data;
45
46 ngx_imap_close_connection(c);
47 }
48
49
50 void ngx_imap_close_connection(ngx_connection_t *c)
51 {
52 ngx_log_debug1(NGX_LOG_DEBUG_IMAP, c->log, 0,
53 "close imap connection: %d", c->fd);
54
55 ngx_close_connection(c);
56 }
0
1 #include <ngx_config.h>
2 #include <ngx_core.h>
3 #include <ngx_event.h>
4 #include <ngx_imap.h>
5
6
7 ngx_int_t ngx_pop3_parse_command(ngx_imap_request_t *r)
8 {
9 u_char ch, *p, *c;
10 enum {
11 sw_start = 0,
12 sw_done
13 } state;
14
15 while (p < r->buf->last && state < sw_done) {
16 ch = *p++;
17
18 switch (state) {
19
20 /* POP3 commands */
21 case sw_start:
22 if (ch == ' ') {
23 c = r->buf->start;
24
25 if (p - 1 - m == 4) {
26
27 if (*c == 'U' && *(c + 1) == 'S'
28 && *(c + 2) == 'E' && *(c + 3) == 'R')
29 {
30 r->command = NGX_POP3_USER;
31
32 } else if (*c == 'P' && *(c + 1) == 'A'
33 && *(c + 2) == 'A' && *(c + 3) == 'S')
34 {
35 r->method = NGX_POP3_PASS;
36
37 } else if (*c == 'Q' && *(c + 1) == 'U'
38 && *(c + 2) == 'I' && *(c + 3) == 'T')
39 {
40 r->method = NGX_POP3_QUIT;
41
42 } else if (*c == 'N' && *(c + 1) == 'O'
43 && *(c + 2) == 'O' && *(c + 3) == 'P')
44 {
45 r->method = NGX_POP3_NOOP;
46 }
47 }
48
49 state = sw_spaces_before_arg;
50 break;
51 }
52
53 if (ch < 'A' || ch > 'Z') {
54 return NGX_IMAP_PARSE_INVALID_COMMAND;
55 }
56
57 break;
58 }
59
60 /* suppress warning */
61 case sw_done:
62 break;
63 }
64 }
65
66 return NGX_OK;
67 }
1919 ngx_os_io_t ngx_os_io = {
2020 ngx_unix_recv,
2121 ngx_readv_chain,
22 NULL,
22 ngx_unix_send,
2323 #if (HAVE_SENDFILE)
2424 ngx_freebsd_sendfile_chain,
2525 NGX_IO_SENDFILE
1111 ngx_os_io_t ngx_os_io = {
1212 ngx_unix_recv,
1313 ngx_readv_chain,
14 NULL,
14 ngx_unix_send,
1515 #if (HAVE_SENDFILE)
1616 ngx_linux_sendfile_chain,
1717 NGX_IO_SENDFILE
3232 ngx_recv_chain_pt recv_chain;
3333 ngx_send_pt send;
3434 ngx_send_chain_pt send_chain;
35 int flags;
35 ngx_uint_t flags;
3636 } ngx_os_io_t;
3737
3838
4545
4646 ssize_t ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size);
4747 ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *entry);
48 ssize_t ngx_unix_send(ngx_connection_t *c, u_char *buf, size_t size);
4849 ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in,
4950 off_t limit);
5051
0
1 #include <ngx_config.h>
2 #include <ngx_core.h>
3 #include <ngx_event.h>
4
5
6 ssize_t ngx_unix_send(ngx_connection_t *c, u_char *buf, size_t size)
7 {
8 ssize_t n;
9 ngx_err_t err;
10 ngx_event_t *wev;
11
12 wev = c->write;
13
14 #if (HAVE_KQUEUE)
15
16 if ((ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) && wev->pending_eof) {
17 ngx_log_error(NGX_LOG_INFO, c->log, wev->kq_errno,
18 "kevent() reported about an closed connection");
19
20 wev->error = 1;
21 return NGX_ERROR;
22 }
23
24 #endif
25
26 for ( ;; ) {
27 n = send(c->fd, buf, size, 0);
28
29 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
30 "send: fd:%d %d of %d", c->fd, n, size);
31
32 if (n > 0) {
33 if (n < (ssize_t) size) {
34 wev->ready = 0;
35 }
36
37 return n;
38 }
39
40 err = ngx_socket_errno;
41
42 if (n == 0) {
43 ngx_log_error(NGX_LOG_ALERT, c->log, err, "send() returned zero");
44 }
45
46 if (err == NGX_EAGAIN || err == NGX_EINTR) {
47 wev->ready = 0;
48
49 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
50 "send() not ready");
51
52 if (err == NGX_EAGAIN) {
53 return NGX_AGAIN;
54 }
55
56 } else {
57 wev->error = 1;
58 ngx_connection_error(c, err, "recv() failed");
59 return NGX_ERROR;
60 }
61 }
62 }
1010 ngx_os_io_t ngx_os_io = {
1111 ngx_unix_recv,
1212 ngx_readv_chain,
13 NULL,
13 ngx_unix_send,
1414 #if (HAVE_SENDFILE)
1515 ngx_solaris_sendfilev_chain,
1616 NGX_IO_SENDFILE
3131 ngx_recv_chain_pt recv_chain;
3232 ngx_send_pt send;
3333 ngx_send_chain_pt send_chain;
34 int flags;
34 ngx_uint_t flags;
3535 } ngx_os_io_t;
3636
3737