nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev
17 years ago
0 | 0 | |
1 | 1 | mkdir -p $OBJS/src/core $OBJS/src/event $OBJS/src/event/modules \ |
2 | 2 | $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 | |
4 | 5 | |
5 | 6 | |
6 | 7 | echo "CC = $CC" > $MAKEFILE |
17 | 18 | echo >> $MAKEFILE |
18 | 19 | fi |
19 | 20 | |
20 | all_inc="$CORE_INCS $OBJS $HTTP_INCS" | |
21 | all_inc="$CORE_INCS $OBJS $HTTP_INCS $IMAP_INCS" | |
21 | 22 | all_inc=`echo " $all_inc" | sed -e "s/ \([^ ]\)/ $INCOPT\1/g"` |
22 | 23 | all_inc=`echo $all_inc | sed -e "s/\//$DIRSEP/g"` |
23 | 24 | |
24 | 25 | echo "ALL_INCS = $all_inc" >> $MAKEFILE |
25 | 26 | echo >> $MAKEFILE |
26 | 27 | |
28 | all_srcs="$CORE_SRCS" | |
29 | ||
27 | 30 | |
28 | 31 | # CORE_DEPS |
29 | 32 | |
59 | 62 | echo >> $MAKEFILE |
60 | 63 | |
61 | 64 | |
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 | |
94 | 143 | |
95 | 144 | |
96 | 145 | # nginx |
104 | 153 | |
105 | 154 | # nginx deps |
106 | 155 | |
107 | for src in $CORE_SRCS $HTTP_SRCS | |
156 | for src in $all_srcs | |
108 | 157 | do |
109 | 158 | obj=`echo $src | sed -e "s/\.c\$/.$OBJEXT/" -e "s/\.S\$/.$OBJEXT/"` |
110 | 159 | obj=`echo $OBJS/$obj | sed -e "s/\//$DIRSEP/g"` |
141 | 190 | |
142 | 191 | # nginx build sources |
143 | 192 | |
144 | for src in $CORE_SRCS $HTTP_SRCS | |
193 | for src in $all_srcs | |
145 | 194 | do |
146 | 195 | obj=`echo $src | sed -e "s/\.c\$/.$OBJEXT/" -e "s/\.S\$/.$OBJEXT/"` |
147 | 196 | obj=`echo $OBJS/$obj | sed -e "s/\//$DIRSEP/g"` |
222 | 271 | |
223 | 272 | # http sources |
224 | 273 | |
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 | |
252 | 340 | |
253 | 341 | |
254 | 342 | # precompiled headers |
135 | 135 | $HTTP_NOT_MODIFIED_FILTER_MODULE" |
136 | 136 | fi |
137 | 137 | |
138 | IMAP_MODULES=$IMAP_MODULE | |
139 | ||
140 | if [ $IMAP = YES ]; then | |
141 | modules="$modules $IMAP_MODULES" | |
142 | fi | |
143 | ||
138 | 144 | |
139 | 145 | echo "#include <ngx_config.h>" > $NGX_MODULES_C |
140 | 146 | echo "#include <ngx_core.h>" >> $NGX_MODULES_C |
38 | 38 | HTTP_STATUS=YES |
39 | 39 | HTTP_REWRITE=YES |
40 | 40 | HTTP_PROXY=YES |
41 | ||
42 | IMAP=NO | |
41 | 43 | |
42 | 44 | USE_PCRE=NO |
43 | 45 | PCRE=NONE |
99 | 101 | --without-http_status_module) HTTP_STATUS=NO ;; |
100 | 102 | --without-http_rewrite_module) HTTP_REWRITE=NO ;; |
101 | 103 | --without-http_proxy_module) HTTP_PROXY=NO ;; |
104 | ||
105 | --with-imap) IMAP=YES ;; | |
102 | 106 | |
103 | 107 | --with-cc=*) CC="$value" ;; |
104 | 108 | --with-cpp=*) CPP="$value" ;; |
3 | 3 | CORE_INCS="src/core" |
4 | 4 | |
5 | 5 | 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" | |
26 | 26 | |
27 | 27 | 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" | |
46 | 46 | |
47 | 47 | |
48 | 48 | REGEX_DEPS=src/core/ngx_regex.h |
127 | 127 | src/os/unix/ngx_socket.c \ |
128 | 128 | src/os/unix/ngx_recv.c \ |
129 | 129 | src/os/unix/ngx_readv_chain.c \ |
130 | src/os/unix/ngx_send.c \ | |
130 | 131 | src/os/unix/ngx_writev_chain.c \ |
131 | 132 | src/os/unix/ngx_channel.c \ |
132 | 133 | src/os/unix/ngx_shared.c \ |
190 | 191 | |
191 | 192 | |
192 | 193 | 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" | |
195 | 196 | |
196 | 197 | HTTP_FILE_CACHE_MODULE=ngx_http_cache_module |
197 | 198 | |
213 | 214 | HTTP_INCS="src/http src/http/modules" |
214 | 215 | |
215 | 216 | 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" | |
222 | 223 | |
223 | 224 | 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" | |
240 | 241 | |
241 | 242 | # STUB |
242 | 243 | HTTP_SRCS="$HTTP_SRCS src/http/ngx_http_busy_lock.c" |
282 | 283 | HTTP_PROXY_INCS="src/http/modules/proxy" |
283 | 284 | HTTP_PROXY_DEPS=src/http/modules/proxy/ngx_http_proxy_handler.h |
284 | 285 | 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" | |
288 | 289 | |
289 | 290 | # 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" |
30 | 30 | ngx_type="socklen_t"; ngx_types="uint32_t"; . auto/types/typedef |
31 | 31 | |
32 | 32 | 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 | |
33 | 35 | |
34 | 36 | ngx_type="rlim_t"; ngx_types="int"; . auto/types/typedef |
35 | 37 |
40 | 40 | ngx_test_null(a.elts, ngx_palloc(p, n * s), rc); \ |
41 | 41 | a.nelts = 0; a.size = s; a.nalloc = n; a.pool = p; |
42 | 42 | |
43 | #define ngx_array_push ngx_push_array | |
44 | ||
43 | 45 | |
44 | 46 | #endif /* _NGX_ARRAY_H_INCLUDED_ */ |
4 | 4 | |
5 | 5 | |
6 | 6 | 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 | } | |
7 | 56 | |
8 | 57 | |
9 | 58 | ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle) |
250 | 299 | } |
251 | 300 | |
252 | 301 | |
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 | ||
253 | 406 | ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text) |
254 | 407 | { |
255 | 408 | ngx_uint_t level; |
128 | 128 | #endif |
129 | 129 | |
130 | 130 | |
131 | ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf, | |
132 | in_addr_t addr, | |
133 | in_port_t port); | |
131 | 134 | ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle); |
132 | 135 | ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle); |
133 | 136 | void ngx_close_listening_sockets(ngx_cycle_t *cycle); |
137 | void ngx_close_connection(ngx_connection_t *c); | |
134 | 138 | ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text); |
135 | 139 | |
136 | 140 |
46 | 46 | }; |
47 | 47 | |
48 | 48 | 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" | |
50 | 51 | }; |
51 | 52 | |
52 | 53 |
20 | 20 | #define NGX_LOG_DEBUG_MUTEX 0x040 |
21 | 21 | #define NGX_LOG_DEBUG_EVENT 0x080 |
22 | 22 | #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 | */ | |
23 | 29 | |
24 | 30 | #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 | |
26 | 32 | #define NGX_LOG_DEBUG_CONNECTION 0x80000000 |
27 | 33 | #define NGX_LOG_DEBUG_ALL 0x7ffffff0 |
28 | 34 |
387 | 387 | |
388 | 388 | #define ngx_recv ngx_io.recv |
389 | 389 | #define ngx_recv_chain ngx_io.recv_chain |
390 | #define ngx_send ngx_io.send | |
390 | 391 | #define ngx_send_chain ngx_io.send_chain |
391 | 392 | |
392 | 393 |
251 | 251 | ngx_memzero(&addr, sizeof(struct sockaddr_in)); |
252 | 252 | |
253 | 253 | addr.sin_family = AF_INET; |
254 | addr.sin_port = (u_short) peer->port; | |
254 | addr.sin_port = peer->port; | |
255 | 255 | addr.sin_addr.s_addr = peer->addr; |
256 | 256 | |
257 | 257 | ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pc->log, 0, |
280 | 280 | size_t len; |
281 | 281 | socklen_t slen; |
282 | 282 | struct sockaddr_in addr_in; |
283 | uint32_t service; | |
284 | 283 | ngx_str_t src, dst; |
285 | 284 | ngx_table_elt_t *set_cookie; |
286 | 285 | |
541 | 540 | |
542 | 541 | if (domain->len == 4 && ngx_strcmp(domain->data, "none") == 0) { |
543 | 542 | domain->len = 1; |
544 | domain->data = "."; | |
543 | domain->data = (u_char *) "."; | |
545 | 544 | } |
546 | 545 | |
547 | 546 | return NGX_CONF_OK; |
1233 | 1233 | u->default_port = 1; |
1234 | 1234 | } |
1235 | 1235 | |
1236 | u->port = htons((u_short) u->port); | |
1236 | u->port = htons(u->port); | |
1237 | 1237 | return NULL; |
1238 | 1238 | } |
1239 | 1239 | } |
1264 | 1264 | if (u->port_text.len > 0) { |
1265 | 1265 | u->port = ngx_atoi(u->port_text.data, u->port_text.len); |
1266 | 1266 | if (u->port > 0) { |
1267 | u->port = htons((u_short) u->port); | |
1267 | u->port = htons(u->port); | |
1268 | 1268 | return NULL; |
1269 | 1269 | } |
1270 | 1270 | } |
40 | 40 | ngx_str_t port_text; |
41 | 41 | ngx_str_t *location; |
42 | 42 | |
43 | ngx_int_t port; | |
43 | in_port_t port; | |
44 | 44 | |
45 | 45 | unsigned default_port:1; |
46 | 46 | } ngx_http_proxy_upstream_conf_t; |
499 | 499 | in_addr = in_port[p].addrs.elts; |
500 | 500 | while (a < in_port[p].addrs.nelts) { |
501 | 501 | |
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) { | |
503 | 505 | return NGX_CONF_ERROR; |
504 | 506 | } |
505 | 507 | |
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; | |
544 | 508 | ls->backlog = -1; |
545 | 509 | #if 0 |
546 | 510 | #if 0 |
1472 | 1472 | ngx_http_core_srv_conf_t *scf = conf; |
1473 | 1473 | |
1474 | 1474 | u_char *addr; |
1475 | u_int p; | |
1475 | ngx_int_t port; | |
1476 | ngx_uint_t p; | |
1476 | 1477 | struct hostent *h; |
1477 | 1478 | ngx_str_t *args; |
1478 | 1479 | ngx_http_listen_t *ls; |
1504 | 1505 | p = 0; |
1505 | 1506 | } |
1506 | 1507 | |
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) { | |
1509 | 1510 | |
1510 | 1511 | /* "listen host" */ |
1511 | 1512 | ls->port = 80; |
1512 | 1513 | |
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" */ | |
1515 | 1516 | |
1516 | 1517 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1517 | 1518 | "invalid port \"%s\" in \"%s\" directive, " |
1522 | 1523 | |
1523 | 1524 | } else if (p == 0) { |
1524 | 1525 | ls->addr = INADDR_ANY; |
1526 | ls->port = (in_port_t) port; | |
1525 | 1527 | return NGX_CONF_OK; |
1526 | 1528 | } |
1527 | 1529 |
8 | 8 | |
9 | 9 | typedef struct { |
10 | 10 | in_addr_t addr; |
11 | int port; | |
11 | in_port_t port; | |
12 | 12 | int family; |
13 | 13 | ngx_str_t file_name; |
14 | 14 | int line; |
77 | 77 | /* list of structures to find core_srv_conf quickly at run time */ |
78 | 78 | |
79 | 79 | typedef struct { |
80 | int port; | |
80 | in_port_t port; | |
81 | 81 | ngx_str_t port_name; |
82 | 82 | ngx_array_t addrs; /* array of ngx_http_in_addr_t */ |
83 | 83 | } ngx_http_in_port_t; |
1 | 1 | #include <ngx_config.h> |
2 | 2 | #include <ngx_core.h> |
3 | 3 | #include <ngx_http.h> |
4 | ||
4 | 5 | |
5 | 6 | ngx_int_t ngx_http_parse_request_line(ngx_http_request_t *r) |
6 | 7 | { |
1898 | 1898 | |
1899 | 1899 | void ngx_http_close_connection(ngx_connection_t *c) |
1900 | 1900 | { |
1901 | ngx_socket_t fd; | |
1902 | ||
1903 | 1901 | ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
1904 | 1902 | "close http connection: %d", c->fd); |
1905 | 1903 | |
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); | |
2004 | 1905 | } |
2005 | 1906 | |
2006 | 1907 |
1 | 1 | #include <ngx_config.h> |
2 | 2 | #include <ngx_core.h> |
3 | 3 | #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); | |
4 | 8 | |
5 | 9 | |
6 | 10 | static ngx_command_t ngx_imap_commands[] = { |
29 | 33 | ngx_imap_commands, /* module directives */ |
30 | 34 | NGX_CORE_MODULE, /* module type */ |
31 | 35 | NULL, /* init module */ |
32 | NULL /* init child */ | |
36 | NULL /* init process */ | |
33 | 37 | }; |
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_ */ |
1 | 1 | #include <ngx_config.h> |
2 | 2 | #include <ngx_core.h> |
3 | 3 | #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; | |
4 | 13 | |
5 | 14 | |
6 | 15 | void ngx_imap_init_connection(ngx_connection_t *c) |
7 | 16 | { |
17 | ngx_int_t rc; | |
18 | ||
8 | 19 | ngx_log_debug0(NGX_LOG_DEBUG_IMAP, c->log, 0, |
9 | 20 | "imap init connection"); |
10 | 21 | |
11 | if (ngx_close_socket(c->fd) == -1) { | |
22 | c->log_error = NGX_ERROR_INFO; | |
12 | 23 | |
13 | /* we use ngx_cycle->log because c->log was in c->pool */ | |
24 | rc = ngx_send(c, pop3_greeting, sizeof(pop3_greeting) - 1); | |
14 | 25 | |
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; | |
17 | 36 | } |
18 | 37 | } |
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 | } |
19 | 19 | ngx_os_io_t ngx_os_io = { |
20 | 20 | ngx_unix_recv, |
21 | 21 | ngx_readv_chain, |
22 | NULL, | |
22 | ngx_unix_send, | |
23 | 23 | #if (HAVE_SENDFILE) |
24 | 24 | ngx_freebsd_sendfile_chain, |
25 | 25 | NGX_IO_SENDFILE |
11 | 11 | ngx_os_io_t ngx_os_io = { |
12 | 12 | ngx_unix_recv, |
13 | 13 | ngx_readv_chain, |
14 | NULL, | |
14 | ngx_unix_send, | |
15 | 15 | #if (HAVE_SENDFILE) |
16 | 16 | ngx_linux_sendfile_chain, |
17 | 17 | NGX_IO_SENDFILE |
32 | 32 | ngx_recv_chain_pt recv_chain; |
33 | 33 | ngx_send_pt send; |
34 | 34 | ngx_send_chain_pt send_chain; |
35 | int flags; | |
35 | ngx_uint_t flags; | |
36 | 36 | } ngx_os_io_t; |
37 | 37 | |
38 | 38 | |
45 | 45 | |
46 | 46 | ssize_t ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size); |
47 | 47 | 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); | |
48 | 49 | ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, |
49 | 50 | off_t limit); |
50 | 51 |
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 | } |