├── .github └── CODEOWNERS ├── LICENSE ├── README.md ├── SECURITY.md ├── auto ├── cc │ ├── acc │ ├── bcc │ ├── ccc │ ├── clang │ ├── conf │ ├── gcc │ ├── icc │ ├── msvc │ ├── name │ ├── owc │ └── sunc ├── configure ├── define ├── endianness ├── feature ├── have ├── have_headers ├── headers ├── include ├── init ├── install ├── lib │ ├── conf │ ├── geoip │ │ └── conf │ ├── google-perftools │ │ └── conf │ ├── libatomic │ │ ├── conf │ │ └── make │ ├── libgd │ │ └── conf │ ├── libxslt │ │ └── conf │ ├── make │ ├── openssl │ │ ├── conf │ │ ├── make │ │ ├── makefile.bcc │ │ └── makefile.msvc │ ├── pcre │ │ ├── conf │ │ ├── make │ │ ├── makefile.bcc │ │ ├── makefile.msvc │ │ └── makefile.owc │ ├── perl │ │ ├── conf │ │ └── make │ └── zlib │ │ ├── conf │ │ ├── make │ │ ├── makefile.bcc │ │ ├── makefile.msvc │ │ └── makefile.owc ├── make ├── module ├── modules ├── nohave ├── options ├── os │ ├── conf │ ├── darwin │ ├── freebsd │ ├── linux │ ├── solaris │ └── win32 ├── sources ├── stubs ├── summary ├── threads ├── types │ ├── sizeof │ ├── typedef │ ├── uintptr_t │ └── value └── unix ├── conf ├── fastcgi.conf ├── fastcgi_params ├── koi-utf ├── koi-win ├── mime.types ├── nginx.QAT-sample.conf ├── nginx.conf ├── scgi_params ├── uwsgi_params └── win-utf ├── config.example ├── configure ├── contrib ├── README ├── geo2nginx.pl ├── unicode2nginx │ ├── koi-utf │ ├── unicode-to-nginx.pl │ └── win-utf └── vim │ ├── ftdetect │ └── nginx.vim │ ├── ftplugin │ └── nginx.vim │ ├── indent │ └── nginx.vim │ └── syntax │ └── nginx.vim ├── dockerfiles ├── Dockerfile ├── README.md └── nginx.conf_qat ├── docs ├── html │ ├── 50x.html │ └── index.html └── man │ └── nginx.8 ├── modules ├── nginx_qat_module │ ├── README │ ├── config │ └── ngx_ssl_engine_qat_module.c └── nginx_qatzip_module │ ├── README │ ├── config │ └── ngx_http_qatzip_filter_module.c ├── src ├── core │ ├── nginx.c │ ├── nginx.h │ ├── ngx_array.c │ ├── ngx_array.h │ ├── ngx_bpf.c │ ├── ngx_bpf.h │ ├── ngx_buf.c │ ├── ngx_buf.h │ ├── ngx_conf_file.c │ ├── ngx_conf_file.h │ ├── ngx_config.h │ ├── ngx_connection.c │ ├── ngx_connection.h │ ├── ngx_core.h │ ├── ngx_cpuinfo.c │ ├── ngx_crc.h │ ├── ngx_crc32.c │ ├── ngx_crc32.h │ ├── ngx_crypt.c │ ├── ngx_crypt.h │ ├── ngx_cycle.c │ ├── ngx_cycle.h │ ├── ngx_file.c │ ├── ngx_file.h │ ├── ngx_hash.c │ ├── ngx_hash.h │ ├── ngx_inet.c │ ├── ngx_inet.h │ ├── ngx_list.c │ ├── ngx_list.h │ ├── ngx_log.c │ ├── ngx_log.h │ ├── ngx_md5.c │ ├── ngx_md5.h │ ├── ngx_module.c │ ├── ngx_module.h │ ├── ngx_murmurhash.c │ ├── ngx_murmurhash.h │ ├── ngx_open_file_cache.c │ ├── ngx_open_file_cache.h │ ├── ngx_output_chain.c │ ├── ngx_palloc.c │ ├── ngx_palloc.h │ ├── ngx_parse.c │ ├── ngx_parse.h │ ├── ngx_parse_time.c │ ├── ngx_parse_time.h │ ├── ngx_proxy_protocol.c │ ├── ngx_proxy_protocol.h │ ├── ngx_queue.c │ ├── ngx_queue.h │ ├── ngx_radix_tree.c │ ├── ngx_radix_tree.h │ ├── ngx_rbtree.c │ ├── ngx_rbtree.h │ ├── ngx_regex.c │ ├── ngx_regex.h │ ├── ngx_resolver.c │ ├── ngx_resolver.h │ ├── ngx_rwlock.c │ ├── ngx_rwlock.h │ ├── ngx_sha1.c │ ├── ngx_sha1.h │ ├── ngx_shmtx.c │ ├── ngx_shmtx.h │ ├── ngx_slab.c │ ├── ngx_slab.h │ ├── ngx_spinlock.c │ ├── ngx_string.c │ ├── ngx_string.h │ ├── ngx_syslog.c │ ├── ngx_syslog.h │ ├── ngx_thread_pool.c │ ├── ngx_thread_pool.h │ ├── ngx_times.c │ └── ngx_times.h ├── engine │ ├── modules │ │ └── ngx_ssl_engine_dasync_module.c │ ├── ngx_ssl_engine.c │ └── ngx_ssl_engine.h ├── event │ ├── modules │ │ ├── ngx_devpoll_module.c │ │ ├── ngx_epoll_module.c │ │ ├── ngx_eventport_module.c │ │ ├── ngx_iocp_module.c │ │ ├── ngx_iocp_module.h │ │ ├── ngx_kqueue_module.c │ │ ├── ngx_poll_module.c │ │ ├── ngx_select_module.c │ │ ├── ngx_win32_poll_module.c │ │ └── ngx_win32_select_module.c │ ├── ngx_event.c │ ├── ngx_event.h │ ├── ngx_event_accept.c │ ├── ngx_event_acceptex.c │ ├── ngx_event_connect.c │ ├── ngx_event_connect.h │ ├── ngx_event_connectex.c │ ├── ngx_event_openssl.c │ ├── ngx_event_openssl.h │ ├── ngx_event_openssl_stapling.c │ ├── ngx_event_pipe.c │ ├── ngx_event_pipe.h │ ├── ngx_event_posted.c │ ├── ngx_event_posted.h │ ├── ngx_event_timer.c │ ├── ngx_event_timer.h │ ├── ngx_event_udp.c │ ├── ngx_event_udp.h │ └── quic │ │ ├── bpf │ │ ├── bpfgen.sh │ │ ├── makefile │ │ └── ngx_quic_reuseport_helper.c │ │ ├── ngx_event_quic.c │ │ ├── ngx_event_quic.h │ │ ├── ngx_event_quic_ack.c │ │ ├── ngx_event_quic_ack.h │ │ ├── ngx_event_quic_bpf.c │ │ ├── ngx_event_quic_bpf_code.c │ │ ├── ngx_event_quic_connection.h │ │ ├── ngx_event_quic_connid.c │ │ ├── ngx_event_quic_connid.h │ │ ├── ngx_event_quic_frames.c │ │ ├── ngx_event_quic_frames.h │ │ ├── ngx_event_quic_migration.c │ │ ├── ngx_event_quic_migration.h │ │ ├── ngx_event_quic_openssl_compat.c │ │ ├── ngx_event_quic_openssl_compat.h │ │ ├── ngx_event_quic_output.c │ │ ├── ngx_event_quic_output.h │ │ ├── ngx_event_quic_protection.c │ │ ├── ngx_event_quic_protection.h │ │ ├── ngx_event_quic_socket.c │ │ ├── ngx_event_quic_socket.h │ │ ├── ngx_event_quic_ssl.c │ │ ├── ngx_event_quic_ssl.h │ │ ├── ngx_event_quic_streams.c │ │ ├── ngx_event_quic_streams.h │ │ ├── ngx_event_quic_tokens.c │ │ ├── ngx_event_quic_tokens.h │ │ ├── ngx_event_quic_transport.c │ │ ├── ngx_event_quic_transport.h │ │ └── ngx_event_quic_udp.c ├── http │ ├── modules │ │ ├── ngx_http_access_module.c │ │ ├── ngx_http_addition_filter_module.c │ │ ├── ngx_http_auth_basic_module.c │ │ ├── ngx_http_auth_request_module.c │ │ ├── ngx_http_autoindex_module.c │ │ ├── ngx_http_browser_module.c │ │ ├── ngx_http_charset_filter_module.c │ │ ├── ngx_http_chunked_filter_module.c │ │ ├── ngx_http_dav_module.c │ │ ├── ngx_http_degradation_module.c │ │ ├── ngx_http_empty_gif_module.c │ │ ├── ngx_http_fastcgi_module.c │ │ ├── ngx_http_flv_module.c │ │ ├── ngx_http_geo_module.c │ │ ├── ngx_http_geoip_module.c │ │ ├── ngx_http_grpc_module.c │ │ ├── ngx_http_gunzip_filter_module.c │ │ ├── ngx_http_gzip_filter_module.c │ │ ├── ngx_http_gzip_static_module.c │ │ ├── ngx_http_headers_filter_module.c │ │ ├── ngx_http_image_filter_module.c │ │ ├── ngx_http_index_module.c │ │ ├── ngx_http_limit_conn_module.c │ │ ├── ngx_http_limit_req_module.c │ │ ├── ngx_http_log_module.c │ │ ├── ngx_http_map_module.c │ │ ├── ngx_http_memcached_module.c │ │ ├── ngx_http_mirror_module.c │ │ ├── ngx_http_mp4_module.c │ │ ├── ngx_http_not_modified_filter_module.c │ │ ├── ngx_http_proxy_module.c │ │ ├── ngx_http_random_index_module.c │ │ ├── ngx_http_range_filter_module.c │ │ ├── ngx_http_realip_module.c │ │ ├── ngx_http_referer_module.c │ │ ├── ngx_http_rewrite_module.c │ │ ├── ngx_http_scgi_module.c │ │ ├── ngx_http_secure_link_module.c │ │ ├── ngx_http_slice_filter_module.c │ │ ├── ngx_http_split_clients_module.c │ │ ├── ngx_http_ssi_filter_module.c │ │ ├── ngx_http_ssi_filter_module.h │ │ ├── ngx_http_ssl_module.c │ │ ├── ngx_http_ssl_module.h │ │ ├── ngx_http_static_module.c │ │ ├── ngx_http_stub_status_module.c │ │ ├── ngx_http_sub_filter_module.c │ │ ├── ngx_http_try_files_module.c │ │ ├── ngx_http_upstream_hash_module.c │ │ ├── ngx_http_upstream_ip_hash_module.c │ │ ├── ngx_http_upstream_keepalive_module.c │ │ ├── ngx_http_upstream_least_conn_module.c │ │ ├── ngx_http_upstream_random_module.c │ │ ├── ngx_http_upstream_zone_module.c │ │ ├── ngx_http_userid_filter_module.c │ │ ├── ngx_http_uwsgi_module.c │ │ ├── ngx_http_xslt_filter_module.c │ │ └── perl │ │ │ ├── Makefile.PL │ │ │ ├── nginx.pm │ │ │ ├── nginx.xs │ │ │ ├── ngx_http_perl_module.c │ │ │ ├── ngx_http_perl_module.h │ │ │ └── typemap │ ├── ngx_http.c │ ├── ngx_http.h │ ├── ngx_http_cache.h │ ├── ngx_http_config.h │ ├── ngx_http_copy_filter_module.c │ ├── ngx_http_core_module.c │ ├── ngx_http_core_module.h │ ├── ngx_http_file_cache.c │ ├── ngx_http_header_filter_module.c │ ├── ngx_http_huff_decode.c │ ├── ngx_http_huff_encode.c │ ├── ngx_http_parse.c │ ├── ngx_http_postpone_filter_module.c │ ├── ngx_http_request.c │ ├── ngx_http_request.h │ ├── ngx_http_request_body.c │ ├── ngx_http_script.c │ ├── ngx_http_script.h │ ├── ngx_http_special_response.c │ ├── ngx_http_upstream.c │ ├── ngx_http_upstream.h │ ├── ngx_http_upstream_round_robin.c │ ├── ngx_http_upstream_round_robin.h │ ├── ngx_http_variables.c │ ├── ngx_http_variables.h │ ├── ngx_http_write_filter_module.c │ ├── v2 │ │ ├── ngx_http_v2.c │ │ ├── ngx_http_v2.h │ │ ├── ngx_http_v2_encode.c │ │ ├── ngx_http_v2_filter_module.c │ │ ├── ngx_http_v2_module.c │ │ ├── ngx_http_v2_module.h │ │ └── ngx_http_v2_table.c │ └── v3 │ │ ├── ngx_http_v3.c │ │ ├── ngx_http_v3.h │ │ ├── ngx_http_v3_encode.c │ │ ├── ngx_http_v3_encode.h │ │ ├── ngx_http_v3_filter_module.c │ │ ├── ngx_http_v3_module.c │ │ ├── ngx_http_v3_parse.c │ │ ├── ngx_http_v3_parse.h │ │ ├── ngx_http_v3_request.c │ │ ├── ngx_http_v3_table.c │ │ ├── ngx_http_v3_table.h │ │ ├── ngx_http_v3_uni.c │ │ └── ngx_http_v3_uni.h ├── mail │ ├── ngx_mail.c │ ├── ngx_mail.h │ ├── ngx_mail_auth_http_module.c │ ├── ngx_mail_core_module.c │ ├── ngx_mail_handler.c │ ├── ngx_mail_imap_handler.c │ ├── ngx_mail_imap_module.c │ ├── ngx_mail_imap_module.h │ ├── ngx_mail_parse.c │ ├── ngx_mail_pop3_handler.c │ ├── ngx_mail_pop3_module.c │ ├── ngx_mail_pop3_module.h │ ├── ngx_mail_proxy_module.c │ ├── ngx_mail_realip_module.c │ ├── ngx_mail_smtp_handler.c │ ├── ngx_mail_smtp_module.c │ ├── ngx_mail_smtp_module.h │ ├── ngx_mail_ssl_module.c │ └── ngx_mail_ssl_module.h ├── misc │ ├── ngx_cpp_test_module.cpp │ └── ngx_google_perftools_module.c ├── os │ ├── unix │ │ ├── ngx_alloc.c │ │ ├── ngx_alloc.h │ │ ├── ngx_atomic.h │ │ ├── ngx_channel.c │ │ ├── ngx_channel.h │ │ ├── ngx_daemon.c │ │ ├── ngx_darwin.h │ │ ├── ngx_darwin_config.h │ │ ├── ngx_darwin_init.c │ │ ├── ngx_darwin_sendfile_chain.c │ │ ├── ngx_dlopen.c │ │ ├── ngx_dlopen.h │ │ ├── ngx_errno.c │ │ ├── ngx_errno.h │ │ ├── ngx_file_aio_read.c │ │ ├── ngx_files.c │ │ ├── ngx_files.h │ │ ├── ngx_freebsd.h │ │ ├── ngx_freebsd_config.h │ │ ├── ngx_freebsd_init.c │ │ ├── ngx_freebsd_sendfile_chain.c │ │ ├── ngx_gcc_atomic_amd64.h │ │ ├── ngx_gcc_atomic_ppc.h │ │ ├── ngx_gcc_atomic_sparc64.h │ │ ├── ngx_gcc_atomic_x86.h │ │ ├── ngx_linux.h │ │ ├── ngx_linux_aio_read.c │ │ ├── ngx_linux_config.h │ │ ├── ngx_linux_init.c │ │ ├── ngx_linux_sendfile_chain.c │ │ ├── ngx_os.h │ │ ├── ngx_posix_config.h │ │ ├── ngx_posix_init.c │ │ ├── ngx_process.c │ │ ├── ngx_process.h │ │ ├── ngx_process_cycle.c │ │ ├── ngx_process_cycle.h │ │ ├── ngx_readv_chain.c │ │ ├── ngx_recv.c │ │ ├── ngx_send.c │ │ ├── ngx_setaffinity.c │ │ ├── ngx_setaffinity.h │ │ ├── ngx_setproctitle.c │ │ ├── ngx_setproctitle.h │ │ ├── ngx_shmem.c │ │ ├── ngx_shmem.h │ │ ├── ngx_socket.c │ │ ├── ngx_socket.h │ │ ├── ngx_solaris.h │ │ ├── ngx_solaris_config.h │ │ ├── ngx_solaris_init.c │ │ ├── ngx_solaris_sendfilev_chain.c │ │ ├── ngx_sunpro_amd64.il │ │ ├── ngx_sunpro_atomic_sparc64.h │ │ ├── ngx_sunpro_sparc64.il │ │ ├── ngx_sunpro_x86.il │ │ ├── ngx_thread.h │ │ ├── ngx_thread_cond.c │ │ ├── ngx_thread_id.c │ │ ├── ngx_thread_mutex.c │ │ ├── ngx_time.c │ │ ├── ngx_time.h │ │ ├── ngx_udp_recv.c │ │ ├── ngx_udp_send.c │ │ ├── ngx_udp_sendmsg_chain.c │ │ ├── ngx_user.c │ │ ├── ngx_user.h │ │ └── ngx_writev_chain.c │ └── win32 │ │ ├── nginx.ico │ │ ├── nginx.rc │ │ ├── nginx_icon16.xpm │ │ ├── nginx_icon32.xpm │ │ ├── nginx_icon48.xpm │ │ ├── ngx_alloc.c │ │ ├── ngx_alloc.h │ │ ├── ngx_atomic.h │ │ ├── ngx_dlopen.c │ │ ├── ngx_dlopen.h │ │ ├── ngx_errno.c │ │ ├── ngx_errno.h │ │ ├── ngx_event_log.c │ │ ├── ngx_files.c │ │ ├── ngx_files.h │ │ ├── ngx_os.h │ │ ├── ngx_process.c │ │ ├── ngx_process.h │ │ ├── ngx_process_cycle.c │ │ ├── ngx_process_cycle.h │ │ ├── ngx_service.c │ │ ├── ngx_shmem.c │ │ ├── ngx_shmem.h │ │ ├── ngx_socket.c │ │ ├── ngx_socket.h │ │ ├── ngx_stat.c │ │ ├── ngx_thread.c │ │ ├── ngx_thread.h │ │ ├── ngx_time.c │ │ ├── ngx_time.h │ │ ├── ngx_udp_wsarecv.c │ │ ├── ngx_user.c │ │ ├── ngx_user.h │ │ ├── ngx_win32_config.h │ │ ├── ngx_win32_init.c │ │ ├── ngx_wsarecv.c │ │ ├── ngx_wsarecv_chain.c │ │ ├── ngx_wsasend.c │ │ └── ngx_wsasend_chain.c └── stream │ ├── ngx_stream.c │ ├── ngx_stream.h │ ├── ngx_stream_access_module.c │ ├── ngx_stream_core_module.c │ ├── ngx_stream_geo_module.c │ ├── ngx_stream_geoip_module.c │ ├── ngx_stream_handler.c │ ├── ngx_stream_limit_conn_module.c │ ├── ngx_stream_log_module.c │ ├── ngx_stream_map_module.c │ ├── ngx_stream_pass_module.c │ ├── ngx_stream_proxy_module.c │ ├── ngx_stream_realip_module.c │ ├── ngx_stream_return_module.c │ ├── ngx_stream_script.c │ ├── ngx_stream_script.h │ ├── ngx_stream_set_module.c │ ├── ngx_stream_split_clients_module.c │ ├── ngx_stream_ssl_module.c │ ├── ngx_stream_ssl_module.h │ ├── ngx_stream_ssl_preread_module.c │ ├── ngx_stream_upstream.c │ ├── ngx_stream_upstream.h │ ├── ngx_stream_upstream_hash_module.c │ ├── ngx_stream_upstream_least_conn_module.c │ ├── ngx_stream_upstream_random_module.c │ ├── ngx_stream_upstream_round_robin.c │ ├── ngx_stream_upstream_round_robin.h │ ├── ngx_stream_upstream_zone_module.c │ ├── ngx_stream_variables.c │ ├── ngx_stream_variables.h │ └── ngx_stream_write_filter_module.c └── test ├── README.md ├── nginx-test.sh └── nginx-tests ├── LICENSE ├── README ├── access.t ├── access_log.t ├── access_log_variables.t ├── addition.t ├── addition_buffered.t ├── auth_basic.t ├── auth_delay.t ├── auth_request.t ├── auth_request_satisfy.t ├── auth_request_set.t ├── autoindex.t ├── autoindex_format.t ├── autoindex_win32.t ├── binary_upgrade.t ├── body.t ├── body_chunked.t ├── charset.t ├── charset_gzip_static.t ├── config_dump.t ├── dav.t ├── dav_chunked.t ├── dav_utf8.t ├── debug_connection.t ├── debug_connection_syslog.t ├── debug_connection_unix.t ├── empty_gif.t ├── error_log.t ├── fastcgi.t ├── fastcgi_body.t ├── fastcgi_body2.t ├── fastcgi_buffering.t ├── fastcgi_cache.t ├── fastcgi_extra_data.t ├── fastcgi_header_params.t ├── fastcgi_keepalive.t ├── fastcgi_merge_params.t ├── fastcgi_merge_params2.t ├── fastcgi_request_buffering.t ├── fastcgi_request_buffering_chunked.t ├── fastcgi_split.t ├── fastcgi_unix.t ├── fastcgi_variables.t ├── geo.t ├── geo_binary.t ├── geo_ipv6.t ├── geo_unix.t ├── geoip.t ├── grpc.t ├── grpc_next_upstream.t ├── grpc_pass.t ├── grpc_request_buffering.t ├── grpc_ssl.t ├── gunzip.t ├── gunzip_memcached.t ├── gunzip_perl.t ├── gunzip_ssi.t ├── gunzip_static.t ├── gzip.t ├── gzip_flush.t ├── h2.t ├── h2_absolute_redirect.t ├── h2_auth_request.t ├── h2_error_page.t ├── h2_fastcgi_request_buffering.t ├── h2_headers.t ├── h2_http2.t ├── h2_keepalive.t ├── h2_limit_conn.t ├── h2_limit_req.t ├── h2_priority.t ├── h2_proxy_cache.t ├── h2_proxy_max_temp_file_size.t ├── h2_proxy_protocol.t ├── h2_proxy_request_buffering.t ├── h2_proxy_request_buffering_redirect.t ├── h2_proxy_request_buffering_ssl.t ├── h2_proxy_ssl.t ├── h2_request_body.t ├── h2_request_body_extra.t ├── h2_request_body_preread.t ├── h2_server_tokens.t ├── h2_ssl.t ├── h2_ssl_proxy_cache.t ├── h2_ssl_proxy_protocol.t ├── h2_ssl_variables.t ├── h2_ssl_verify_client.t ├── h2_trailers.t ├── h2_variables.t ├── h3_absolute_redirect.t ├── h3_headers.t ├── h3_keepalive.t ├── h3_limit_conn.t ├── h3_limit_req.t ├── h3_proxy.t ├── h3_proxy_max_temp_file_size.t ├── h3_request_body.t ├── h3_request_body_extra.t ├── h3_reusable.t ├── h3_server_name.t ├── h3_server_tokens.t ├── h3_ssl_early_data.t ├── h3_ssl_reject_handshake.t ├── h3_ssl_session_reuse.t ├── h3_trailers.t ├── headers.t ├── http_absolute_redirect.t ├── http_disable_symlinks.t ├── http_error_page.t ├── http_expect_100_continue.t ├── http_header_buffers.t ├── http_headers_multi.t ├── http_host.t ├── http_include.t ├── http_keepalive.t ├── http_keepalive_shutdown.t ├── http_listen.t ├── http_listen_wildcard.t ├── http_location.t ├── http_location_auto.t ├── http_location_win32.t ├── http_method.t ├── http_resolver.t ├── http_resolver_aaaa.t ├── http_resolver_cleanup.t ├── http_resolver_cname.t ├── http_resolver_ipv4.t ├── http_server_name.t ├── http_try_files.t ├── http_uri.t ├── http_variables.t ├── ignore_invalid_headers.t ├── image_filter.t ├── image_filter_finalize.t ├── image_filter_webp.t ├── index.t ├── lib └── Test │ ├── Nginx.pm │ └── Nginx │ ├── HTTP2.pm │ ├── HTTP3.pm │ ├── IMAP.pm │ ├── POP3.pm │ ├── SMTP.pm │ └── Stream.pm ├── limit_conn.t ├── limit_conn_complex.t ├── limit_conn_dry_run.t ├── limit_rate.t ├── limit_req.t ├── limit_req2.t ├── limit_req_delay.t ├── limit_req_dry_run.t ├── mail_capability.t ├── mail_error_log.t ├── mail_imap.t ├── mail_imap_ssl.t ├── mail_max_errors.t ├── mail_pop3.t ├── mail_proxy_protocol.t ├── mail_proxy_smtp_auth.t ├── mail_resolver.t ├── mail_smtp.t ├── mail_smtp_greeting_delay.t ├── mail_smtp_xclient.t ├── mail_ssl.t ├── mail_ssl_conf_command.t ├── mail_ssl_session_reuse.t ├── map.t ├── map_complex.t ├── map_volatile.t ├── memcached.t ├── memcached_fake.t ├── memcached_fake_extra.t ├── memcached_keepalive.t ├── memcached_keepalive_stale.t ├── merge_slashes.t ├── mirror.t ├── mirror_proxy.t ├── mp4.t ├── mp4_ssi.t ├── mp4_start_key_frame.t ├── msie_refresh.t ├── not_modified.t ├── not_modified_finalize.t ├── not_modified_proxy.t ├── perl.t ├── perl_gzip.t ├── perl_sleep.t ├── perl_ssi.t ├── post_action.t ├── proxy.t ├── proxy_available.t ├── proxy_bind.t ├── proxy_bind_transparent.t ├── proxy_bind_transparent_capability.t ├── proxy_cache.t ├── proxy_cache_bypass.t ├── proxy_cache_chunked.t ├── proxy_cache_control.t ├── proxy_cache_convert_head.t ├── proxy_cache_error.t ├── proxy_cache_lock.t ├── proxy_cache_lock_age.t ├── proxy_cache_lock_ssi.t ├── proxy_cache_manager.t ├── proxy_cache_max_range_offset.t ├── proxy_cache_min_free.t ├── proxy_cache_path.t ├── proxy_cache_range.t ├── proxy_cache_revalidate.t ├── proxy_cache_use_stale.t ├── proxy_cache_valid.t ├── proxy_cache_variables.t ├── proxy_cache_vary.t ├── proxy_chunked.t ├── proxy_chunked_extra.t ├── proxy_cookie.t ├── proxy_cookie_flags.t ├── proxy_duplicate_headers.t ├── proxy_extra_data.t ├── proxy_force_ranges.t ├── proxy_if.t ├── proxy_implicit.t ├── proxy_intercept_errors.t ├── proxy_keepalive.t ├── proxy_limit_rate.t ├── proxy_limit_rate2.t ├── proxy_max_temp_file_size.t ├── proxy_merge_headers.t ├── proxy_method.t ├── proxy_next_upstream.t ├── proxy_next_upstream_tries.t ├── proxy_noclose.t ├── proxy_non_idempotent.t ├── proxy_pass_request.t ├── proxy_protocol.t ├── proxy_protocol2.t ├── proxy_protocol2_tlv.t ├── proxy_protocol_ipv6.t ├── proxy_protocol_unix.t ├── proxy_redirect.t ├── proxy_request_buffering.t ├── proxy_request_buffering_chunked.t ├── proxy_request_buffering_keepalive.t ├── proxy_request_buffering_ssl.t ├── proxy_set_body.t ├── proxy_ssi_body.t ├── proxy_ssl.t ├── proxy_ssl_certificate.t ├── proxy_ssl_certificate_empty.t ├── proxy_ssl_certificate_vars.t ├── proxy_ssl_conf_command.t ├── proxy_ssl_keepalive.t ├── proxy_ssl_name.t ├── proxy_ssl_verify.t ├── proxy_store.t ├── proxy_unfinished.t ├── proxy_unix.t ├── proxy_upgrade.t ├── proxy_upstream_cookie.t ├── proxy_variables.t ├── proxy_websocket.t ├── proxy_xar.t ├── quic_ciphers.t ├── quic_key_update.t ├── quic_migration.t ├── quic_retry.t ├── random_index.t ├── range.t ├── range_charset.t ├── range_clearing.t ├── range_flv.t ├── range_if_range.t ├── range_mp4.t ├── realip.t ├── realip_hostname.t ├── realip_remote_addr.t ├── realip_remote_port.t ├── referer.t ├── request_id.t ├── rewrite.t ├── rewrite_if.t ├── rewrite_set.t ├── rewrite_unescape.t ├── scgi.t ├── scgi_body.t ├── scgi_cache.t ├── scgi_extra_data.t ├── scgi_gzip.t ├── scgi_merge_params.t ├── secure_link.t ├── server_tokens.t ├── slice.t ├── split_clients.t ├── ssi.t ├── ssi_delayed.t ├── ssi_if.t ├── ssi_include_big.t ├── ssi_waited.t ├── ssl.t ├── ssl_certificate.t ├── ssl_certificate_chain.t ├── ssl_certificate_perl.t ├── ssl_certificates.t ├── ssl_client_escaped_cert.t ├── ssl_conf_command.t ├── ssl_crl.t ├── ssl_curve.t ├── ssl_engine_keys.t ├── ssl_ocsp.t ├── ssl_password_file.t ├── ssl_proxy_protocol.t ├── ssl_proxy_upgrade.t ├── ssl_reject_handshake.t ├── ssl_session_reuse.t ├── ssl_session_ticket_key.t ├── ssl_sni.t ├── ssl_sni_reneg.t ├── ssl_sni_sessions.t ├── ssl_stapling.t ├── ssl_verify_client.t ├── ssl_verify_depth.t ├── stream_access.t ├── stream_access_log.t ├── stream_access_log_escape.t ├── stream_access_log_none.t ├── stream_error_log.t ├── stream_geo.t ├── stream_geo_binary.t ├── stream_geo_ipv6.t ├── stream_geo_unix.t ├── stream_geoip.t ├── stream_limit_conn.t ├── stream_limit_conn_complex.t ├── stream_limit_conn_dry_run.t ├── stream_limit_rate.t ├── stream_limit_rate2.t ├── stream_map.t ├── stream_pass.t ├── stream_proxy.t ├── stream_proxy_bind.t ├── stream_proxy_complex.t ├── stream_proxy_half_close.t ├── stream_proxy_next_upstream.t ├── stream_proxy_protocol.t ├── stream_proxy_protocol2_tlv.t ├── stream_proxy_protocol_ipv6.t ├── stream_proxy_protocol_ssl.t ├── stream_proxy_ssl.t ├── stream_proxy_ssl_certificate.t ├── stream_proxy_ssl_certificate_vars.t ├── stream_proxy_ssl_conf_command.t ├── stream_proxy_ssl_name.t ├── stream_proxy_ssl_name_complex.t ├── stream_proxy_ssl_verify.t ├── stream_realip.t ├── stream_realip_hostname.t ├── stream_resolver.t ├── stream_server_name.t ├── stream_set.t ├── stream_split_clients.t ├── stream_ssl.t ├── stream_ssl_alpn.t ├── stream_ssl_certificate.t ├── stream_ssl_conf_command.t ├── stream_ssl_preread.t ├── stream_ssl_preread_alpn.t ├── stream_ssl_preread_protocol.t ├── stream_ssl_realip.t ├── stream_ssl_reject_handshake.t ├── stream_ssl_session_reuse.t ├── stream_ssl_variables.t ├── stream_ssl_verify_client.t ├── stream_status_variable.t ├── stream_tcp_nodelay.t ├── stream_udp_limit_conn.t ├── stream_udp_limit_rate.t ├── stream_udp_proxy.t ├── stream_udp_proxy_requests.t ├── stream_udp_stream.t ├── stream_udp_upstream.t ├── stream_udp_upstream_hash.t ├── stream_udp_upstream_least_conn.t ├── stream_udp_wildcard.t ├── stream_unix.t ├── stream_upstream.t ├── stream_upstream_hash.t ├── stream_upstream_least_conn.t ├── stream_upstream_max_conns.t ├── stream_upstream_random.t ├── stream_upstream_zone.t ├── stream_upstream_zone_ssl.t ├── stream_variables.t ├── stub_status.t ├── sub_filter.t ├── sub_filter_buffering.t ├── sub_filter_merge.t ├── sub_filter_multi.t ├── sub_filter_multi2.t ├── sub_filter_perl.t ├── sub_filter_slice.t ├── sub_filter_ssi.t ├── subrequest_output_buffer_size.t ├── syslog.t ├── trailers.t ├── upstream.t ├── upstream_hash.t ├── upstream_hash_memcached.t ├── upstream_ip_hash.t ├── upstream_ip_hash_ipv6.t ├── upstream_keepalive.t ├── upstream_least_conn.t ├── upstream_max_conns.t ├── upstream_random.t ├── upstream_zone.t ├── upstream_zone_ssl.t ├── userid.t ├── userid_flags.t ├── uwsgi.t ├── uwsgi_body.t ├── uwsgi_ssl.t ├── uwsgi_ssl_certificate.t ├── uwsgi_ssl_certificate_vars.t ├── uwsgi_ssl_verify.t ├── worker_shutdown_timeout.t ├── worker_shutdown_timeout_h2.t ├── worker_shutdown_timeout_mail.t ├── worker_shutdown_timeout_proxy_upgrade.t ├── worker_shutdown_timeout_stream.t ├── xslt.t └── xslt_params.t /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * hardik2.patel@intel.com david.qian@intel.com yogaraj.alamenda@intel.com venkatesh.j@intel.com 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD LICENSE 2 | 3 | Copyright (C) 2002-2021 Igor Sysoev 4 | Copyright (C) 2011-2024 Nginx, Inc. 5 | Copyright (C) 2014-2024 Intel Corporation. 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 3. Neither the name of Intel Corporation nor the names of its 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. 3 | 4 | ## Reporting a Vulnerability 5 | Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html). 6 | -------------------------------------------------------------------------------- /auto/cc/acc: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | # aCC: HP ANSI C++ B3910B A.03.55.02 7 | 8 | # C89 mode 9 | 10 | CFLAGS="$CFLAGS -Ae" 11 | CC_TEST_FLAGS="-Ae" 12 | 13 | PCRE_OPT="$PCRE_OPT -Ae" 14 | ZLIB_OPT="$ZLIB_OPT -Ae" 15 | -------------------------------------------------------------------------------- /auto/cc/bcc: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | # Borland C++ 5.5 7 | 8 | # optimizations 9 | 10 | # maximize speed 11 | CFLAGS="$CFLAGS -O2" 12 | 13 | case $CPU in 14 | pentium) 15 | # optimize for Pentium and Athlon 16 | CPU_OPT="-5" 17 | ;; 18 | 19 | pentiumpro) 20 | # optimize for Pentium Pro, Pentium II and Pentium III 21 | CPU_OPT="-6" 22 | ;; 23 | esac 24 | 25 | # __stdcall 26 | #CPU_OPT="$CPU_OPT -ps" 27 | # __fastcall 28 | #CPU_OPT="$CPU_OPT -pr" 29 | 30 | CFLAGS="$CFLAGS $CPU_OPT" 31 | 32 | # multithreaded 33 | CFLAGS="$CFLAGS -tWM" 34 | 35 | # stop on warning 36 | CFLAGS="$CFLAGS -w!" 37 | 38 | # disable logo 39 | CFLAGS="$CFLAGS -q" 40 | 41 | 42 | # precompiled headers 43 | CORE_DEPS="$CORE_DEPS $NGX_OBJS/ngx_config.csm" 44 | NGX_PCH="$NGX_OBJS/ngx_config.csm" 45 | NGX_BUILD_PCH="-H=$NGX_OBJS/ngx_config.csm" 46 | NGX_USE_PCH="-Hu -H=$NGX_OBJS/ngx_config.csm" 47 | 48 | 49 | # Win32 GUI mode application 50 | #LINK="\$(CC) -laa" 51 | 52 | 53 | # the resource file 54 | NGX_RES="$NGX_OBJS/nginx.res" 55 | NGX_RCC="brcc32 -fo$NGX_OBJS/nginx.res \$(CORE_INCS) $NGX_WIN32_RC" 56 | # the pragma allows to link the resource file using bcc32 and 57 | # to avoid the direct ilink32 calling and the c0w32.obj's WinMain/main problem 58 | NGX_PRAGMA="#pragma resource \"$NGX_OBJS/nginx.res\"" 59 | 60 | 61 | ngx_include_opt="-I" 62 | ngx_objout="-o" 63 | ngx_binout="-e" 64 | ngx_objext="obj" 65 | 66 | ngx_long_start='@&&| 67 | ' 68 | ngx_long_end='|' 69 | 70 | ngx_regex_dirsep='\\' 71 | ngx_dirsep="\\" 72 | -------------------------------------------------------------------------------- /auto/cc/ccc: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | # Compaq C V6.5-207 7 | 8 | ngx_include_opt="-I" 9 | 10 | # warnings 11 | 12 | CFLAGS="$CFLAGS -msg_enable level6 -msg_fatal level6" 13 | 14 | CFLAGS="$CFLAGS -msg_disable unknownmacro" 15 | CFLAGS="$CFLAGS -msg_disable unusedincl" 16 | CFLAGS="$CFLAGS -msg_disable unnecincl" 17 | CFLAGS="$CFLAGS -msg_disable nestincl" 18 | CFLAGS="$CFLAGS -msg_disable strctpadding" 19 | CFLAGS="$CFLAGS -msg_disable ansialiascast" 20 | CFLAGS="$CFLAGS -msg_disable inlinestoclsmod" 21 | CFLAGS="$CFLAGS -msg_disable cxxkeyword" 22 | CFLAGS="$CFLAGS -msg_disable longlongsufx" 23 | CFLAGS="$CFLAGS -msg_disable valuepres" 24 | 25 | # STUB 26 | CFLAGS="$CFLAGS -msg_disable truncintcast" 27 | CFLAGS="$CFLAGS -msg_disable trunclongcast" 28 | 29 | CFLAGS="$CFLAGS -msg_disable truncintasn" 30 | CFLAGS="$CFLAGS -msg_disable trunclongint" 31 | CFLAGS="$CFLAGS -msg_disable intconcastsgn" 32 | CFLAGS="$CFLAGS -msg_disable intconstsign" 33 | CFLAGS="$CFLAGS -msg_disable switchlong" 34 | CFLAGS="$CFLAGS -msg_disable subscrbounds2" 35 | 36 | CFLAGS="$CFLAGS -msg_disable hexoctunsign" 37 | 38 | CFLAGS="$CFLAGS -msg_disable ignorecallval" 39 | CFLAGS="$CFLAGS -msg_disable nonstandcast" 40 | CFLAGS="$CFLAGS -msg_disable embedcomment" 41 | CFLAGS="$CFLAGS -msg_disable unreachcode" 42 | CFLAGS="$CFLAGS -msg_disable questcompare2" 43 | CFLAGS="$CFLAGS -msg_disable unusedtop" 44 | CFLAGS="$CFLAGS -msg_disable unrefdecl" 45 | 46 | CFLAGS="$CFLAGS -msg_disable bitnotint" 47 | -------------------------------------------------------------------------------- /auto/cc/name: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | if [ "$NGX_PLATFORM" != win32 ]; then 7 | 8 | ngx_feature="C compiler" 9 | ngx_feature_name= 10 | ngx_feature_run=yes 11 | ngx_feature_incs= 12 | ngx_feature_path= 13 | ngx_feature_libs= 14 | ngx_feature_test= 15 | . auto/feature 16 | 17 | if [ $ngx_found = no ]; then 18 | echo 19 | echo $0: error: C compiler $CC is not found 20 | echo 21 | exit 1 22 | fi 23 | 24 | fi 25 | 26 | 27 | if [ "$CC" = cl ]; then 28 | NGX_CC_NAME=msvc 29 | echo " + using Microsoft Visual C++ compiler" 30 | 31 | elif [ "$CC" = wcl386 ]; then 32 | NGX_CC_NAME=owc 33 | echo " + using Open Watcom C compiler" 34 | 35 | elif [ "$CC" = bcc32 ]; then 36 | NGX_CC_NAME=bcc 37 | echo " + using Borland C++ compiler" 38 | 39 | elif `$CC -V 2>&1 | grep '^Intel(R) C' >/dev/null 2>&1`; then 40 | NGX_CC_NAME=icc 41 | echo " + using Intel C++ compiler" 42 | 43 | elif `$CC -v 2>&1 | grep 'gcc version' >/dev/null 2>&1`; then 44 | NGX_CC_NAME=gcc 45 | echo " + using GNU C compiler" 46 | 47 | elif `$CC -v 2>&1 | grep 'clang version' >/dev/null 2>&1`; then 48 | NGX_CC_NAME=clang 49 | echo " + using Clang C compiler" 50 | 51 | elif `$CC -v 2>&1 | grep 'LLVM version' >/dev/null 2>&1`; then 52 | NGX_CC_NAME=clang 53 | echo " + using Clang C compiler" 54 | 55 | elif `$CC -V 2>&1 | grep 'Sun C' >/dev/null 2>&1`; then 56 | NGX_CC_NAME=sunc 57 | echo " + using Sun C compiler" 58 | 59 | elif `$CC -V 2>&1 | grep '^Compaq C' >/dev/null 2>&1`; then 60 | NGX_CC_NAME=ccc 61 | echo " + using Compaq C compiler" 62 | 63 | elif `$CC -V 2>&1 | grep '^aCC: ' >/dev/null 2>&1`; then 64 | NGX_CC_NAME=acc 65 | echo " + using HP aC++ compiler" 66 | 67 | else 68 | NGX_CC_NAME=unknown 69 | 70 | fi 71 | -------------------------------------------------------------------------------- /auto/define: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | cat << END >> $NGX_AUTO_CONFIG_H 7 | 8 | #ifndef $have 9 | #define $have $value 10 | #endif 11 | 12 | END 13 | -------------------------------------------------------------------------------- /auto/endianness: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | echo $ngx_n "checking for system byte ordering ...$ngx_c" 7 | 8 | cat << END >> $NGX_AUTOCONF_ERR 9 | 10 | ---------------------------------------- 11 | checking for system byte ordering 12 | 13 | END 14 | 15 | 16 | cat << END > $NGX_AUTOTEST.c 17 | 18 | int main(void) { 19 | int i = 0x11223344; 20 | char *p; 21 | 22 | p = (char *) &i; 23 | if (*p == 0x44) return 0; 24 | return 1; 25 | } 26 | 27 | END 28 | 29 | ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \ 30 | -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs" 31 | 32 | eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1" 33 | 34 | if [ -x $NGX_AUTOTEST ]; then 35 | if $NGX_AUTOTEST >/dev/null 2>&1; then 36 | echo " little endian" 37 | have=NGX_HAVE_LITTLE_ENDIAN . auto/have 38 | else 39 | echo " big endian" 40 | fi 41 | 42 | rm -rf $NGX_AUTOTEST* 43 | 44 | else 45 | rm -rf $NGX_AUTOTEST* 46 | 47 | echo 48 | echo "$0: error: cannot detect system byte ordering" 49 | exit 1 50 | fi 51 | -------------------------------------------------------------------------------- /auto/have: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | cat << END >> $NGX_AUTO_CONFIG_H 7 | 8 | #ifndef $have 9 | #define $have 1 10 | #endif 11 | 12 | END 13 | -------------------------------------------------------------------------------- /auto/have_headers: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | cat << END >> $NGX_AUTO_HEADERS_H 7 | 8 | #ifndef $have 9 | #define $have 1 10 | #endif 11 | 12 | END 13 | -------------------------------------------------------------------------------- /auto/headers: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | ngx_include="unistd.h"; . auto/include 7 | ngx_include="inttypes.h"; . auto/include 8 | ngx_include="limits.h"; . auto/include 9 | ngx_include="sys/filio.h"; . auto/include 10 | ngx_include="sys/param.h"; . auto/include 11 | ngx_include="sys/mount.h"; . auto/include 12 | ngx_include="sys/statvfs.h"; . auto/include 13 | ngx_include="crypt.h"; . auto/include 14 | -------------------------------------------------------------------------------- /auto/include: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | echo $ngx_n "checking for $ngx_include ...$ngx_c" 7 | 8 | cat << END >> $NGX_AUTOCONF_ERR 9 | 10 | ---------------------------------------- 11 | checking for $ngx_include 12 | 13 | END 14 | 15 | 16 | ngx_found=no 17 | 18 | cat << END > $NGX_AUTOTEST.c 19 | 20 | $NGX_INCLUDE_SYS_PARAM_H 21 | #include <$ngx_include> 22 | 23 | int main(void) { 24 | return 0; 25 | } 26 | 27 | END 28 | 29 | 30 | ngx_test="$CC -o $NGX_AUTOTEST $NGX_AUTOTEST.c" 31 | 32 | eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1" 33 | 34 | if [ -x $NGX_AUTOTEST ]; then 35 | 36 | ngx_found=yes 37 | 38 | echo " found" 39 | 40 | ngx_name=`echo $ngx_include \ 41 | | tr abcdefghijklmnopqrstuvwxyz/. ABCDEFGHIJKLMNOPQRSTUVWXYZ__` 42 | 43 | 44 | have=NGX_HAVE_$ngx_name . auto/have_headers 45 | 46 | eval "NGX_INCLUDE_$ngx_name='#include <$ngx_include>'" 47 | 48 | else 49 | echo " not found" 50 | 51 | echo "----------" >> $NGX_AUTOCONF_ERR 52 | cat $NGX_AUTOTEST.c >> $NGX_AUTOCONF_ERR 53 | echo "----------" >> $NGX_AUTOCONF_ERR 54 | echo $ngx_test >> $NGX_AUTOCONF_ERR 55 | echo "----------" >> $NGX_AUTOCONF_ERR 56 | fi 57 | 58 | rm -rf $NGX_AUTOTEST* 59 | -------------------------------------------------------------------------------- /auto/init: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | NGX_MAKEFILE=$NGX_OBJS/Makefile 7 | NGX_MODULES_C=$NGX_OBJS/ngx_modules.c 8 | 9 | NGX_AUTO_HEADERS_H=$NGX_OBJS/ngx_auto_headers.h 10 | NGX_AUTO_CONFIG_H=$NGX_OBJS/ngx_auto_config.h 11 | 12 | NGX_AUTOTEST=$NGX_OBJS/autotest 13 | NGX_AUTOCONF_ERR=$NGX_OBJS/autoconf.err 14 | 15 | # STUBs 16 | NGX_ERR=$NGX_OBJS/autoconf.err 17 | MAKEFILE=$NGX_OBJS/Makefile 18 | 19 | 20 | NGX_PCH= 21 | NGX_USE_PCH= 22 | 23 | 24 | # check the echo's "-n" option and "\c" capability 25 | 26 | if echo "test\c" | grep c >/dev/null; then 27 | 28 | if echo -n test | grep n >/dev/null; then 29 | ngx_n= 30 | ngx_c= 31 | 32 | else 33 | ngx_n=-n 34 | ngx_c= 35 | fi 36 | 37 | else 38 | ngx_n= 39 | ngx_c='\c' 40 | fi 41 | 42 | 43 | # create Makefile 44 | 45 | cat << END > Makefile 46 | 47 | default: build 48 | 49 | clean: 50 | rm -rf Makefile $NGX_OBJS 51 | 52 | .PHONY: default clean 53 | END 54 | -------------------------------------------------------------------------------- /auto/lib/conf: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | if [ $USE_PCRE = YES -o $PCRE != NONE ]; then 7 | . auto/lib/pcre/conf 8 | 9 | else 10 | if [ $USE_PCRE = DISABLED -a $HTTP = YES -a $HTTP_REWRITE = YES ]; then 11 | 12 | cat << END 13 | 14 | $0: error: the HTTP rewrite module requires the PCRE library. 15 | You can either disable the module by using --without-http_rewrite_module 16 | option or you have to enable the PCRE support. 17 | 18 | END 19 | exit 1 20 | fi 21 | fi 22 | 23 | 24 | if [ $USE_OPENSSL = YES ]; then 25 | . auto/lib/openssl/conf 26 | fi 27 | 28 | if [ $USE_ZLIB = YES ]; then 29 | . auto/lib/zlib/conf 30 | fi 31 | 32 | if [ $USE_LIBXSLT != NO ]; then 33 | . auto/lib/libxslt/conf 34 | fi 35 | 36 | if [ $USE_LIBGD != NO ]; then 37 | . auto/lib/libgd/conf 38 | fi 39 | 40 | if [ $USE_PERL != NO ]; then 41 | . auto/lib/perl/conf 42 | fi 43 | 44 | if [ $USE_GEOIP != NO ]; then 45 | . auto/lib/geoip/conf 46 | fi 47 | 48 | if [ $NGX_GOOGLE_PERFTOOLS = YES ]; then 49 | . auto/lib/google-perftools/conf 50 | fi 51 | 52 | if [ $NGX_LIBATOMIC != NO ]; then 53 | . auto/lib/libatomic/conf 54 | fi 55 | -------------------------------------------------------------------------------- /auto/lib/google-perftools/conf: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | ngx_feature="Google perftools" 7 | ngx_feature_name= 8 | ngx_feature_run=no 9 | ngx_feature_incs= 10 | ngx_feature_path= 11 | ngx_feature_libs="-lprofiler" 12 | ngx_feature_test="void ProfilerStop(void); 13 | ProfilerStop()" 14 | . auto/feature 15 | 16 | 17 | if [ $ngx_found = no ]; then 18 | 19 | # FreeBSD port 20 | 21 | ngx_feature="Google perftools in /usr/local/" 22 | 23 | if [ $NGX_RPATH = YES ]; then 24 | ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -lprofiler" 25 | else 26 | ngx_feature_libs="-L/usr/local/lib -lprofiler" 27 | fi 28 | 29 | . auto/feature 30 | fi 31 | 32 | 33 | if [ $ngx_found = no ]; then 34 | 35 | # MacPorts 36 | 37 | ngx_feature="Google perftools in /opt/local/" 38 | 39 | if [ $NGX_RPATH = YES ]; then 40 | ngx_feature_libs="-R/opt/local/lib -L/opt/local/lib -lprofiler" 41 | else 42 | ngx_feature_libs="-L/opt/local/lib -lprofiler" 43 | fi 44 | 45 | . auto/feature 46 | fi 47 | 48 | 49 | if [ $ngx_found = no ]; then 50 | 51 | # Homebrew on Apple Silicon 52 | 53 | ngx_feature="Google perftools in /opt/homebrew/" 54 | 55 | if [ $NGX_RPATH = YES ]; then 56 | ngx_feature_libs="-R/opt/homebrew/lib -L/opt/homebrew/lib -lprofiler" 57 | else 58 | ngx_feature_libs="-L/opt/homebrew/lib -lprofiler" 59 | fi 60 | 61 | . auto/feature 62 | fi 63 | 64 | 65 | if [ $ngx_found = yes ]; then 66 | CORE_LIBS="$CORE_LIBS $ngx_feature_libs" 67 | 68 | else 69 | 70 | cat << END 71 | 72 | $0: error: the Google perftools module requires the Google perftools 73 | library. You can either do not enable the module or install the library. 74 | 75 | END 76 | 77 | exit 1 78 | fi 79 | -------------------------------------------------------------------------------- /auto/lib/libatomic/conf: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | if [ $NGX_LIBATOMIC != YES ]; then 7 | 8 | have=NGX_HAVE_LIBATOMIC . auto/have 9 | CORE_INCS="$CORE_INCS $NGX_LIBATOMIC/src" 10 | LINK_DEPS="$LINK_DEPS $NGX_LIBATOMIC/src/libatomic_ops.a" 11 | CORE_LIBS="$CORE_LIBS $NGX_LIBATOMIC/src/libatomic_ops.a" 12 | 13 | else 14 | 15 | ngx_feature="atomic_ops library" 16 | ngx_feature_name=NGX_HAVE_LIBATOMIC 17 | ngx_feature_run=yes 18 | ngx_feature_incs="#define AO_REQUIRE_CAS 19 | #include " 20 | ngx_feature_path= 21 | ngx_feature_libs="-latomic_ops" 22 | ngx_feature_test="AO_t n = 0; 23 | if (!AO_compare_and_swap(&n, 0, 1)) 24 | return 1; 25 | if (AO_fetch_and_add(&n, 1) != 1) 26 | return 1; 27 | if (n != 2) 28 | return 1; 29 | AO_nop();" 30 | . auto/feature 31 | 32 | if [ $ngx_found = yes ]; then 33 | CORE_LIBS="$CORE_LIBS $ngx_feature_libs" 34 | else 35 | 36 | cat << END 37 | 38 | $0: error: libatomic_ops library was not found. 39 | 40 | END 41 | exit 1 42 | fi 43 | fi 44 | -------------------------------------------------------------------------------- /auto/lib/libatomic/make: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | cat << END >> $NGX_MAKEFILE 7 | 8 | $NGX_LIBATOMIC/src/libatomic_ops.a: $NGX_LIBATOMIC/Makefile 9 | cd $NGX_LIBATOMIC && \$(MAKE) 10 | 11 | $NGX_LIBATOMIC/Makefile: $NGX_MAKEFILE 12 | cd $NGX_LIBATOMIC \\ 13 | && if [ -f Makefile ]; then \$(MAKE) distclean; fi \\ 14 | && ./configure 15 | 16 | END 17 | -------------------------------------------------------------------------------- /auto/lib/make: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | if [ $PCRE != NONE -a $PCRE != NO -a $PCRE != YES ]; then 7 | . auto/lib/pcre/make 8 | fi 9 | 10 | if [ $OPENSSL != NONE -a $OPENSSL != NO -a $OPENSSL != YES ]; then 11 | . auto/lib/openssl/make 12 | fi 13 | 14 | if [ $ZLIB != NONE -a $ZLIB != NO -a $ZLIB != YES ]; then 15 | . auto/lib/zlib/make 16 | fi 17 | 18 | if [ $NGX_LIBATOMIC != NO -a $NGX_LIBATOMIC != YES ]; then 19 | . auto/lib/libatomic/make 20 | fi 21 | 22 | if [ $USE_PERL != NO ]; then 23 | . auto/lib/perl/make 24 | fi 25 | -------------------------------------------------------------------------------- /auto/lib/openssl/makefile.bcc: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | all: 7 | cd $(OPENSSL) 8 | 9 | perl Configure BC-32 no-shared --prefix=openssl $(OPENSSL_OPT) 10 | 11 | ms\do_nasm 12 | 13 | $(MAKE) -f ms\bcb.mak 14 | $(MAKE) -f ms\bcb.mak install 15 | 16 | # Borland's make does not expand "[ch]" in 17 | # copy "inc32\openssl\*.[ch]" "openssl\include\openssl" 18 | copy inc32\openssl\*.h openssl\include\openssl 19 | -------------------------------------------------------------------------------- /auto/lib/openssl/makefile.msvc: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | all: 7 | cd $(OPENSSL) 8 | 9 | perl Configure $(OPENSSL_TARGET) no-shared no-threads \ 10 | --prefix="%cd%/openssl" \ 11 | --openssldir="%cd%/openssl/ssl" \ 12 | $(OPENSSL_OPT) 13 | 14 | if exist ms\do_ms.bat ( \ 15 | ms\do_ms \ 16 | && $(MAKE) -f ms\nt.mak \ 17 | && $(MAKE) -f ms\nt.mak install \ 18 | ) else ( \ 19 | $(MAKE) \ 20 | && $(MAKE) install_sw \ 21 | ) 22 | -------------------------------------------------------------------------------- /auto/lib/pcre/makefile.bcc: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | CFLAGS = -q -O2 -tWM -w-8004 $(CPU_OPT) 7 | PCREFLAGS = -DHAVE_CONFIG_H -DPCRE_STATIC -DPOSIX_MALLOC_THRESHOLD=10 \ 8 | -DSUPPORT_PCRE8 -DHAVE_MEMMOVE 9 | 10 | 11 | pcre.lib: 12 | cd $(PCRE) 13 | 14 | bcc32 -c $(CFLAGS) -I. $(PCREFLAGS) pcre_*.c 15 | 16 | copy /y nul pcre.lst 17 | for %n in (*.obj) do @echo +%n ^^& >> pcre.lst 18 | echo + >> pcre.lst 19 | 20 | tlib pcre.lib @pcre.lst 21 | 22 | pcre.h: 23 | cd $(PCRE) 24 | 25 | copy /y pcre.h.generic pcre.h 26 | copy /y config.h.generic config.h 27 | copy /y pcre_chartables.c.dist pcre_chartables.c 28 | -------------------------------------------------------------------------------- /auto/lib/pcre/makefile.msvc: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | CFLAGS = -O2 -Ob1 -Oi -Gs $(LIBC) $(CPU_OPT) 7 | PCREFLAGS = -DHAVE_CONFIG_H -DPCRE_STATIC -DPOSIX_MALLOC_THRESHOLD=10 \ 8 | -DSUPPORT_PCRE8 -DHAVE_MEMMOVE 9 | 10 | 11 | pcre.lib: 12 | cd $(PCRE) 13 | 14 | cl -nologo -c $(CFLAGS) -I . $(PCREFLAGS) pcre_*.c 15 | 16 | link -lib -out:pcre.lib -verbose:lib pcre_*.obj 17 | 18 | pcre.h: 19 | cd $(PCRE) 20 | 21 | copy /y pcre.h.generic pcre.h 22 | copy /y config.h.generic config.h 23 | copy /y pcre_chartables.c.dist pcre_chartables.c 24 | -------------------------------------------------------------------------------- /auto/lib/pcre/makefile.owc: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | CFLAGS = -c -zq -bt=nt -ot -op -oi -oe -s -bm $(CPU_OPT) 7 | PCREFLAGS = -DHAVE_CONFIG_H -DPCRE_STATIC -DPOSIX_MALLOC_THRESHOLD=10 & 8 | -DSUPPORT_PCRE8 -DHAVE_MEMMOVE 9 | 10 | 11 | pcre.lib: 12 | cd $(PCRE) 13 | 14 | wcl386 $(CFLAGS) -i=. $(PCREFLAGS) pcre_*.c 15 | 16 | dir /b *.obj > pcre.lst 17 | 18 | wlib -n pcre.lib @pcre.lst 19 | 20 | pcre.h: 21 | cd $(PCRE) 22 | 23 | copy /y pcre.h.generic pcre.h 24 | copy /y config.h.generic config.h 25 | copy /y pcre_chartables.c.dist pcre_chartables.c 26 | -------------------------------------------------------------------------------- /auto/lib/perl/make: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | cat << END >> $NGX_MAKEFILE 7 | 8 | $NGX_OBJS/src/http/modules/perl/ngx_http_perl_module.o: \\ 9 | $NGX_OBJS/$ngx_perl_module 10 | 11 | $NGX_OBJS/$ngx_perl_module: \\ 12 | \$(CORE_DEPS) \$(HTTP_DEPS) \\ 13 | src/http/modules/perl/ngx_http_perl_module.h \\ 14 | $NGX_OBJS/src/http/modules/perl/Makefile 15 | cd $NGX_OBJS/src/http/modules/perl && \$(MAKE) 16 | 17 | rm -rf $NGX_OBJS/install_perl 18 | 19 | 20 | $NGX_OBJS/src/http/modules/perl/Makefile: \\ 21 | $NGX_AUTO_CONFIG_H \\ 22 | src/core/nginx.h \\ 23 | src/http/modules/perl/Makefile.PL \\ 24 | src/http/modules/perl/nginx.pm \\ 25 | src/http/modules/perl/nginx.xs \\ 26 | src/http/modules/perl/typemap 27 | grep 'define NGINX_VERSION' src/core/nginx.h \\ 28 | | sed -e 's/^.*"\(.*\)".*/\1/' > \\ 29 | $NGX_OBJS/src/http/modules/perl/version 30 | sed "s/%%VERSION%%/\`cat $NGX_OBJS/src/http/modules/perl/version\`/" \\ 31 | src/http/modules/perl/nginx.pm > \\ 32 | $NGX_OBJS/src/http/modules/perl/nginx.pm 33 | cp -p src/http/modules/perl/nginx.xs $NGX_OBJS/src/http/modules/perl/ 34 | cp -p src/http/modules/perl/typemap $NGX_OBJS/src/http/modules/perl/ 35 | cp -p src/http/modules/perl/Makefile.PL $NGX_OBJS/src/http/modules/perl/ 36 | 37 | cd $NGX_OBJS/src/http/modules/perl \\ 38 | && NGX_PM_CFLAGS="\$(NGX_PM_CFLAGS) -g $NGX_CC_OPT" \\ 39 | NGX_PM_LDFLAGS="$NGX_LD_OPT \$(NGX_PM_LDFLAGS)" \\ 40 | NGX_INCS="$CORE_INCS $NGX_OBJS $HTTP_INCS" \\ 41 | NGX_DEPS="\$(CORE_DEPS) \$(HTTP_DEPS)" \\ 42 | $NGX_PERL Makefile.PL \\ 43 | LIB=$NGX_PERL_MODULES \\ 44 | INSTALLSITEMAN3DIR=$NGX_PERL_MODULES_MAN 45 | 46 | END 47 | -------------------------------------------------------------------------------- /auto/lib/zlib/makefile.bcc: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | CFLAGS = -q -O2 -tWM -w-8004 -w-8012 $(CPU_OPT) 7 | 8 | zlib.lib: 9 | cd $(ZLIB) 10 | 11 | bcc32 -c $(CFLAGS) adler32.c crc32.c deflate.c \ 12 | trees.c zutil.c compress.c \ 13 | inflate.c inffast.c inftrees.c 14 | 15 | tlib zlib.lib +adler32.obj +crc32.obj +deflate.obj \ 16 | +trees.obj +zutil.obj +compress.obj \ 17 | +inflate.obj +inffast.obj +inftrees.obj 18 | -------------------------------------------------------------------------------- /auto/lib/zlib/makefile.msvc: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | CFLAGS = -nologo -O2 -Ob1 -Oi -Gs $(LIBC) $(CPU_OPT) 7 | 8 | zlib.lib: 9 | cd $(ZLIB) 10 | 11 | cl -c $(CFLAGS) adler32.c crc32.c deflate.c \ 12 | trees.c zutil.c compress.c \ 13 | inflate.c inffast.c inftrees.c 14 | 15 | link -lib -out:zlib.lib adler32.obj crc32.obj deflate.obj \ 16 | trees.obj zutil.obj compress.obj \ 17 | inflate.obj inffast.obj inftrees.obj 18 | -------------------------------------------------------------------------------- /auto/lib/zlib/makefile.owc: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | CFLAGS = -zq -bt=nt -ot -op -oi -oe -s -bm $(CPU_OPT) 7 | 8 | zlib.lib: 9 | cd $(ZLIB) 10 | 11 | wcl386 -c $(CFLAGS) adler32.c crc32.c deflate.c trees.c zutil.c & 12 | compress.c inflate.c inffast.c inftrees.c 13 | wlib -n zlib.lib adler32.obj crc32.obj deflate.obj trees.obj & 14 | zutil.obj compress.obj inflate.obj inffast.obj inftrees.obj 15 | -------------------------------------------------------------------------------- /auto/nohave: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | cat << END >> $NGX_AUTO_CONFIG_H 7 | 8 | #ifndef $have 9 | #define $have 0 10 | #endif 11 | 12 | END 13 | -------------------------------------------------------------------------------- /auto/os/solaris: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | have=NGX_SOLARIS . auto/have_headers 7 | 8 | CORE_INCS="$UNIX_INCS" 9 | CORE_DEPS="$UNIX_DEPS $SOLARIS_DEPS" 10 | CORE_SRCS="$UNIX_SRCS $SOLARIS_SRCS " 11 | CORE_LIBS="$CORE_LIBS -lsocket -lnsl" 12 | 13 | NGX_RPATH=YES 14 | 15 | # Solaris's make does not support a blank line between target and rules 16 | ngx_spacer= 17 | 18 | CC_AUX_FLAGS="$CC_AUX_FLAGS -D_FILE_OFFSET_BITS=64 -lsocket -lnsl" 19 | 20 | 21 | if [ $ZLIB_ASM != NO ]; then 22 | echo "$0: error: the --with-zlib-asm=CPU option is not supported" 23 | echo "on that platform" 24 | echo 25 | 26 | exit 1 27 | fi 28 | 29 | 30 | ngx_feature="sendfilev()" 31 | ngx_feature_name="NGX_HAVE_SENDFILE" 32 | ngx_feature_run=no 33 | ngx_feature_incs="#include " 34 | ngx_feature_path= 35 | ngx_feature_libs="-lsendfile" 36 | ngx_feature_test="int fd = 1; sendfilevec_t vec[1]; 37 | size_t sent; ssize_t n; 38 | n = sendfilev(fd, vec, 1, &sent); 39 | if (n == -1) return 1" 40 | . auto/feature 41 | 42 | 43 | if [ $ngx_found = yes ]; then 44 | CORE_SRCS="$CORE_SRCS $SOLARIS_SENDFILEV_SRCS" 45 | CORE_LIBS="$CORE_LIBS -lsendfile" 46 | fi 47 | 48 | 49 | ngx_feature="event ports" 50 | ngx_feature_name="NGX_HAVE_EVENTPORT" 51 | ngx_feature_run=no 52 | ngx_feature_incs="#include " 53 | ngx_feature_path= 54 | ngx_feature_libs= 55 | ngx_feature_test="(void) port_create()" 56 | . auto/feature 57 | 58 | if [ $ngx_found = yes ]; then 59 | CORE_SRCS="$CORE_SRCS $EVENTPORT_SRCS" 60 | EVENT_MODULES="$EVENT_MODULES $EVENTPORT_MODULE" 61 | fi 62 | -------------------------------------------------------------------------------- /auto/os/win32: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | have=NGX_WIN32 . auto/have_headers 7 | 8 | CORE_INCS="$WIN32_INCS" 9 | CORE_DEPS="$WIN32_DEPS" 10 | CORE_SRCS="$WIN32_SRCS $IOCP_SRCS" 11 | OS_CONFIG="$WIN32_CONFIG" 12 | NGX_ICONS="$NGX_WIN32_ICONS" 13 | SELECT_SRCS=$WIN32_SELECT_SRCS 14 | POLL_SRCS=$WIN32_POLL_SRCS 15 | 16 | ngx_pic_opt= 17 | ngx_binext=".exe" 18 | 19 | case "$NGX_CC_NAME" in 20 | 21 | clang | gcc) 22 | CORE_LIBS="$CORE_LIBS -ladvapi32 -lws2_32" 23 | MAIN_LINK="$MAIN_LINK -Wl,--export-all-symbols" 24 | MAIN_LINK="$MAIN_LINK -Wl,--out-implib=$NGX_OBJS/libnginx.a" 25 | MODULE_LINK="-shared -L $NGX_OBJS -lnginx" 26 | ;; 27 | 28 | *) 29 | CORE_LIBS="$CORE_LIBS advapi32.lib ws2_32.lib" 30 | ;; 31 | 32 | esac 33 | 34 | EVENT_MODULES="$EVENT_MODULES $IOCP_MODULE" 35 | #EVENT_FOUND=YES 36 | 37 | have=NGX_HAVE_INET6 . auto/have 38 | 39 | have=NGX_HAVE_IOCP . auto/have 40 | -------------------------------------------------------------------------------- /auto/stubs: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | have=NGX_SUPPRESS_WARN . auto/have 7 | 8 | have=NGX_SMP . auto/have 9 | -------------------------------------------------------------------------------- /auto/threads: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Nginx, Inc. 3 | 4 | 5 | if [ $USE_THREADS = YES ]; then 6 | 7 | if [ "$NGX_PLATFORM" = win32 ]; then 8 | cat << END 9 | 10 | $0: --with-threads is not supported on Windows 11 | 12 | END 13 | exit 1 14 | fi 15 | 16 | have=NGX_THREADS . auto/have 17 | CORE_DEPS="$CORE_DEPS $THREAD_POOL_DEPS" 18 | CORE_SRCS="$CORE_SRCS $THREAD_POOL_SRCS" 19 | CORE_LIBS="$CORE_LIBS -lpthread" 20 | NGX_LIBPTHREAD="-lpthread" 21 | fi 22 | -------------------------------------------------------------------------------- /auto/types/sizeof: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | echo $ngx_n "checking for $ngx_type size ...$ngx_c" 7 | 8 | cat << END >> $NGX_AUTOCONF_ERR 9 | 10 | ---------------------------------------- 11 | checking for $ngx_type size 12 | 13 | END 14 | 15 | ngx_size= 16 | 17 | cat << END > $NGX_AUTOTEST.c 18 | 19 | #include 20 | #include 21 | $NGX_INCLUDE_UNISTD_H 22 | #include 23 | #include 24 | #include 25 | $NGX_INCLUDE_INTTYPES_H 26 | $NGX_INCLUDE_AUTO_CONFIG_H 27 | 28 | int main(void) { 29 | printf("%d", (int) sizeof($ngx_type)); 30 | return 0; 31 | } 32 | 33 | END 34 | 35 | 36 | ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \ 37 | -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs" 38 | 39 | eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1" 40 | 41 | 42 | if [ -x $NGX_AUTOTEST ]; then 43 | ngx_size=`$NGX_AUTOTEST` 44 | echo " $ngx_size bytes" 45 | fi 46 | 47 | 48 | case $ngx_size in 49 | 4) 50 | ngx_max_value=2147483647 51 | ngx_max_len='(sizeof("-2147483648") - 1)' 52 | ;; 53 | 54 | 8) 55 | ngx_max_value=9223372036854775807LL 56 | ngx_max_len='(sizeof("-9223372036854775808") - 1)' 57 | ;; 58 | 59 | *) 60 | echo 61 | echo "$0: error: can not detect $ngx_type size" 62 | 63 | echo "----------" >> $NGX_AUTOCONF_ERR 64 | cat $NGX_AUTOTEST.c >> $NGX_AUTOCONF_ERR 65 | echo "----------" >> $NGX_AUTOCONF_ERR 66 | echo $ngx_test >> $NGX_AUTOCONF_ERR 67 | echo "----------" >> $NGX_AUTOCONF_ERR 68 | 69 | rm -rf $NGX_AUTOTEST* 70 | 71 | exit 1 72 | esac 73 | 74 | 75 | rm -rf $NGX_AUTOTEST* 76 | 77 | -------------------------------------------------------------------------------- /auto/types/uintptr_t: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | echo $ngx_n "checking for uintptr_t ...$ngx_c" 7 | 8 | cat << END >> $NGX_AUTOCONF_ERR 9 | 10 | ---------------------------------------- 11 | checking for uintptr_t 12 | 13 | END 14 | 15 | found=no 16 | 17 | cat << END > $NGX_AUTOTEST.c 18 | 19 | #include 20 | $NGX_INCLUDE_INTTYPES_H 21 | 22 | int main(void) { 23 | uintptr_t i = 0; 24 | return (int) i; 25 | } 26 | 27 | END 28 | 29 | ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \ 30 | -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT" 31 | 32 | eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1" 33 | 34 | if [ -x $NGX_AUTOTEST ]; then 35 | echo " uintptr_t found" 36 | found=yes 37 | else 38 | echo $ngx_n " uintptr_t not found" $ngx_c 39 | fi 40 | 41 | rm -rf $NGX_AUTOTEST* 42 | 43 | 44 | if [ $found = no ]; then 45 | found="uint`expr 8 \* $ngx_ptr_size`_t" 46 | echo ", $found used" 47 | 48 | echo "typedef $found uintptr_t;" >> $NGX_AUTO_CONFIG_H 49 | echo "typedef $found intptr_t;" | sed -e 's/u//g' >> $NGX_AUTO_CONFIG_H 50 | fi 51 | -------------------------------------------------------------------------------- /auto/types/value: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | 6 | cat << END >> $NGX_AUTO_CONFIG_H 7 | 8 | #ifndef $ngx_param 9 | #define $ngx_param $ngx_value 10 | #endif 11 | 12 | END 13 | -------------------------------------------------------------------------------- /conf/fastcgi.conf: -------------------------------------------------------------------------------- 1 | 2 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 3 | fastcgi_param QUERY_STRING $query_string; 4 | fastcgi_param REQUEST_METHOD $request_method; 5 | fastcgi_param CONTENT_TYPE $content_type; 6 | fastcgi_param CONTENT_LENGTH $content_length; 7 | 8 | fastcgi_param SCRIPT_NAME $fastcgi_script_name; 9 | fastcgi_param REQUEST_URI $request_uri; 10 | fastcgi_param DOCUMENT_URI $document_uri; 11 | fastcgi_param DOCUMENT_ROOT $document_root; 12 | fastcgi_param SERVER_PROTOCOL $server_protocol; 13 | fastcgi_param REQUEST_SCHEME $scheme; 14 | fastcgi_param HTTPS $https if_not_empty; 15 | 16 | fastcgi_param GATEWAY_INTERFACE CGI/1.1; 17 | fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; 18 | 19 | fastcgi_param REMOTE_ADDR $remote_addr; 20 | fastcgi_param REMOTE_PORT $remote_port; 21 | fastcgi_param SERVER_ADDR $server_addr; 22 | fastcgi_param SERVER_PORT $server_port; 23 | fastcgi_param SERVER_NAME $server_name; 24 | 25 | # PHP only, required if PHP was built with --enable-force-cgi-redirect 26 | fastcgi_param REDIRECT_STATUS 200; 27 | -------------------------------------------------------------------------------- /conf/fastcgi_params: -------------------------------------------------------------------------------- 1 | 2 | fastcgi_param QUERY_STRING $query_string; 3 | fastcgi_param REQUEST_METHOD $request_method; 4 | fastcgi_param CONTENT_TYPE $content_type; 5 | fastcgi_param CONTENT_LENGTH $content_length; 6 | 7 | fastcgi_param SCRIPT_NAME $fastcgi_script_name; 8 | fastcgi_param REQUEST_URI $request_uri; 9 | fastcgi_param DOCUMENT_URI $document_uri; 10 | fastcgi_param DOCUMENT_ROOT $document_root; 11 | fastcgi_param SERVER_PROTOCOL $server_protocol; 12 | fastcgi_param REQUEST_SCHEME $scheme; 13 | fastcgi_param HTTPS $https if_not_empty; 14 | 15 | fastcgi_param GATEWAY_INTERFACE CGI/1.1; 16 | fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; 17 | 18 | fastcgi_param REMOTE_ADDR $remote_addr; 19 | fastcgi_param REMOTE_PORT $remote_port; 20 | fastcgi_param SERVER_ADDR $server_addr; 21 | fastcgi_param SERVER_PORT $server_port; 22 | fastcgi_param SERVER_NAME $server_name; 23 | 24 | # PHP only, required if PHP was built with --enable-force-cgi-redirect 25 | fastcgi_param REDIRECT_STATUS 200; 26 | -------------------------------------------------------------------------------- /conf/scgi_params: -------------------------------------------------------------------------------- 1 | 2 | scgi_param REQUEST_METHOD $request_method; 3 | scgi_param REQUEST_URI $request_uri; 4 | scgi_param QUERY_STRING $query_string; 5 | scgi_param CONTENT_TYPE $content_type; 6 | 7 | scgi_param DOCUMENT_URI $document_uri; 8 | scgi_param DOCUMENT_ROOT $document_root; 9 | scgi_param SCGI 1; 10 | scgi_param SERVER_PROTOCOL $server_protocol; 11 | scgi_param REQUEST_SCHEME $scheme; 12 | scgi_param HTTPS $https if_not_empty; 13 | 14 | scgi_param REMOTE_ADDR $remote_addr; 15 | scgi_param REMOTE_PORT $remote_port; 16 | scgi_param SERVER_PORT $server_port; 17 | scgi_param SERVER_NAME $server_name; 18 | -------------------------------------------------------------------------------- /conf/uwsgi_params: -------------------------------------------------------------------------------- 1 | 2 | uwsgi_param QUERY_STRING $query_string; 3 | uwsgi_param REQUEST_METHOD $request_method; 4 | uwsgi_param CONTENT_TYPE $content_type; 5 | uwsgi_param CONTENT_LENGTH $content_length; 6 | 7 | uwsgi_param REQUEST_URI $request_uri; 8 | uwsgi_param PATH_INFO $document_uri; 9 | uwsgi_param DOCUMENT_ROOT $document_root; 10 | uwsgi_param SERVER_PROTOCOL $server_protocol; 11 | uwsgi_param REQUEST_SCHEME $scheme; 12 | uwsgi_param HTTPS $https if_not_empty; 13 | 14 | uwsgi_param REMOTE_ADDR $remote_addr; 15 | uwsgi_param REMOTE_PORT $remote_port; 16 | uwsgi_param SERVER_PORT $server_port; 17 | uwsgi_param SERVER_NAME $server_name; 18 | -------------------------------------------------------------------------------- /contrib/README: -------------------------------------------------------------------------------- 1 | 2 | geo2nginx.pl by Andrei Nigmatulin 3 | 4 | The perl script to convert CSV geoip database ( free download 5 | at http://www.maxmind.com/app/geoip_country ) to format, suitable 6 | for use by the ngx_http_geo_module. 7 | 8 | 9 | unicode2nginx by Maxim Dounin 10 | 11 | The perl script to convert unicode mappings ( available 12 | at http://www.unicode.org/Public/MAPPINGS/ ) to the nginx 13 | configuration file format. 14 | Two generated full maps for windows-1251 and koi8-r. 15 | 16 | 17 | vim by Evan Miller 18 | 19 | Syntax highlighting of nginx configuration for vim, to be 20 | placed into ~/.vim/. 21 | 22 | -------------------------------------------------------------------------------- /contrib/geo2nginx.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # (c) Andrei Nigmatulin, 2005 4 | # 5 | # this script provided "as is", without any warranties. use it at your own risk. 6 | # 7 | # special thanx to Andrew Sitnikov for perl port 8 | # 9 | # this script converts CSV geoip database (free download at http://www.maxmind.com/app/geoip_country) 10 | # to format, suitable for use with nginx_http_geo module (http://sysoev.ru/nginx) 11 | # 12 | # for example, line with ip range 13 | # 14 | # "62.16.68.0","62.16.127.255","1041253376","1041268735","RU","Russian Federation" 15 | # 16 | # will be converted to four subnetworks: 17 | # 18 | # 62.16.68.0/22 RU; 19 | # 62.16.72.0/21 RU; 20 | # 62.16.80.0/20 RU; 21 | # 62.16.96.0/19 RU; 22 | 23 | 24 | use warnings; 25 | use strict; 26 | 27 | while( ){ 28 | if (/"[^"]+","[^"]+","([^"]+)","([^"]+)","([^"]+)"/){ 29 | print_subnets($1, $2, $3); 30 | } 31 | } 32 | 33 | sub print_subnets { 34 | my ($a1, $a2, $c) = @_; 35 | my $l; 36 | while ($a1 <= $a2) { 37 | for ($l = 0; ($a1 & (1 << $l)) == 0 && ($a1 + ((1 << ($l + 1)) - 1)) <= $a2; $l++){}; 38 | print long2ip($a1) . "/" . (32 - $l) . " " . $c . ";\n"; 39 | $a1 += (1 << $l); 40 | } 41 | } 42 | 43 | sub long2ip { 44 | my $ip = shift; 45 | 46 | my $str = 0; 47 | 48 | $str = ($ip & 255); 49 | 50 | $ip >>= 8; 51 | $str = ($ip & 255).".$str"; 52 | 53 | $ip >>= 8; 54 | $str = ($ip & 255).".$str"; 55 | 56 | $ip >>= 8; 57 | $str = ($ip & 255).".$str"; 58 | } 59 | -------------------------------------------------------------------------------- /contrib/unicode2nginx/unicode-to-nginx.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # Convert unicode mappings to nginx configuration file format. 4 | 5 | # You may find useful mappings in various places, including 6 | # unicode.org official site: 7 | # 8 | # http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1251.TXT 9 | # http://www.unicode.org/Public/MAPPINGS/VENDORS/MISC/KOI8-R.TXT 10 | 11 | # Needs perl 5.6 or later. 12 | 13 | # Written by Maxim Dounin, mdounin@mdounin.ru 14 | 15 | ############################################################################### 16 | 17 | require 5.006; 18 | 19 | while (<>) { 20 | # Skip comments and empty lines 21 | 22 | next if /^#/; 23 | next if /^\s*$/; 24 | chomp; 25 | 26 | # Convert mappings 27 | 28 | if (/^\s*0x(..)\s*0x(....)\s*(#.*)/) { 29 | # Mapping "#" 30 | my $cs_code = $1; 31 | my $un_code = $2; 32 | my $un_name = $3; 33 | 34 | # Produce UTF-8 sequence from character code; 35 | 36 | my $un_utf8 = join('', 37 | map { sprintf("%02X", $_) } 38 | unpack("U0C*", pack("U", hex($un_code))) 39 | ); 40 | 41 | print " $cs_code $un_utf8 ; $un_name\n"; 42 | 43 | } else { 44 | warn "Unrecognized line: '$_'"; 45 | } 46 | } 47 | 48 | ############################################################################### 49 | -------------------------------------------------------------------------------- /contrib/vim/ftdetect/nginx.vim: -------------------------------------------------------------------------------- 1 | au BufRead,BufNewFile *.nginx set ft=nginx 2 | au BufRead,BufNewFile */etc/nginx/* set ft=nginx 3 | au BufRead,BufNewFile */usr/local/nginx/conf/* set ft=nginx 4 | au BufRead,BufNewFile nginx.conf set ft=nginx 5 | -------------------------------------------------------------------------------- /contrib/vim/ftplugin/nginx.vim: -------------------------------------------------------------------------------- 1 | setlocal commentstring=#\ %s 2 | -------------------------------------------------------------------------------- /contrib/vim/indent/nginx.vim: -------------------------------------------------------------------------------- 1 | if exists("b:did_indent") 2 | finish 3 | endif 4 | let b:did_indent = 1 5 | 6 | setlocal indentexpr= 7 | 8 | " cindent actually works for nginx' simple file structure 9 | setlocal cindent 10 | " Just make sure that the comments are not reset as defs would be. 11 | setlocal cinkeys-=0# 12 | -------------------------------------------------------------------------------- /docs/html/50x.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Error 5 | 10 | 11 | 12 |

An error occurred.

13 |

Sorry, the page you are looking for is currently unavailable.
14 | Please try again later.

15 |

If you are the system administrator of this resource then you should check 16 | the error log for details.

17 |

Faithfully yours, nginx.

18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Welcome to nginx! 5 | 10 | 11 | 12 |

Welcome to nginx!

13 |

If you see this page, the nginx web server is successfully installed and 14 | working. Further configuration is required.

15 | 16 |

For online documentation and support please refer to 17 | nginx.org.
18 | Commercial support is available at 19 | nginx.com.

20 | 21 |

Thank you for using nginx.

22 | 23 | 24 | -------------------------------------------------------------------------------- /modules/nginx_qat_module/config: -------------------------------------------------------------------------------- 1 | # Copyright (C) Intel, Inc. 2 | 3 | ngx_addon_name=ngx_ssl_engine_qat_module 4 | 5 | if test -n "$ngx_module_link"; then 6 | ngx_module_type=ENGINE 7 | ngx_module_name=ngx_ssl_engine_qat_module 8 | ngx_module_srcs="$ngx_addon_dir/ngx_ssl_engine_qat_module.c" 9 | 10 | . auto/module 11 | else 12 | SSL_ENGINE_MODULES="$SSL_ENGINE_MODULES ngx_ssl_engine_qat_module" 13 | NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_ssl_engine_qat_module.c" 14 | fi 15 | 16 | -------------------------------------------------------------------------------- /modules/nginx_qatzip_module/config: -------------------------------------------------------------------------------- 1 | # Copyright (C) Intel, Inc. 2 | 3 | ngx_addon_name=ngx_http_qatzip_filter_module 4 | 5 | if test -n "$ngx_module_link"; then 6 | ngx_module_type=HTTP 7 | ngx_module_name=ngx_http_qatzip_filter_module 8 | ngx_module_srcs="$ngx_addon_dir/ngx_http_qatzip_filter_module.c" 9 | 10 | ngx_module_order="ngx_http_static_module \ 11 | ngx_http_gzip_static_module \ 12 | ngx_http_dav_module \ 13 | ngx_http_autoindex_module \ 14 | ngx_http_index_module \ 15 | ngx_http_random_index_module \ 16 | ngx_http_access_module \ 17 | ngx_http_realip_module \ 18 | ngx_http_write_filter_module \ 19 | ngx_http_header_filter_module \ 20 | ngx_http_chunked_filter_module \ 21 | ngx_http_v2_filter_module \ 22 | ngx_http_range_header_filter_module \ 23 | ngx_http_qatzip_filter_module \ 24 | ngx_http_postpone_filter_module \ 25 | ngx_http_ssi_filter_module \ 26 | ngx_http_charset_filter_module \ 27 | ngx_http_xslt_filter_module \ 28 | ngx_http_image_filter_module \ 29 | ngx_http_sub_filter_module \ 30 | ngx_http_addition_filter_module \ 31 | ngx_http_gunzip_filter_module \ 32 | ngx_http_userid_filter_module \ 33 | ngx_http_headers_filter_module \ 34 | ngx_http_copy_filter_module \ 35 | ngx_http_range_body_filter_module \ 36 | ngx_http_not_modified_filter_module \ 37 | ngx_http_slice_filter_module" 38 | 39 | 40 | . auto/module 41 | else 42 | HTTP_MODULES="$HTTP_MODULES ngx_http_qatzip_filter_module" 43 | NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_qatzip_filter_module.c" 44 | fi 45 | -------------------------------------------------------------------------------- /src/core/nginx.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGINX_H_INCLUDED_ 9 | #define _NGINX_H_INCLUDED_ 10 | 11 | 12 | #define nginx_version 1026002 13 | #define NGINX_VERSION "1.26.2" 14 | #define NGINX_VER "nginx/" NGINX_VERSION 15 | 16 | #ifdef NGX_BUILD 17 | #define NGINX_VER_BUILD NGINX_VER " (" NGX_BUILD ")" 18 | #else 19 | #define NGINX_VER_BUILD NGINX_VER 20 | #endif 21 | 22 | #define NGINX_VAR "NGINX" 23 | #define NGX_OLDPID_EXT ".oldbin" 24 | 25 | 26 | #endif /* _NGINX_H_INCLUDED_ */ 27 | -------------------------------------------------------------------------------- /src/core/ngx_array.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_ARRAY_H_INCLUDED_ 9 | #define _NGX_ARRAY_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef struct { 17 | void *elts; 18 | ngx_uint_t nelts; 19 | size_t size; 20 | ngx_uint_t nalloc; 21 | ngx_pool_t *pool; 22 | } ngx_array_t; 23 | 24 | 25 | ngx_array_t *ngx_array_create(ngx_pool_t *p, ngx_uint_t n, size_t size); 26 | void ngx_array_destroy(ngx_array_t *a); 27 | void *ngx_array_push(ngx_array_t *a); 28 | void *ngx_array_push_n(ngx_array_t *a, ngx_uint_t n); 29 | 30 | 31 | static ngx_inline ngx_int_t 32 | ngx_array_init(ngx_array_t *array, ngx_pool_t *pool, ngx_uint_t n, size_t size) 33 | { 34 | /* 35 | * set "array->nelts" before "array->elts", otherwise MSVC thinks 36 | * that "array->nelts" may be used without having been initialized 37 | */ 38 | 39 | array->nelts = 0; 40 | array->size = size; 41 | array->nalloc = n; 42 | array->pool = pool; 43 | 44 | array->elts = ngx_palloc(pool, n * size); 45 | if (array->elts == NULL) { 46 | return NGX_ERROR; 47 | } 48 | 49 | return NGX_OK; 50 | } 51 | 52 | 53 | #endif /* _NGX_ARRAY_H_INCLUDED_ */ 54 | -------------------------------------------------------------------------------- /src/core/ngx_bpf.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | 7 | #ifndef _NGX_BPF_H_INCLUDED_ 8 | #define _NGX_BPF_H_INCLUDED_ 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | typedef struct { 17 | char *name; 18 | int offset; 19 | } ngx_bpf_reloc_t; 20 | 21 | typedef struct { 22 | char *license; 23 | enum bpf_prog_type type; 24 | struct bpf_insn *ins; 25 | size_t nins; 26 | ngx_bpf_reloc_t *relocs; 27 | size_t nrelocs; 28 | } ngx_bpf_program_t; 29 | 30 | 31 | void ngx_bpf_program_link(ngx_bpf_program_t *program, const char *symbol, 32 | int fd); 33 | int ngx_bpf_load_program(ngx_log_t *log, ngx_bpf_program_t *program); 34 | 35 | int ngx_bpf_map_create(ngx_log_t *log, enum bpf_map_type type, int key_size, 36 | int value_size, int max_entries, uint32_t map_flags); 37 | int ngx_bpf_map_update(int fd, const void *key, const void *value, 38 | uint64_t flags); 39 | int ngx_bpf_map_delete(int fd, const void *key); 40 | int ngx_bpf_map_lookup(int fd, const void *key, void *value); 41 | 42 | #endif /* _NGX_BPF_H_INCLUDED_ */ 43 | 44 | -------------------------------------------------------------------------------- /src/core/ngx_crc.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_CRC_H_INCLUDED_ 9 | #define _NGX_CRC_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | /* 32-bit crc16 */ 17 | 18 | static ngx_inline uint32_t 19 | ngx_crc(u_char *data, size_t len) 20 | { 21 | uint32_t sum; 22 | 23 | for (sum = 0; len; len--) { 24 | 25 | /* 26 | * gcc 2.95.2 x86 and icc 7.1.006 compile 27 | * that operator into the single "rol" opcode, 28 | * msvc 6.0sp2 compiles it into four opcodes. 29 | */ 30 | sum = sum >> 1 | sum << 31; 31 | 32 | sum += *data++; 33 | } 34 | 35 | return sum; 36 | } 37 | 38 | 39 | #endif /* _NGX_CRC_H_INCLUDED_ */ 40 | -------------------------------------------------------------------------------- /src/core/ngx_crc32.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_CRC32_H_INCLUDED_ 9 | #define _NGX_CRC32_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | extern uint32_t *ngx_crc32_table_short; 17 | extern uint32_t ngx_crc32_table256[]; 18 | 19 | 20 | static ngx_inline uint32_t 21 | ngx_crc32_short(u_char *p, size_t len) 22 | { 23 | u_char c; 24 | uint32_t crc; 25 | 26 | crc = 0xffffffff; 27 | 28 | while (len--) { 29 | c = *p++; 30 | crc = ngx_crc32_table_short[(crc ^ (c & 0xf)) & 0xf] ^ (crc >> 4); 31 | crc = ngx_crc32_table_short[(crc ^ (c >> 4)) & 0xf] ^ (crc >> 4); 32 | } 33 | 34 | return crc ^ 0xffffffff; 35 | } 36 | 37 | 38 | static ngx_inline uint32_t 39 | ngx_crc32_long(u_char *p, size_t len) 40 | { 41 | uint32_t crc; 42 | 43 | crc = 0xffffffff; 44 | 45 | while (len--) { 46 | crc = ngx_crc32_table256[(crc ^ *p++) & 0xff] ^ (crc >> 8); 47 | } 48 | 49 | return crc ^ 0xffffffff; 50 | } 51 | 52 | 53 | #define ngx_crc32_init(crc) \ 54 | crc = 0xffffffff 55 | 56 | 57 | static ngx_inline void 58 | ngx_crc32_update(uint32_t *crc, u_char *p, size_t len) 59 | { 60 | uint32_t c; 61 | 62 | c = *crc; 63 | 64 | while (len--) { 65 | c = ngx_crc32_table256[(c ^ *p++) & 0xff] ^ (c >> 8); 66 | } 67 | 68 | *crc = c; 69 | } 70 | 71 | 72 | #define ngx_crc32_final(crc) \ 73 | crc ^= 0xffffffff 74 | 75 | 76 | ngx_int_t ngx_crc32_table_init(void); 77 | 78 | 79 | #endif /* _NGX_CRC32_H_INCLUDED_ */ 80 | -------------------------------------------------------------------------------- /src/core/ngx_crypt.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_CRYPT_H_INCLUDED_ 9 | #define _NGX_CRYPT_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | ngx_int_t ngx_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, 17 | u_char **encrypted); 18 | 19 | 20 | #endif /* _NGX_CRYPT_H_INCLUDED_ */ 21 | -------------------------------------------------------------------------------- /src/core/ngx_list.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | ngx_list_t * 13 | ngx_list_create(ngx_pool_t *pool, ngx_uint_t n, size_t size) 14 | { 15 | ngx_list_t *list; 16 | 17 | list = ngx_palloc(pool, sizeof(ngx_list_t)); 18 | if (list == NULL) { 19 | return NULL; 20 | } 21 | 22 | if (ngx_list_init(list, pool, n, size) != NGX_OK) { 23 | return NULL; 24 | } 25 | 26 | return list; 27 | } 28 | 29 | 30 | void * 31 | ngx_list_push(ngx_list_t *l) 32 | { 33 | void *elt; 34 | ngx_list_part_t *last; 35 | 36 | last = l->last; 37 | 38 | if (last->nelts == l->nalloc) { 39 | 40 | /* the last part is full, allocate a new list part */ 41 | 42 | last = ngx_palloc(l->pool, sizeof(ngx_list_part_t)); 43 | if (last == NULL) { 44 | return NULL; 45 | } 46 | 47 | last->elts = ngx_palloc(l->pool, l->nalloc * l->size); 48 | if (last->elts == NULL) { 49 | return NULL; 50 | } 51 | 52 | last->nelts = 0; 53 | last->next = NULL; 54 | 55 | l->last->next = last; 56 | l->last = last; 57 | } 58 | 59 | elt = (char *) last->elts + l->size * last->nelts; 60 | last->nelts++; 61 | 62 | return elt; 63 | } 64 | -------------------------------------------------------------------------------- /src/core/ngx_list.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_LIST_H_INCLUDED_ 9 | #define _NGX_LIST_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef struct ngx_list_part_s ngx_list_part_t; 17 | 18 | struct ngx_list_part_s { 19 | void *elts; 20 | ngx_uint_t nelts; 21 | ngx_list_part_t *next; 22 | }; 23 | 24 | 25 | typedef struct { 26 | ngx_list_part_t *last; 27 | ngx_list_part_t part; 28 | size_t size; 29 | ngx_uint_t nalloc; 30 | ngx_pool_t *pool; 31 | } ngx_list_t; 32 | 33 | 34 | ngx_list_t *ngx_list_create(ngx_pool_t *pool, ngx_uint_t n, size_t size); 35 | 36 | static ngx_inline ngx_int_t 37 | ngx_list_init(ngx_list_t *list, ngx_pool_t *pool, ngx_uint_t n, size_t size) 38 | { 39 | list->part.elts = ngx_palloc(pool, n * size); 40 | if (list->part.elts == NULL) { 41 | return NGX_ERROR; 42 | } 43 | 44 | list->part.nelts = 0; 45 | list->part.next = NULL; 46 | list->last = &list->part; 47 | list->size = size; 48 | list->nalloc = n; 49 | list->pool = pool; 50 | 51 | return NGX_OK; 52 | } 53 | 54 | 55 | /* 56 | * 57 | * the iteration through the list: 58 | * 59 | * part = &list.part; 60 | * data = part->elts; 61 | * 62 | * for (i = 0 ;; i++) { 63 | * 64 | * if (i >= part->nelts) { 65 | * if (part->next == NULL) { 66 | * break; 67 | * } 68 | * 69 | * part = part->next; 70 | * data = part->elts; 71 | * i = 0; 72 | * } 73 | * 74 | * ... data[i] ... 75 | * 76 | * } 77 | */ 78 | 79 | 80 | void *ngx_list_push(ngx_list_t *list); 81 | 82 | 83 | #endif /* _NGX_LIST_H_INCLUDED_ */ 84 | -------------------------------------------------------------------------------- /src/core/ngx_md5.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_MD5_H_INCLUDED_ 9 | #define _NGX_MD5_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef struct { 17 | uint64_t bytes; 18 | uint32_t a, b, c, d; 19 | u_char buffer[64]; 20 | } ngx_md5_t; 21 | 22 | 23 | void ngx_md5_init(ngx_md5_t *ctx); 24 | void ngx_md5_update(ngx_md5_t *ctx, const void *data, size_t size); 25 | void ngx_md5_final(u_char result[16], ngx_md5_t *ctx); 26 | 27 | 28 | #endif /* _NGX_MD5_H_INCLUDED_ */ 29 | -------------------------------------------------------------------------------- /src/core/ngx_murmurhash.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Austin Appleby 4 | */ 5 | 6 | 7 | #include 8 | #include 9 | 10 | 11 | uint32_t 12 | ngx_murmur_hash2(u_char *data, size_t len) 13 | { 14 | uint32_t h, k; 15 | 16 | h = 0 ^ len; 17 | 18 | while (len >= 4) { 19 | k = data[0]; 20 | k |= data[1] << 8; 21 | k |= data[2] << 16; 22 | k |= data[3] << 24; 23 | 24 | k *= 0x5bd1e995; 25 | k ^= k >> 24; 26 | k *= 0x5bd1e995; 27 | 28 | h *= 0x5bd1e995; 29 | h ^= k; 30 | 31 | data += 4; 32 | len -= 4; 33 | } 34 | 35 | switch (len) { 36 | case 3: 37 | h ^= data[2] << 16; 38 | /* fall through */ 39 | case 2: 40 | h ^= data[1] << 8; 41 | /* fall through */ 42 | case 1: 43 | h ^= data[0]; 44 | h *= 0x5bd1e995; 45 | } 46 | 47 | h ^= h >> 13; 48 | h *= 0x5bd1e995; 49 | h ^= h >> 15; 50 | 51 | return h; 52 | } 53 | -------------------------------------------------------------------------------- /src/core/ngx_murmurhash.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_MURMURHASH_H_INCLUDED_ 9 | #define _NGX_MURMURHASH_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | uint32_t ngx_murmur_hash2(u_char *data, size_t len); 17 | 18 | 19 | #endif /* _NGX_MURMURHASH_H_INCLUDED_ */ 20 | -------------------------------------------------------------------------------- /src/core/ngx_parse.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_PARSE_H_INCLUDED_ 9 | #define _NGX_PARSE_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | ssize_t ngx_parse_size(ngx_str_t *line); 17 | off_t ngx_parse_offset(ngx_str_t *line); 18 | ngx_int_t ngx_parse_time(ngx_str_t *line, ngx_uint_t is_sec); 19 | 20 | 21 | #endif /* _NGX_PARSE_H_INCLUDED_ */ 22 | -------------------------------------------------------------------------------- /src/core/ngx_parse_time.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_PARSE_TIME_H_INCLUDED_ 9 | #define _NGX_PARSE_TIME_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | time_t ngx_parse_http_time(u_char *value, size_t len); 17 | 18 | /* compatibility */ 19 | #define ngx_http_parse_time(value, len) ngx_parse_http_time(value, len) 20 | 21 | 22 | #endif /* _NGX_PARSE_TIME_H_INCLUDED_ */ 23 | -------------------------------------------------------------------------------- /src/core/ngx_proxy_protocol.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Roman Arutyunyan 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_PROXY_PROTOCOL_H_INCLUDED_ 9 | #define _NGX_PROXY_PROTOCOL_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | #define NGX_PROXY_PROTOCOL_V1_MAX_HEADER 107 17 | #define NGX_PROXY_PROTOCOL_MAX_HEADER 4096 18 | 19 | 20 | struct ngx_proxy_protocol_s { 21 | ngx_str_t src_addr; 22 | ngx_str_t dst_addr; 23 | in_port_t src_port; 24 | in_port_t dst_port; 25 | ngx_str_t tlvs; 26 | }; 27 | 28 | 29 | u_char *ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, 30 | u_char *last); 31 | u_char *ngx_proxy_protocol_write(ngx_connection_t *c, u_char *buf, 32 | u_char *last); 33 | ngx_int_t ngx_proxy_protocol_get_tlv(ngx_connection_t *c, ngx_str_t *name, 34 | ngx_str_t *value); 35 | 36 | 37 | #endif /* _NGX_PROXY_PROTOCOL_H_INCLUDED_ */ 38 | -------------------------------------------------------------------------------- /src/core/ngx_radix_tree.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_RADIX_TREE_H_INCLUDED_ 9 | #define _NGX_RADIX_TREE_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | #define NGX_RADIX_NO_VALUE (uintptr_t) -1 17 | 18 | typedef struct ngx_radix_node_s ngx_radix_node_t; 19 | 20 | struct ngx_radix_node_s { 21 | ngx_radix_node_t *right; 22 | ngx_radix_node_t *left; 23 | ngx_radix_node_t *parent; 24 | uintptr_t value; 25 | }; 26 | 27 | 28 | typedef struct { 29 | ngx_radix_node_t *root; 30 | ngx_pool_t *pool; 31 | ngx_radix_node_t *free; 32 | char *start; 33 | size_t size; 34 | } ngx_radix_tree_t; 35 | 36 | 37 | ngx_radix_tree_t *ngx_radix_tree_create(ngx_pool_t *pool, 38 | ngx_int_t preallocate); 39 | 40 | ngx_int_t ngx_radix32tree_insert(ngx_radix_tree_t *tree, 41 | uint32_t key, uint32_t mask, uintptr_t value); 42 | ngx_int_t ngx_radix32tree_delete(ngx_radix_tree_t *tree, 43 | uint32_t key, uint32_t mask); 44 | uintptr_t ngx_radix32tree_find(ngx_radix_tree_t *tree, uint32_t key); 45 | 46 | #if (NGX_HAVE_INET6) 47 | ngx_int_t ngx_radix128tree_insert(ngx_radix_tree_t *tree, 48 | u_char *key, u_char *mask, uintptr_t value); 49 | ngx_int_t ngx_radix128tree_delete(ngx_radix_tree_t *tree, 50 | u_char *key, u_char *mask); 51 | uintptr_t ngx_radix128tree_find(ngx_radix_tree_t *tree, u_char *key); 52 | #endif 53 | 54 | 55 | #endif /* _NGX_RADIX_TREE_H_INCLUDED_ */ 56 | -------------------------------------------------------------------------------- /src/core/ngx_regex.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_REGEX_H_INCLUDED_ 9 | #define _NGX_REGEX_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | #if (NGX_PCRE2) 17 | 18 | #define PCRE2_CODE_UNIT_WIDTH 8 19 | #include 20 | 21 | #define NGX_REGEX_NO_MATCHED PCRE2_ERROR_NOMATCH /* -1 */ 22 | 23 | typedef pcre2_code ngx_regex_t; 24 | 25 | #else 26 | 27 | #include 28 | 29 | #define NGX_REGEX_NO_MATCHED PCRE_ERROR_NOMATCH /* -1 */ 30 | 31 | typedef struct { 32 | pcre *code; 33 | pcre_extra *extra; 34 | } ngx_regex_t; 35 | 36 | #endif 37 | 38 | 39 | #define NGX_REGEX_CASELESS 0x00000001 40 | #define NGX_REGEX_MULTILINE 0x00000002 41 | 42 | 43 | typedef struct { 44 | ngx_str_t pattern; 45 | ngx_pool_t *pool; 46 | ngx_uint_t options; 47 | 48 | ngx_regex_t *regex; 49 | int captures; 50 | int named_captures; 51 | int name_size; 52 | u_char *names; 53 | ngx_str_t err; 54 | } ngx_regex_compile_t; 55 | 56 | 57 | typedef struct { 58 | ngx_regex_t *regex; 59 | u_char *name; 60 | } ngx_regex_elt_t; 61 | 62 | 63 | void ngx_regex_init(void); 64 | ngx_int_t ngx_regex_compile(ngx_regex_compile_t *rc); 65 | 66 | ngx_int_t ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s, int *captures, 67 | ngx_uint_t size); 68 | 69 | #if (NGX_PCRE2) 70 | #define ngx_regex_exec_n "pcre2_match()" 71 | #else 72 | #define ngx_regex_exec_n "pcre_exec()" 73 | #endif 74 | 75 | ngx_int_t ngx_regex_exec_array(ngx_array_t *a, ngx_str_t *s, ngx_log_t *log); 76 | 77 | 78 | #endif /* _NGX_REGEX_H_INCLUDED_ */ 79 | -------------------------------------------------------------------------------- /src/core/ngx_rwlock.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Ruslan Ermilov 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_RWLOCK_H_INCLUDED_ 9 | #define _NGX_RWLOCK_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | void ngx_rwlock_wlock(ngx_atomic_t *lock); 17 | void ngx_rwlock_rlock(ngx_atomic_t *lock); 18 | void ngx_rwlock_unlock(ngx_atomic_t *lock); 19 | void ngx_rwlock_downgrade(ngx_atomic_t *lock); 20 | 21 | 22 | #endif /* _NGX_RWLOCK_H_INCLUDED_ */ 23 | -------------------------------------------------------------------------------- /src/core/ngx_sha1.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_SHA1_H_INCLUDED_ 9 | #define _NGX_SHA1_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef struct { 17 | uint64_t bytes; 18 | uint32_t a, b, c, d, e, f; 19 | u_char buffer[64]; 20 | } ngx_sha1_t; 21 | 22 | 23 | void ngx_sha1_init(ngx_sha1_t *ctx); 24 | void ngx_sha1_update(ngx_sha1_t *ctx, const void *data, size_t size); 25 | void ngx_sha1_final(u_char result[20], ngx_sha1_t *ctx); 26 | 27 | 28 | #endif /* _NGX_SHA1_H_INCLUDED_ */ 29 | -------------------------------------------------------------------------------- /src/core/ngx_shmtx.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_SHMTX_H_INCLUDED_ 9 | #define _NGX_SHMTX_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef struct { 17 | ngx_atomic_t lock; 18 | #if (NGX_HAVE_POSIX_SEM) 19 | ngx_atomic_t wait; 20 | #endif 21 | } ngx_shmtx_sh_t; 22 | 23 | 24 | typedef struct { 25 | #if (NGX_HAVE_ATOMIC_OPS) 26 | ngx_atomic_t *lock; 27 | #if (NGX_HAVE_POSIX_SEM) 28 | ngx_atomic_t *wait; 29 | ngx_uint_t semaphore; 30 | sem_t sem; 31 | #endif 32 | #else 33 | ngx_fd_t fd; 34 | u_char *name; 35 | #endif 36 | ngx_uint_t spin; 37 | } ngx_shmtx_t; 38 | 39 | 40 | ngx_int_t ngx_shmtx_create(ngx_shmtx_t *mtx, ngx_shmtx_sh_t *addr, 41 | u_char *name); 42 | void ngx_shmtx_destroy(ngx_shmtx_t *mtx); 43 | ngx_uint_t ngx_shmtx_trylock(ngx_shmtx_t *mtx); 44 | void ngx_shmtx_lock(ngx_shmtx_t *mtx); 45 | void ngx_shmtx_unlock(ngx_shmtx_t *mtx); 46 | ngx_uint_t ngx_shmtx_force_unlock(ngx_shmtx_t *mtx, ngx_pid_t pid); 47 | 48 | 49 | #endif /* _NGX_SHMTX_H_INCLUDED_ */ 50 | -------------------------------------------------------------------------------- /src/core/ngx_slab.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_SLAB_H_INCLUDED_ 9 | #define _NGX_SLAB_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef struct ngx_slab_page_s ngx_slab_page_t; 17 | 18 | struct ngx_slab_page_s { 19 | uintptr_t slab; 20 | ngx_slab_page_t *next; 21 | uintptr_t prev; 22 | }; 23 | 24 | 25 | typedef struct { 26 | ngx_uint_t total; 27 | ngx_uint_t used; 28 | 29 | ngx_uint_t reqs; 30 | ngx_uint_t fails; 31 | } ngx_slab_stat_t; 32 | 33 | 34 | typedef struct { 35 | ngx_shmtx_sh_t lock; 36 | 37 | size_t min_size; 38 | size_t min_shift; 39 | 40 | ngx_slab_page_t *pages; 41 | ngx_slab_page_t *last; 42 | ngx_slab_page_t free; 43 | 44 | ngx_slab_stat_t *stats; 45 | ngx_uint_t pfree; 46 | 47 | u_char *start; 48 | u_char *end; 49 | 50 | ngx_shmtx_t mutex; 51 | 52 | u_char *log_ctx; 53 | u_char zero; 54 | 55 | unsigned log_nomem:1; 56 | 57 | void *data; 58 | void *addr; 59 | } ngx_slab_pool_t; 60 | 61 | 62 | void ngx_slab_sizes_init(void); 63 | void ngx_slab_init(ngx_slab_pool_t *pool); 64 | void *ngx_slab_alloc(ngx_slab_pool_t *pool, size_t size); 65 | void *ngx_slab_alloc_locked(ngx_slab_pool_t *pool, size_t size); 66 | void *ngx_slab_calloc(ngx_slab_pool_t *pool, size_t size); 67 | void *ngx_slab_calloc_locked(ngx_slab_pool_t *pool, size_t size); 68 | void ngx_slab_free(ngx_slab_pool_t *pool, void *p); 69 | void ngx_slab_free_locked(ngx_slab_pool_t *pool, void *p); 70 | 71 | 72 | #endif /* _NGX_SLAB_H_INCLUDED_ */ 73 | -------------------------------------------------------------------------------- /src/core/ngx_spinlock.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | void 13 | ngx_spinlock(ngx_atomic_t *lock, ngx_atomic_int_t value, ngx_uint_t spin) 14 | { 15 | 16 | #if (NGX_HAVE_ATOMIC_OPS) 17 | 18 | ngx_uint_t i, n; 19 | 20 | for ( ;; ) { 21 | 22 | if (*lock == 0 && ngx_atomic_cmp_set(lock, 0, value)) { 23 | return; 24 | } 25 | 26 | if (ngx_ncpu > 1) { 27 | 28 | for (n = 1; n < spin; n <<= 1) { 29 | 30 | for (i = 0; i < n; i++) { 31 | ngx_cpu_pause(); 32 | } 33 | 34 | if (*lock == 0 && ngx_atomic_cmp_set(lock, 0, value)) { 35 | return; 36 | } 37 | } 38 | } 39 | 40 | ngx_sched_yield(); 41 | } 42 | 43 | #else 44 | 45 | #if (NGX_THREADS) 46 | 47 | #error ngx_spinlock() or ngx_atomic_cmp_set() are not defined ! 48 | 49 | #endif 50 | 51 | #endif 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/core/ngx_syslog.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | 7 | #ifndef _NGX_SYSLOG_H_INCLUDED_ 8 | #define _NGX_SYSLOG_H_INCLUDED_ 9 | 10 | 11 | typedef struct { 12 | ngx_uint_t facility; 13 | ngx_uint_t severity; 14 | ngx_str_t tag; 15 | 16 | ngx_str_t *hostname; 17 | 18 | ngx_addr_t server; 19 | ngx_connection_t conn; 20 | 21 | ngx_log_t log; 22 | ngx_log_t *logp; 23 | 24 | unsigned busy:1; 25 | unsigned nohostname:1; 26 | } ngx_syslog_peer_t; 27 | 28 | 29 | char *ngx_syslog_process_conf(ngx_conf_t *cf, ngx_syslog_peer_t *peer); 30 | u_char *ngx_syslog_add_header(ngx_syslog_peer_t *peer, u_char *buf); 31 | void ngx_syslog_writer(ngx_log_t *log, ngx_uint_t level, u_char *buf, 32 | size_t len); 33 | ssize_t ngx_syslog_send(ngx_syslog_peer_t *peer, u_char *buf, size_t len); 34 | 35 | 36 | #endif /* _NGX_SYSLOG_H_INCLUDED_ */ 37 | -------------------------------------------------------------------------------- /src/core/ngx_thread_pool.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | * Copyright (C) Valentin V. Bartenev 5 | */ 6 | 7 | 8 | #ifndef _NGX_THREAD_POOL_H_INCLUDED_ 9 | #define _NGX_THREAD_POOL_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | struct ngx_thread_task_s { 18 | ngx_thread_task_t *next; 19 | ngx_uint_t id; 20 | void *ctx; 21 | void (*handler)(void *data, ngx_log_t *log); 22 | ngx_event_t event; 23 | }; 24 | 25 | 26 | typedef struct ngx_thread_pool_s ngx_thread_pool_t; 27 | 28 | 29 | ngx_thread_pool_t *ngx_thread_pool_add(ngx_conf_t *cf, ngx_str_t *name); 30 | ngx_thread_pool_t *ngx_thread_pool_get(ngx_cycle_t *cycle, ngx_str_t *name); 31 | 32 | ngx_thread_task_t *ngx_thread_task_alloc(ngx_pool_t *pool, size_t size); 33 | ngx_int_t ngx_thread_task_post(ngx_thread_pool_t *tp, ngx_thread_task_t *task); 34 | 35 | 36 | #endif /* _NGX_THREAD_POOL_H_INCLUDED_ */ 37 | -------------------------------------------------------------------------------- /src/core/ngx_times.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_TIMES_H_INCLUDED_ 9 | #define _NGX_TIMES_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef struct { 17 | time_t sec; 18 | ngx_uint_t msec; 19 | ngx_int_t gmtoff; 20 | } ngx_time_t; 21 | 22 | 23 | void ngx_time_init(void); 24 | void ngx_time_update(void); 25 | void ngx_time_sigsafe_update(void); 26 | u_char *ngx_http_time(u_char *buf, time_t t); 27 | u_char *ngx_http_cookie_time(u_char *buf, time_t t); 28 | void ngx_gmtime(time_t t, ngx_tm_t *tp); 29 | 30 | time_t ngx_next_time(time_t when); 31 | #define ngx_next_time_n "mktime()" 32 | 33 | 34 | extern volatile ngx_time_t *ngx_cached_time; 35 | 36 | #define ngx_time() ngx_cached_time->sec 37 | #define ngx_timeofday() (ngx_time_t *) ngx_cached_time 38 | 39 | extern volatile ngx_str_t ngx_cached_err_log_time; 40 | extern volatile ngx_str_t ngx_cached_http_time; 41 | extern volatile ngx_str_t ngx_cached_http_log_time; 42 | extern volatile ngx_str_t ngx_cached_http_log_iso8601; 43 | extern volatile ngx_str_t ngx_cached_syslog_time; 44 | 45 | /* 46 | * milliseconds elapsed since some unspecified point in the past 47 | * and truncated to ngx_msec_t, used in event timers 48 | */ 49 | extern volatile ngx_msec_t ngx_current_msec; 50 | 51 | 52 | #endif /* _NGX_TIMES_H_INCLUDED_ */ 53 | -------------------------------------------------------------------------------- /src/event/modules/ngx_iocp_module.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_IOCP_MODULE_H_INCLUDED_ 9 | #define _NGX_IOCP_MODULE_H_INCLUDED_ 10 | 11 | 12 | typedef struct { 13 | int threads; 14 | int post_acceptex; 15 | int acceptex_read; 16 | } ngx_iocp_conf_t; 17 | 18 | 19 | extern ngx_module_t ngx_iocp_module; 20 | 21 | 22 | #endif /* _NGX_IOCP_MODULE_H_INCLUDED_ */ 23 | -------------------------------------------------------------------------------- /src/event/ngx_event_posted.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | ngx_queue_t ngx_posted_accept_events; 14 | ngx_queue_t ngx_posted_next_events; 15 | ngx_queue_t ngx_posted_events; 16 | 17 | 18 | void 19 | ngx_event_process_posted(ngx_cycle_t *cycle, ngx_queue_t *posted) 20 | { 21 | ngx_queue_t *q; 22 | ngx_event_t *ev; 23 | 24 | while (!ngx_queue_empty(posted)) { 25 | 26 | q = ngx_queue_head(posted); 27 | ev = ngx_queue_data(q, ngx_event_t, queue); 28 | 29 | ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 30 | "posted event %p", ev); 31 | 32 | ngx_delete_posted_event(ev); 33 | 34 | ev->handler(ev); 35 | } 36 | } 37 | 38 | 39 | void 40 | ngx_event_move_posted_next(ngx_cycle_t *cycle) 41 | { 42 | ngx_queue_t *q; 43 | ngx_event_t *ev; 44 | 45 | for (q = ngx_queue_head(&ngx_posted_next_events); 46 | q != ngx_queue_sentinel(&ngx_posted_next_events); 47 | q = ngx_queue_next(q)) 48 | { 49 | ev = ngx_queue_data(q, ngx_event_t, queue); 50 | 51 | ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 52 | "posted next event %p", ev); 53 | 54 | ev->ready = 1; 55 | ev->available = -1; 56 | } 57 | 58 | ngx_queue_add(&ngx_posted_events, &ngx_posted_next_events); 59 | ngx_queue_init(&ngx_posted_next_events); 60 | } 61 | -------------------------------------------------------------------------------- /src/event/ngx_event_udp.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | 7 | #ifndef _NGX_EVENT_UDP_H_INCLUDED_ 8 | #define _NGX_EVENT_UDP_H_INCLUDED_ 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | #if !(NGX_WIN32) 16 | 17 | #if ((NGX_HAVE_MSGHDR_MSG_CONTROL) \ 18 | && (NGX_HAVE_IP_SENDSRCADDR || NGX_HAVE_IP_RECVDSTADDR \ 19 | || NGX_HAVE_IP_PKTINFO \ 20 | || (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO))) 21 | #define NGX_HAVE_ADDRINFO_CMSG 1 22 | 23 | #endif 24 | 25 | 26 | struct ngx_udp_connection_s { 27 | ngx_rbtree_node_t node; 28 | ngx_connection_t *connection; 29 | ngx_buf_t *buffer; 30 | ngx_str_t key; 31 | }; 32 | 33 | 34 | #if (NGX_HAVE_ADDRINFO_CMSG) 35 | 36 | typedef union { 37 | #if (NGX_HAVE_IP_SENDSRCADDR || NGX_HAVE_IP_RECVDSTADDR) 38 | struct in_addr addr; 39 | #endif 40 | 41 | #if (NGX_HAVE_IP_PKTINFO) 42 | struct in_pktinfo pkt; 43 | #endif 44 | 45 | #if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO) 46 | struct in6_pktinfo pkt6; 47 | #endif 48 | } ngx_addrinfo_t; 49 | 50 | size_t ngx_set_srcaddr_cmsg(struct cmsghdr *cmsg, 51 | struct sockaddr *local_sockaddr); 52 | ngx_int_t ngx_get_srcaddr_cmsg(struct cmsghdr *cmsg, 53 | struct sockaddr *local_sockaddr); 54 | 55 | #endif 56 | 57 | void ngx_event_recvmsg(ngx_event_t *ev); 58 | ssize_t ngx_sendmsg(ngx_connection_t *c, struct msghdr *msg, int flags); 59 | void ngx_udp_rbtree_insert_value(ngx_rbtree_node_t *temp, 60 | ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel); 61 | #endif 62 | 63 | void ngx_delete_udp_connection(void *data); 64 | 65 | 66 | #endif /* _NGX_EVENT_UDP_H_INCLUDED_ */ 67 | 68 | -------------------------------------------------------------------------------- /src/event/quic/bpf/makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-O2 -Wall 2 | 3 | LICENSE=BSD 4 | 5 | PROGNAME=ngx_quic_reuseport_helper 6 | RESULT=ngx_event_quic_bpf_code 7 | DEST=../$(RESULT).c 8 | 9 | all: $(RESULT) 10 | 11 | $(RESULT): $(PROGNAME).o 12 | LICENSE=$(LICENSE) PROGNAME=$(PROGNAME) bash ./bpfgen.sh $< > $@ 13 | 14 | DEFS=-DPROGNAME=\"$(PROGNAME)\" \ 15 | -DLICENSE_$(LICENSE) \ 16 | -DLICENSE=\"$(LICENSE)\" \ 17 | 18 | $(PROGNAME).o: $(PROGNAME).c 19 | clang $(CFLAGS) $(DEFS) -target bpf -c $< -o $@ 20 | 21 | install: $(RESULT) 22 | cp $(RESULT) $(DEST) 23 | 24 | clean: 25 | @rm -f $(RESULT) *.o 26 | 27 | debug: $(PROGNAME).o 28 | llvm-objdump -S -no-show-raw-insn $< 29 | 30 | .DELETE_ON_ERROR: 31 | -------------------------------------------------------------------------------- /src/event/quic/ngx_event_quic_ack.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | 7 | #ifndef _NGX_EVENT_QUIC_ACK_H_INCLUDED_ 8 | #define _NGX_EVENT_QUIC_ACK_H_INCLUDED_ 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | ngx_int_t ngx_quic_handle_ack_frame(ngx_connection_t *c, 16 | ngx_quic_header_t *pkt, ngx_quic_frame_t *f); 17 | 18 | void ngx_quic_congestion_ack(ngx_connection_t *c, 19 | ngx_quic_frame_t *frame); 20 | void ngx_quic_resend_frames(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx); 21 | void ngx_quic_set_lost_timer(ngx_connection_t *c); 22 | void ngx_quic_pto_handler(ngx_event_t *ev); 23 | ngx_msec_t ngx_quic_pto(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx); 24 | 25 | ngx_int_t ngx_quic_ack_packet(ngx_connection_t *c, 26 | ngx_quic_header_t *pkt); 27 | ngx_int_t ngx_quic_generate_ack(ngx_connection_t *c, 28 | ngx_quic_send_ctx_t *ctx); 29 | 30 | #endif /* _NGX_EVENT_QUIC_ACK_H_INCLUDED_ */ 31 | -------------------------------------------------------------------------------- /src/event/quic/ngx_event_quic_connid.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | 7 | #ifndef _NGX_EVENT_QUIC_CONNID_H_INCLUDED_ 8 | #define _NGX_EVENT_QUIC_CONNID_H_INCLUDED_ 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | ngx_int_t ngx_quic_handle_retire_connection_id_frame(ngx_connection_t *c, 16 | ngx_quic_retire_cid_frame_t *f); 17 | ngx_int_t ngx_quic_handle_new_connection_id_frame(ngx_connection_t *c, 18 | ngx_quic_new_conn_id_frame_t *f); 19 | 20 | ngx_int_t ngx_quic_create_sockets(ngx_connection_t *c); 21 | ngx_int_t ngx_quic_create_server_id(ngx_connection_t *c, u_char *id); 22 | 23 | ngx_quic_client_id_t *ngx_quic_create_client_id(ngx_connection_t *c, 24 | ngx_str_t *id, uint64_t seqnum, u_char *token); 25 | ngx_quic_client_id_t *ngx_quic_next_client_id(ngx_connection_t *c); 26 | ngx_int_t ngx_quic_free_client_id(ngx_connection_t *c, 27 | ngx_quic_client_id_t *cid); 28 | 29 | #endif /* _NGX_EVENT_QUIC_CONNID_H_INCLUDED_ */ 30 | -------------------------------------------------------------------------------- /src/event/quic/ngx_event_quic_frames.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | 7 | #ifndef _NGX_EVENT_QUIC_FRAMES_H_INCLUDED_ 8 | #define _NGX_EVENT_QUIC_FRAMES_H_INCLUDED_ 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | typedef ngx_int_t (*ngx_quic_frame_handler_pt)(ngx_connection_t *c, 16 | ngx_quic_frame_t *frame, void *data); 17 | 18 | 19 | ngx_quic_frame_t *ngx_quic_alloc_frame(ngx_connection_t *c); 20 | void ngx_quic_free_frame(ngx_connection_t *c, ngx_quic_frame_t *frame); 21 | void ngx_quic_free_frames(ngx_connection_t *c, ngx_queue_t *frames); 22 | void ngx_quic_queue_frame(ngx_quic_connection_t *qc, ngx_quic_frame_t *frame); 23 | ngx_int_t ngx_quic_split_frame(ngx_connection_t *c, ngx_quic_frame_t *f, 24 | size_t len); 25 | 26 | ngx_chain_t *ngx_quic_alloc_chain(ngx_connection_t *c); 27 | void ngx_quic_free_chain(ngx_connection_t *c, ngx_chain_t *in); 28 | 29 | ngx_chain_t *ngx_quic_copy_buffer(ngx_connection_t *c, u_char *data, 30 | size_t len); 31 | ngx_chain_t *ngx_quic_read_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb, 32 | uint64_t limit); 33 | ngx_chain_t *ngx_quic_write_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb, 34 | ngx_chain_t *in, uint64_t limit, uint64_t offset); 35 | void ngx_quic_skip_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb, 36 | uint64_t offset); 37 | void ngx_quic_free_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb); 38 | 39 | #if (NGX_DEBUG) 40 | void ngx_quic_log_frame(ngx_log_t *log, ngx_quic_frame_t *f, ngx_uint_t tx); 41 | #else 42 | #define ngx_quic_log_frame(log, f, tx) 43 | #endif 44 | 45 | #endif /* _NGX_EVENT_QUIC_FRAMES_H_INCLUDED_ */ 46 | -------------------------------------------------------------------------------- /src/event/quic/ngx_event_quic_migration.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | 7 | #ifndef _NGX_EVENT_QUIC_MIGRATION_H_INCLUDED_ 8 | #define _NGX_EVENT_QUIC_MIGRATION_H_INCLUDED_ 9 | 10 | 11 | #include 12 | #include 13 | 14 | #define NGX_QUIC_PATH_RETRIES 3 15 | 16 | #define NGX_QUIC_PATH_PROBE 0 17 | #define NGX_QUIC_PATH_ACTIVE 1 18 | #define NGX_QUIC_PATH_BACKUP 2 19 | 20 | #define ngx_quic_path_dbg(c, msg, path) \ 21 | ngx_log_debug7(NGX_LOG_DEBUG_EVENT, c->log, 0, \ 22 | "quic path seq:%uL %s tx:%O rx:%O valid:%d st:%d mtu:%uz", \ 23 | path->seqnum, msg, path->sent, path->received, \ 24 | path->validated, path->state, path->mtu); 25 | 26 | ngx_int_t ngx_quic_handle_path_challenge_frame(ngx_connection_t *c, 27 | ngx_quic_header_t *pkt, ngx_quic_path_challenge_frame_t *f); 28 | ngx_int_t ngx_quic_handle_path_response_frame(ngx_connection_t *c, 29 | ngx_quic_path_challenge_frame_t *f); 30 | 31 | ngx_quic_path_t *ngx_quic_new_path(ngx_connection_t *c, 32 | struct sockaddr *sockaddr, socklen_t socklen, ngx_quic_client_id_t *cid); 33 | ngx_int_t ngx_quic_free_path(ngx_connection_t *c, ngx_quic_path_t *path); 34 | 35 | ngx_int_t ngx_quic_set_path(ngx_connection_t *c, ngx_quic_header_t *pkt); 36 | ngx_int_t ngx_quic_handle_migration(ngx_connection_t *c, 37 | ngx_quic_header_t *pkt); 38 | 39 | void ngx_quic_path_handler(ngx_event_t *ev); 40 | 41 | void ngx_quic_discover_path_mtu(ngx_connection_t *c, ngx_quic_path_t *path); 42 | ngx_int_t ngx_quic_handle_path_mtu(ngx_connection_t *c, 43 | ngx_quic_path_t *path, uint64_t min, uint64_t max); 44 | 45 | #endif /* _NGX_EVENT_QUIC_MIGRATION_H_INCLUDED_ */ 46 | -------------------------------------------------------------------------------- /src/event/quic/ngx_event_quic_output.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | 7 | #ifndef _NGX_EVENT_QUIC_OUTPUT_H_INCLUDED_ 8 | #define _NGX_EVENT_QUIC_OUTPUT_H_INCLUDED_ 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | ngx_int_t ngx_quic_output(ngx_connection_t *c); 16 | 17 | ngx_int_t ngx_quic_negotiate_version(ngx_connection_t *c, 18 | ngx_quic_header_t *inpkt); 19 | 20 | ngx_int_t ngx_quic_send_stateless_reset(ngx_connection_t *c, 21 | ngx_quic_conf_t *conf, ngx_quic_header_t *pkt); 22 | ngx_int_t ngx_quic_send_cc(ngx_connection_t *c); 23 | ngx_int_t ngx_quic_send_early_cc(ngx_connection_t *c, 24 | ngx_quic_header_t *inpkt, ngx_uint_t err, const char *reason); 25 | 26 | ngx_int_t ngx_quic_send_retry(ngx_connection_t *c, 27 | ngx_quic_conf_t *conf, ngx_quic_header_t *pkt); 28 | ngx_int_t ngx_quic_send_new_token(ngx_connection_t *c, ngx_quic_path_t *path); 29 | 30 | ngx_int_t ngx_quic_send_ack(ngx_connection_t *c, 31 | ngx_quic_send_ctx_t *ctx); 32 | ngx_int_t ngx_quic_send_ack_range(ngx_connection_t *c, 33 | ngx_quic_send_ctx_t *ctx, uint64_t smallest, uint64_t largest); 34 | 35 | ngx_int_t ngx_quic_frame_sendto(ngx_connection_t *c, ngx_quic_frame_t *frame, 36 | size_t min, ngx_quic_path_t *path); 37 | size_t ngx_quic_path_limit(ngx_connection_t *c, ngx_quic_path_t *path, 38 | size_t size); 39 | 40 | #endif /* _NGX_EVENT_QUIC_OUTPUT_H_INCLUDED_ */ 41 | -------------------------------------------------------------------------------- /src/event/quic/ngx_event_quic_socket.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | 7 | #ifndef _NGX_EVENT_QUIC_SOCKET_H_INCLUDED_ 8 | #define _NGX_EVENT_QUIC_SOCKET_H_INCLUDED_ 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | ngx_int_t ngx_quic_open_sockets(ngx_connection_t *c, 16 | ngx_quic_connection_t *qc, ngx_quic_header_t *pkt); 17 | void ngx_quic_close_sockets(ngx_connection_t *c); 18 | 19 | ngx_quic_socket_t *ngx_quic_create_socket(ngx_connection_t *c, 20 | ngx_quic_connection_t *qc); 21 | ngx_int_t ngx_quic_listen(ngx_connection_t *c, ngx_quic_connection_t *qc, 22 | ngx_quic_socket_t *qsock); 23 | void ngx_quic_close_socket(ngx_connection_t *c, ngx_quic_socket_t *qsock); 24 | 25 | ngx_quic_socket_t *ngx_quic_find_socket(ngx_connection_t *c, uint64_t seqnum); 26 | 27 | 28 | #endif /* _NGX_EVENT_QUIC_SOCKET_H_INCLUDED_ */ 29 | -------------------------------------------------------------------------------- /src/event/quic/ngx_event_quic_ssl.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | 7 | #ifndef _NGX_EVENT_QUIC_SSL_H_INCLUDED_ 8 | #define _NGX_EVENT_QUIC_SSL_H_INCLUDED_ 9 | 10 | 11 | #include 12 | #include 13 | 14 | ngx_int_t ngx_quic_init_connection(ngx_connection_t *c); 15 | 16 | ngx_int_t ngx_quic_handle_crypto_frame(ngx_connection_t *c, 17 | ngx_quic_header_t *pkt, ngx_quic_frame_t *frame); 18 | 19 | #endif /* _NGX_EVENT_QUIC_SSL_H_INCLUDED_ */ 20 | -------------------------------------------------------------------------------- /src/event/quic/ngx_event_quic_streams.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | 7 | #ifndef _NGX_EVENT_QUIC_STREAMS_H_INCLUDED_ 8 | #define _NGX_EVENT_QUIC_STREAMS_H_INCLUDED_ 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | ngx_int_t ngx_quic_handle_stream_frame(ngx_connection_t *c, 16 | ngx_quic_header_t *pkt, ngx_quic_frame_t *frame); 17 | void ngx_quic_handle_stream_ack(ngx_connection_t *c, 18 | ngx_quic_frame_t *f); 19 | ngx_int_t ngx_quic_handle_max_data_frame(ngx_connection_t *c, 20 | ngx_quic_max_data_frame_t *f); 21 | ngx_int_t ngx_quic_handle_streams_blocked_frame(ngx_connection_t *c, 22 | ngx_quic_header_t *pkt, ngx_quic_streams_blocked_frame_t *f); 23 | ngx_int_t ngx_quic_handle_data_blocked_frame(ngx_connection_t *c, 24 | ngx_quic_header_t *pkt, ngx_quic_data_blocked_frame_t *f); 25 | ngx_int_t ngx_quic_handle_stream_data_blocked_frame(ngx_connection_t *c, 26 | ngx_quic_header_t *pkt, ngx_quic_stream_data_blocked_frame_t *f); 27 | ngx_int_t ngx_quic_handle_max_stream_data_frame(ngx_connection_t *c, 28 | ngx_quic_header_t *pkt, ngx_quic_max_stream_data_frame_t *f); 29 | ngx_int_t ngx_quic_handle_reset_stream_frame(ngx_connection_t *c, 30 | ngx_quic_header_t *pkt, ngx_quic_reset_stream_frame_t *f); 31 | ngx_int_t ngx_quic_handle_stop_sending_frame(ngx_connection_t *c, 32 | ngx_quic_header_t *pkt, ngx_quic_stop_sending_frame_t *f); 33 | ngx_int_t ngx_quic_handle_max_streams_frame(ngx_connection_t *c, 34 | ngx_quic_header_t *pkt, ngx_quic_max_streams_frame_t *f); 35 | 36 | ngx_int_t ngx_quic_init_streams(ngx_connection_t *c); 37 | void ngx_quic_rbtree_insert_stream(ngx_rbtree_node_t *temp, 38 | ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel); 39 | ngx_quic_stream_t *ngx_quic_find_stream(ngx_rbtree_t *rbtree, 40 | uint64_t id); 41 | ngx_int_t ngx_quic_close_streams(ngx_connection_t *c, 42 | ngx_quic_connection_t *qc); 43 | 44 | #endif /* _NGX_EVENT_QUIC_STREAMS_H_INCLUDED_ */ 45 | -------------------------------------------------------------------------------- /src/event/quic/ngx_event_quic_tokens.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | 7 | #ifndef _NGX_EVENT_QUIC_TOKENS_H_INCLUDED_ 8 | #define _NGX_EVENT_QUIC_TOKENS_H_INCLUDED_ 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | #define NGX_QUIC_MAX_TOKEN_SIZE 64 16 | /* SHA-1(addr)=20 + sizeof(time_t) + retry(1) + odcid.len(1) + odcid */ 17 | 18 | #define NGX_QUIC_AES_256_GCM_IV_LEN 12 19 | #define NGX_QUIC_AES_256_GCM_TAG_LEN 16 20 | 21 | #define NGX_QUIC_TOKEN_BUF_SIZE (NGX_QUIC_AES_256_GCM_IV_LEN \ 22 | + NGX_QUIC_MAX_TOKEN_SIZE \ 23 | + NGX_QUIC_AES_256_GCM_TAG_LEN) 24 | 25 | 26 | ngx_int_t ngx_quic_new_sr_token(ngx_connection_t *c, ngx_str_t *cid, 27 | u_char *secret, u_char *token); 28 | ngx_int_t ngx_quic_new_token(ngx_log_t *log, struct sockaddr *sockaddr, 29 | socklen_t socklen, u_char *key, ngx_str_t *token, ngx_str_t *odcid, 30 | time_t expires, ngx_uint_t is_retry); 31 | ngx_int_t ngx_quic_validate_token(ngx_connection_t *c, 32 | u_char *key, ngx_quic_header_t *pkt); 33 | 34 | #endif /* _NGX_EVENT_QUIC_TOKENS_H_INCLUDED_ */ 35 | -------------------------------------------------------------------------------- /src/http/modules/perl/Makefile.PL: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) Igor Sysoev 3 | # Copyright (C) Nginx, Inc. 4 | 5 | use 5.006001; 6 | use ExtUtils::MakeMaker; 7 | 8 | WriteMakefile( 9 | NAME => 'nginx', 10 | VERSION_FROM => 'nginx.pm', # finds $VERSION 11 | PREREQ_PM => {}, # e.g., Module::Name => 1.1 12 | 13 | ABSTRACT_FROM => 'nginx.pm', # retrieve abstract from module 14 | AUTHOR => 'Igor Sysoev', 15 | 16 | CCFLAGS => "$ENV{NGX_PM_CFLAGS}", 17 | OPTIMIZE => '-O', 18 | 19 | LDDLFLAGS => "$ENV{NGX_PM_LDFLAGS}", 20 | 21 | INC => join(" ", map { 22 | m#^/# ? "-I $_" : "-I ../../../../../$_" 23 | } (split /\s+/, $ENV{NGX_INCS})), 24 | 25 | depend => { 26 | 'nginx.c' => join(" ", map { 27 | m#^/# ? $_ : "../../../../../$_" 28 | } (split(/\s+/, $ENV{NGX_DEPS}), 29 | "src/http/modules/perl/ngx_http_perl_module.h")) 30 | }, 31 | 32 | PM => { 33 | 'nginx.pm' => '$(INST_LIBDIR)/nginx.pm' 34 | } 35 | ); 36 | -------------------------------------------------------------------------------- /src/http/modules/perl/ngx_http_perl_module.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_HTTP_PERL_MODULE_H_INCLUDED_ 9 | #define _NGX_HTTP_PERL_MODULE_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | 20 | 21 | typedef ngx_http_request_t *nginx; 22 | 23 | typedef struct { 24 | ngx_http_request_t *request; 25 | 26 | ngx_str_t filename; 27 | ngx_str_t redirect_uri; 28 | 29 | SV *next; 30 | 31 | ngx_int_t status; 32 | 33 | unsigned done:1; 34 | unsigned error:1; 35 | unsigned variable:1; 36 | unsigned header_sent:1; 37 | 38 | ngx_array_t *variables; /* array of ngx_http_perl_var_t */ 39 | 40 | #if (NGX_HTTP_SSI) 41 | ngx_http_ssi_ctx_t *ssi; 42 | #endif 43 | } ngx_http_perl_ctx_t; 44 | 45 | 46 | typedef struct { 47 | ngx_uint_t hash; 48 | ngx_str_t name; 49 | ngx_str_t value; 50 | } ngx_http_perl_var_t; 51 | 52 | 53 | extern ngx_module_t ngx_http_perl_module; 54 | 55 | 56 | /* 57 | * workaround for "unused variable `Perl___notused'" warning 58 | * when building with perl 5.6.1 59 | */ 60 | #ifndef PERL_IMPLICIT_CONTEXT 61 | #undef dTHXa 62 | #define dTHXa(a) 63 | #endif 64 | 65 | 66 | extern void boot_DynaLoader(pTHX_ CV* cv); 67 | 68 | 69 | void ngx_http_perl_handle_request(ngx_http_request_t *r); 70 | void ngx_http_perl_sleep_handler(ngx_http_request_t *r); 71 | 72 | 73 | #endif /* _NGX_HTTP_PERL_MODULE_H_INCLUDED_ */ 74 | -------------------------------------------------------------------------------- /src/http/modules/perl/typemap: -------------------------------------------------------------------------------- 1 | TYPEMAP 2 | 3 | nginx T_PTROBJ 4 | -------------------------------------------------------------------------------- /src/http/v2/ngx_http_v2_encode.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | * Copyright (C) Valentin V. Bartenev 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | static u_char *ngx_http_v2_write_int(u_char *pos, ngx_uint_t prefix, 14 | ngx_uint_t value); 15 | 16 | 17 | u_char * 18 | ngx_http_v2_string_encode(u_char *dst, u_char *src, size_t len, u_char *tmp, 19 | ngx_uint_t lower) 20 | { 21 | size_t hlen; 22 | 23 | hlen = ngx_http_huff_encode(src, len, tmp, lower); 24 | 25 | if (hlen > 0) { 26 | *dst = NGX_HTTP_V2_ENCODE_HUFF; 27 | dst = ngx_http_v2_write_int(dst, ngx_http_v2_prefix(7), hlen); 28 | return ngx_cpymem(dst, tmp, hlen); 29 | } 30 | 31 | *dst = NGX_HTTP_V2_ENCODE_RAW; 32 | dst = ngx_http_v2_write_int(dst, ngx_http_v2_prefix(7), len); 33 | 34 | if (lower) { 35 | ngx_strlow(dst, src, len); 36 | return dst + len; 37 | } 38 | 39 | return ngx_cpymem(dst, src, len); 40 | } 41 | 42 | 43 | static u_char * 44 | ngx_http_v2_write_int(u_char *pos, ngx_uint_t prefix, ngx_uint_t value) 45 | { 46 | if (value < prefix) { 47 | *pos++ |= value; 48 | return pos; 49 | } 50 | 51 | *pos++ |= prefix; 52 | value -= prefix; 53 | 54 | while (value >= 128) { 55 | *pos++ = value % 128 + 128; 56 | value /= 128; 57 | } 58 | 59 | *pos++ = (u_char) value; 60 | 61 | return pos; 62 | } 63 | -------------------------------------------------------------------------------- /src/http/v2/ngx_http_v2_module.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | * Copyright (C) Valentin V. Bartenev 5 | */ 6 | 7 | 8 | #ifndef _NGX_HTTP_V2_MODULE_H_INCLUDED_ 9 | #define _NGX_HTTP_V2_MODULE_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | typedef struct { 18 | size_t recv_buffer_size; 19 | u_char *recv_buffer; 20 | } ngx_http_v2_main_conf_t; 21 | 22 | 23 | typedef struct { 24 | size_t chunk_size; 25 | } ngx_http_v2_loc_conf_t; 26 | 27 | 28 | #endif /* _NGX_HTTP_V2_MODULE_H_INCLUDED_ */ 29 | -------------------------------------------------------------------------------- /src/http/v3/ngx_http_v3_encode.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Roman Arutyunyan 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_HTTP_V3_ENCODE_H_INCLUDED_ 9 | #define _NGX_HTTP_V3_ENCODE_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | uintptr_t ngx_http_v3_encode_varlen_int(u_char *p, uint64_t value); 18 | uintptr_t ngx_http_v3_encode_prefix_int(u_char *p, uint64_t value, 19 | ngx_uint_t prefix); 20 | 21 | uintptr_t ngx_http_v3_encode_field_section_prefix(u_char *p, 22 | ngx_uint_t insert_count, ngx_uint_t sign, ngx_uint_t delta_base); 23 | uintptr_t ngx_http_v3_encode_field_ri(u_char *p, ngx_uint_t dynamic, 24 | ngx_uint_t index); 25 | uintptr_t ngx_http_v3_encode_field_lri(u_char *p, ngx_uint_t dynamic, 26 | ngx_uint_t index, u_char *data, size_t len); 27 | uintptr_t ngx_http_v3_encode_field_l(u_char *p, ngx_str_t *name, 28 | ngx_str_t *value); 29 | uintptr_t ngx_http_v3_encode_field_pbi(u_char *p, ngx_uint_t index); 30 | uintptr_t ngx_http_v3_encode_field_lpbi(u_char *p, ngx_uint_t index, 31 | u_char *data, size_t len); 32 | 33 | 34 | #endif /* _NGX_HTTP_V3_ENCODE_H_INCLUDED_ */ 35 | -------------------------------------------------------------------------------- /src/http/v3/ngx_http_v3_uni.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Roman Arutyunyan 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_HTTP_V3_UNI_H_INCLUDED_ 9 | #define _NGX_HTTP_V3_UNI_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | void ngx_http_v3_init_uni_stream(ngx_connection_t *c); 18 | ngx_int_t ngx_http_v3_register_uni_stream(ngx_connection_t *c, uint64_t type); 19 | 20 | ngx_int_t ngx_http_v3_cancel_stream(ngx_connection_t *c, ngx_uint_t stream_id); 21 | 22 | ngx_connection_t *ngx_http_v3_get_uni_stream(ngx_connection_t *c, 23 | ngx_uint_t type); 24 | ngx_int_t ngx_http_v3_send_settings(ngx_connection_t *c); 25 | ngx_int_t ngx_http_v3_send_goaway(ngx_connection_t *c, uint64_t id); 26 | ngx_int_t ngx_http_v3_send_ack_section(ngx_connection_t *c, 27 | ngx_uint_t stream_id); 28 | ngx_int_t ngx_http_v3_send_cancel_stream(ngx_connection_t *c, 29 | ngx_uint_t stream_id); 30 | ngx_int_t ngx_http_v3_send_inc_insert_count(ngx_connection_t *c, 31 | ngx_uint_t inc); 32 | 33 | 34 | #endif /* _NGX_HTTP_V3_UNI_H_INCLUDED_ */ 35 | -------------------------------------------------------------------------------- /src/mail/ngx_mail_imap_module.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_MAIL_IMAP_MODULE_H_INCLUDED_ 9 | #define _NGX_MAIL_IMAP_MODULE_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | typedef struct { 18 | size_t client_buffer_size; 19 | 20 | ngx_str_t capability; 21 | ngx_str_t starttls_capability; 22 | ngx_str_t starttls_only_capability; 23 | 24 | ngx_uint_t auth_methods; 25 | 26 | ngx_array_t capabilities; 27 | } ngx_mail_imap_srv_conf_t; 28 | 29 | 30 | void ngx_mail_imap_init_session(ngx_mail_session_t *s, ngx_connection_t *c); 31 | void ngx_mail_imap_init_protocol(ngx_event_t *rev); 32 | void ngx_mail_imap_auth_state(ngx_event_t *rev); 33 | ngx_int_t ngx_mail_imap_parse_command(ngx_mail_session_t *s); 34 | 35 | 36 | extern ngx_module_t ngx_mail_imap_module; 37 | 38 | 39 | #endif /* _NGX_MAIL_IMAP_MODULE_H_INCLUDED_ */ 40 | -------------------------------------------------------------------------------- /src/mail/ngx_mail_pop3_module.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_MAIL_POP3_MODULE_H_INCLUDED_ 9 | #define _NGX_MAIL_POP3_MODULE_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | typedef struct { 18 | ngx_str_t capability; 19 | ngx_str_t starttls_capability; 20 | ngx_str_t starttls_only_capability; 21 | ngx_str_t auth_capability; 22 | 23 | ngx_uint_t auth_methods; 24 | 25 | ngx_array_t capabilities; 26 | } ngx_mail_pop3_srv_conf_t; 27 | 28 | 29 | void ngx_mail_pop3_init_session(ngx_mail_session_t *s, ngx_connection_t *c); 30 | void ngx_mail_pop3_init_protocol(ngx_event_t *rev); 31 | void ngx_mail_pop3_auth_state(ngx_event_t *rev); 32 | ngx_int_t ngx_mail_pop3_parse_command(ngx_mail_session_t *s); 33 | 34 | 35 | extern ngx_module_t ngx_mail_pop3_module; 36 | 37 | 38 | #endif /* _NGX_MAIL_POP3_MODULE_H_INCLUDED_ */ 39 | -------------------------------------------------------------------------------- /src/mail/ngx_mail_smtp_module.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_MAIL_SMTP_MODULE_H_INCLUDED_ 9 | #define _NGX_MAIL_SMTP_MODULE_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | typedef struct { 19 | ngx_msec_t greeting_delay; 20 | 21 | size_t client_buffer_size; 22 | 23 | ngx_str_t capability; 24 | ngx_str_t starttls_capability; 25 | ngx_str_t starttls_only_capability; 26 | 27 | ngx_str_t server_name; 28 | ngx_str_t greeting; 29 | 30 | ngx_uint_t auth_methods; 31 | 32 | ngx_array_t capabilities; 33 | } ngx_mail_smtp_srv_conf_t; 34 | 35 | 36 | void ngx_mail_smtp_init_session(ngx_mail_session_t *s, ngx_connection_t *c); 37 | void ngx_mail_smtp_init_protocol(ngx_event_t *rev); 38 | void ngx_mail_smtp_auth_state(ngx_event_t *rev); 39 | ngx_int_t ngx_mail_smtp_parse_command(ngx_mail_session_t *s); 40 | 41 | 42 | extern ngx_module_t ngx_mail_smtp_module; 43 | 44 | 45 | #endif /* _NGX_MAIL_SMTP_MODULE_H_INCLUDED_ */ 46 | -------------------------------------------------------------------------------- /src/mail/ngx_mail_ssl_module.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | * Copyright (C) Intel, Inc. 6 | */ 7 | 8 | 9 | #ifndef _NGX_MAIL_SSL_H_INCLUDED_ 10 | #define _NGX_MAIL_SSL_H_INCLUDED_ 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | #define NGX_MAIL_STARTTLS_OFF 0 19 | #define NGX_MAIL_STARTTLS_ON 1 20 | #define NGX_MAIL_STARTTLS_ONLY 2 21 | 22 | 23 | typedef struct { 24 | ngx_flag_t asynch; 25 | ngx_flag_t prefer_server_ciphers; 26 | 27 | ngx_ssl_t ssl; 28 | 29 | ngx_uint_t starttls; 30 | ngx_uint_t listen; 31 | ngx_uint_t protocols; 32 | 33 | ngx_uint_t verify; 34 | ngx_uint_t verify_depth; 35 | 36 | ssize_t builtin_session_cache; 37 | 38 | time_t session_timeout; 39 | 40 | ngx_array_t *certificates; 41 | ngx_array_t *certificate_keys; 42 | 43 | ngx_str_t dhparam; 44 | ngx_str_t ecdh_curve; 45 | ngx_str_t client_certificate; 46 | ngx_str_t trusted_certificate; 47 | ngx_str_t crl; 48 | 49 | ngx_str_t ciphers; 50 | 51 | ngx_array_t *passwords; 52 | ngx_array_t *conf_commands; 53 | 54 | ngx_shm_zone_t *shm_zone; 55 | 56 | ngx_flag_t session_tickets; 57 | ngx_array_t *session_ticket_keys; 58 | 59 | u_char *file; 60 | ngx_uint_t line; 61 | } ngx_mail_ssl_conf_t; 62 | 63 | 64 | extern ngx_module_t ngx_mail_ssl_module; 65 | 66 | 67 | #endif /* _NGX_MAIL_SSL_H_INCLUDED_ */ 68 | -------------------------------------------------------------------------------- /src/misc/ngx_cpp_test_module.cpp: -------------------------------------------------------------------------------- 1 | 2 | // stub module to test header files' C++ compatibility 3 | 4 | extern "C" { 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | } 20 | 21 | // nginx header files should go before other, because they define 64-bit off_t 22 | // #include 23 | 24 | 25 | void ngx_cpp_test_handler(void *data); 26 | 27 | void 28 | ngx_cpp_test_handler(void *data) 29 | { 30 | return; 31 | } 32 | -------------------------------------------------------------------------------- /src/os/unix/ngx_alloc.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_ALLOC_H_INCLUDED_ 9 | #define _NGX_ALLOC_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | void *ngx_alloc(size_t size, ngx_log_t *log); 17 | void *ngx_calloc(size_t size, ngx_log_t *log); 18 | 19 | #define ngx_free free 20 | 21 | 22 | /* 23 | * Linux has memalign() or posix_memalign() 24 | * Solaris has memalign() 25 | * FreeBSD 7.0 has posix_memalign(), besides, early version's malloc() 26 | * aligns allocations bigger than page size at the page boundary 27 | */ 28 | 29 | #if (NGX_HAVE_POSIX_MEMALIGN || NGX_HAVE_MEMALIGN) 30 | 31 | void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log); 32 | 33 | #else 34 | 35 | #define ngx_memalign(alignment, size, log) ngx_alloc(size, log) 36 | 37 | #endif 38 | 39 | 40 | extern ngx_uint_t ngx_pagesize; 41 | extern ngx_uint_t ngx_pagesize_shift; 42 | extern ngx_uint_t ngx_cacheline_size; 43 | 44 | 45 | #endif /* _NGX_ALLOC_H_INCLUDED_ */ 46 | -------------------------------------------------------------------------------- /src/os/unix/ngx_channel.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_CHANNEL_H_INCLUDED_ 9 | #define _NGX_CHANNEL_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | typedef struct { 18 | ngx_uint_t command; 19 | ngx_pid_t pid; 20 | ngx_int_t slot; 21 | ngx_fd_t fd; 22 | } ngx_channel_t; 23 | 24 | 25 | ngx_int_t ngx_write_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size, 26 | ngx_log_t *log); 27 | ngx_int_t ngx_read_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size, 28 | ngx_log_t *log); 29 | ngx_int_t ngx_add_channel_event(ngx_cycle_t *cycle, ngx_fd_t fd, 30 | ngx_int_t event, ngx_event_handler_pt handler); 31 | void ngx_close_channel(ngx_fd_t *fd, ngx_log_t *log); 32 | 33 | 34 | #endif /* _NGX_CHANNEL_H_INCLUDED_ */ 35 | -------------------------------------------------------------------------------- /src/os/unix/ngx_daemon.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | ngx_int_t 13 | ngx_daemon(ngx_log_t *log) 14 | { 15 | int fd; 16 | 17 | switch (fork()) { 18 | case -1: 19 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "fork() failed"); 20 | return NGX_ERROR; 21 | 22 | case 0: 23 | break; 24 | 25 | default: 26 | exit(0); 27 | } 28 | 29 | ngx_parent = ngx_pid; 30 | ngx_pid = ngx_getpid(); 31 | 32 | if (setsid() == -1) { 33 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "setsid() failed"); 34 | return NGX_ERROR; 35 | } 36 | 37 | umask(0); 38 | 39 | fd = open("/dev/null", O_RDWR); 40 | if (fd == -1) { 41 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, 42 | "open(\"/dev/null\") failed"); 43 | return NGX_ERROR; 44 | } 45 | 46 | if (dup2(fd, STDIN_FILENO) == -1) { 47 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDIN) failed"); 48 | return NGX_ERROR; 49 | } 50 | 51 | if (dup2(fd, STDOUT_FILENO) == -1) { 52 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDOUT) failed"); 53 | return NGX_ERROR; 54 | } 55 | 56 | #if 0 57 | if (dup2(fd, STDERR_FILENO) == -1) { 58 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDERR) failed"); 59 | return NGX_ERROR; 60 | } 61 | #endif 62 | 63 | if (fd > STDERR_FILENO) { 64 | if (close(fd) == -1) { 65 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "close() failed"); 66 | return NGX_ERROR; 67 | } 68 | } 69 | 70 | return NGX_OK; 71 | } 72 | -------------------------------------------------------------------------------- /src/os/unix/ngx_darwin.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_DARWIN_H_INCLUDED_ 9 | #define _NGX_DARWIN_H_INCLUDED_ 10 | 11 | 12 | void ngx_debug_init(void); 13 | ngx_chain_t *ngx_darwin_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, 14 | off_t limit); 15 | 16 | extern int ngx_darwin_kern_osreldate; 17 | extern int ngx_darwin_hw_ncpu; 18 | extern u_long ngx_darwin_net_inet_tcp_sendspace; 19 | 20 | extern ngx_uint_t ngx_debug_malloc; 21 | 22 | 23 | #endif /* _NGX_DARWIN_H_INCLUDED_ */ 24 | -------------------------------------------------------------------------------- /src/os/unix/ngx_dlopen.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Maxim Dounin 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | #if (NGX_HAVE_DLOPEN) 13 | 14 | char * 15 | ngx_dlerror(void) 16 | { 17 | char *err; 18 | 19 | err = (char *) dlerror(); 20 | 21 | if (err == NULL) { 22 | return ""; 23 | } 24 | 25 | return err; 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/os/unix/ngx_dlopen.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Maxim Dounin 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_DLOPEN_H_INCLUDED_ 9 | #define _NGX_DLOPEN_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | #define ngx_dlopen(path) dlopen((char *) path, RTLD_NOW | RTLD_GLOBAL) 17 | #define ngx_dlopen_n "dlopen()" 18 | 19 | #define ngx_dlsym(handle, symbol) dlsym(handle, symbol) 20 | #define ngx_dlsym_n "dlsym()" 21 | 22 | #define ngx_dlclose(handle) dlclose(handle) 23 | #define ngx_dlclose_n "dlclose()" 24 | 25 | 26 | #if (NGX_HAVE_DLOPEN) 27 | char *ngx_dlerror(void); 28 | #endif 29 | 30 | 31 | #endif /* _NGX_DLOPEN_H_INCLUDED_ */ 32 | -------------------------------------------------------------------------------- /src/os/unix/ngx_freebsd.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_FREEBSD_H_INCLUDED_ 9 | #define _NGX_FREEBSD_H_INCLUDED_ 10 | 11 | 12 | void ngx_debug_init(void); 13 | ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, 14 | off_t limit); 15 | 16 | extern int ngx_freebsd_kern_osreldate; 17 | extern int ngx_freebsd_hw_ncpu; 18 | extern u_long ngx_freebsd_net_inet_tcp_sendspace; 19 | 20 | extern ngx_uint_t ngx_freebsd_sendfile_nbytes_bug; 21 | extern ngx_uint_t ngx_freebsd_use_tcp_nopush; 22 | extern ngx_uint_t ngx_debug_malloc; 23 | 24 | 25 | #endif /* _NGX_FREEBSD_H_INCLUDED_ */ 26 | -------------------------------------------------------------------------------- /src/os/unix/ngx_gcc_atomic_amd64.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #if (NGX_SMP) 9 | #define NGX_SMP_LOCK "lock;" 10 | #else 11 | #define NGX_SMP_LOCK 12 | #endif 13 | 14 | 15 | /* 16 | * "cmpxchgq r, [m]": 17 | * 18 | * if (rax == [m]) { 19 | * zf = 1; 20 | * [m] = r; 21 | * } else { 22 | * zf = 0; 23 | * rax = [m]; 24 | * } 25 | * 26 | * 27 | * The "r" is any register, %rax (%r0) - %r16. 28 | * The "=a" and "a" are the %rax register. 29 | * Although we can return result in any register, we use "a" because it is 30 | * used in cmpxchgq anyway. The result is actually in %al but not in $rax, 31 | * however as the code is inlined gcc can test %al as well as %rax. 32 | * 33 | * The "cc" means that flags were changed. 34 | */ 35 | 36 | static ngx_inline ngx_atomic_uint_t 37 | ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old, 38 | ngx_atomic_uint_t set) 39 | { 40 | u_char res; 41 | 42 | __asm__ volatile ( 43 | 44 | NGX_SMP_LOCK 45 | " cmpxchgq %3, %1; " 46 | " sete %0; " 47 | 48 | : "=a" (res) : "m" (*lock), "a" (old), "r" (set) : "cc", "memory"); 49 | 50 | return res; 51 | } 52 | 53 | 54 | /* 55 | * "xaddq r, [m]": 56 | * 57 | * temp = [m]; 58 | * [m] += r; 59 | * r = temp; 60 | * 61 | * 62 | * The "+r" is any register, %rax (%r0) - %r16. 63 | * The "cc" means that flags were changed. 64 | */ 65 | 66 | static ngx_inline ngx_atomic_int_t 67 | ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) 68 | { 69 | __asm__ volatile ( 70 | 71 | NGX_SMP_LOCK 72 | " xaddq %0, %1; " 73 | 74 | : "+r" (add) : "m" (*value) : "cc", "memory"); 75 | 76 | return add; 77 | } 78 | 79 | 80 | #define ngx_memory_barrier() __asm__ volatile ("" ::: "memory") 81 | 82 | #define ngx_cpu_pause() __asm__ ("pause") 83 | -------------------------------------------------------------------------------- /src/os/unix/ngx_gcc_atomic_sparc64.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | /* 9 | * "casa [r1] 0x80, r2, r0" and 10 | * "casxa [r1] 0x80, r2, r0" do the following: 11 | * 12 | * if ([r1] == r2) { 13 | * swap(r0, [r1]); 14 | * } else { 15 | * r0 = [r1]; 16 | * } 17 | * 18 | * so "r0 == r2" means that the operation was successful. 19 | * 20 | * 21 | * The "r" means the general register. 22 | * The "+r" means the general register used for both input and output. 23 | */ 24 | 25 | 26 | #if (NGX_PTR_SIZE == 4) 27 | #define NGX_CASA "casa" 28 | #else 29 | #define NGX_CASA "casxa" 30 | #endif 31 | 32 | 33 | static ngx_inline ngx_atomic_uint_t 34 | ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old, 35 | ngx_atomic_uint_t set) 36 | { 37 | __asm__ volatile ( 38 | 39 | NGX_CASA " [%1] 0x80, %2, %0" 40 | 41 | : "+r" (set) : "r" (lock), "r" (old) : "memory"); 42 | 43 | return (set == old); 44 | } 45 | 46 | 47 | static ngx_inline ngx_atomic_int_t 48 | ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) 49 | { 50 | ngx_atomic_uint_t old, res; 51 | 52 | old = *value; 53 | 54 | for ( ;; ) { 55 | 56 | res = old + add; 57 | 58 | __asm__ volatile ( 59 | 60 | NGX_CASA " [%1] 0x80, %2, %0" 61 | 62 | : "+r" (res) : "r" (value), "r" (old) : "memory"); 63 | 64 | if (res == old) { 65 | return res; 66 | } 67 | 68 | old = res; 69 | } 70 | } 71 | 72 | 73 | #if (NGX_SMP) 74 | #define ngx_memory_barrier() \ 75 | __asm__ volatile ( \ 76 | "membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad" \ 77 | ::: "memory") 78 | #else 79 | #define ngx_memory_barrier() __asm__ volatile ("" ::: "memory") 80 | #endif 81 | 82 | #define ngx_cpu_pause() 83 | -------------------------------------------------------------------------------- /src/os/unix/ngx_linux.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_LINUX_H_INCLUDED_ 9 | #define _NGX_LINUX_H_INCLUDED_ 10 | 11 | 12 | ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, 13 | off_t limit); 14 | 15 | 16 | #endif /* _NGX_LINUX_H_INCLUDED_ */ 17 | -------------------------------------------------------------------------------- /src/os/unix/ngx_linux_init.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | u_char ngx_linux_kern_ostype[50]; 13 | u_char ngx_linux_kern_osrelease[50]; 14 | 15 | 16 | static ngx_os_io_t ngx_linux_io = { 17 | ngx_unix_recv, 18 | ngx_readv_chain, 19 | ngx_udp_unix_recv, 20 | ngx_unix_send, 21 | ngx_udp_unix_send, 22 | ngx_udp_unix_sendmsg_chain, 23 | #if (NGX_HAVE_SENDFILE) 24 | ngx_linux_sendfile_chain, 25 | NGX_IO_SENDFILE 26 | #else 27 | ngx_writev_chain, 28 | 0 29 | #endif 30 | }; 31 | 32 | 33 | ngx_int_t 34 | ngx_os_specific_init(ngx_log_t *log) 35 | { 36 | struct utsname u; 37 | 38 | if (uname(&u) == -1) { 39 | ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "uname() failed"); 40 | return NGX_ERROR; 41 | } 42 | 43 | (void) ngx_cpystrn(ngx_linux_kern_ostype, (u_char *) u.sysname, 44 | sizeof(ngx_linux_kern_ostype)); 45 | 46 | (void) ngx_cpystrn(ngx_linux_kern_osrelease, (u_char *) u.release, 47 | sizeof(ngx_linux_kern_osrelease)); 48 | 49 | ngx_os_io = ngx_linux_io; 50 | 51 | return NGX_OK; 52 | } 53 | 54 | 55 | void 56 | ngx_os_specific_status(ngx_log_t *log) 57 | { 58 | ngx_log_error(NGX_LOG_NOTICE, log, 0, "OS: %s %s", 59 | ngx_linux_kern_ostype, ngx_linux_kern_osrelease); 60 | } 61 | -------------------------------------------------------------------------------- /src/os/unix/ngx_process_cycle.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_PROCESS_CYCLE_H_INCLUDED_ 9 | #define _NGX_PROCESS_CYCLE_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | #define NGX_CMD_OPEN_CHANNEL 1 17 | #define NGX_CMD_CLOSE_CHANNEL 2 18 | #define NGX_CMD_QUIT 3 19 | #define NGX_CMD_TERMINATE 4 20 | #define NGX_CMD_REOPEN 5 21 | 22 | 23 | #define NGX_PROCESS_SINGLE 0 24 | #define NGX_PROCESS_MASTER 1 25 | #define NGX_PROCESS_SIGNALLER 2 26 | #define NGX_PROCESS_WORKER 3 27 | #define NGX_PROCESS_HELPER 4 28 | 29 | 30 | typedef struct { 31 | ngx_event_handler_pt handler; 32 | char *name; 33 | ngx_msec_t delay; 34 | } ngx_cache_manager_ctx_t; 35 | 36 | 37 | void ngx_master_process_cycle(ngx_cycle_t *cycle); 38 | void ngx_single_process_cycle(ngx_cycle_t *cycle); 39 | 40 | 41 | extern ngx_uint_t ngx_process; 42 | extern ngx_uint_t ngx_worker; 43 | extern ngx_pid_t ngx_pid; 44 | extern ngx_pid_t ngx_new_binary; 45 | extern ngx_uint_t ngx_inherited; 46 | extern ngx_uint_t ngx_daemonized; 47 | extern ngx_uint_t ngx_exiting; 48 | 49 | extern sig_atomic_t ngx_reap; 50 | extern sig_atomic_t ngx_sigio; 51 | extern sig_atomic_t ngx_sigalrm; 52 | extern sig_atomic_t ngx_quit; 53 | extern sig_atomic_t ngx_debug_quit; 54 | extern sig_atomic_t ngx_terminate; 55 | extern sig_atomic_t ngx_noaccept; 56 | extern sig_atomic_t ngx_reconfigure; 57 | extern sig_atomic_t ngx_reopen; 58 | extern sig_atomic_t ngx_change_binary; 59 | 60 | 61 | #endif /* _NGX_PROCESS_CYCLE_H_INCLUDED_ */ 62 | -------------------------------------------------------------------------------- /src/os/unix/ngx_send.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | ssize_t 14 | ngx_unix_send(ngx_connection_t *c, u_char *buf, size_t size) 15 | { 16 | ssize_t n; 17 | ngx_err_t err; 18 | ngx_event_t *wev; 19 | 20 | wev = c->write; 21 | 22 | #if (NGX_HAVE_KQUEUE) 23 | 24 | if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && wev->pending_eof) { 25 | (void) ngx_connection_error(c, wev->kq_errno, 26 | "kevent() reported about an closed connection"); 27 | wev->error = 1; 28 | return NGX_ERROR; 29 | } 30 | 31 | #endif 32 | 33 | for ( ;; ) { 34 | n = send(c->fd, buf, size, 0); 35 | 36 | ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, 37 | "send: fd:%d %z of %uz", c->fd, n, size); 38 | 39 | if (n > 0) { 40 | if (n < (ssize_t) size) { 41 | wev->ready = 0; 42 | } 43 | 44 | c->sent += n; 45 | 46 | return n; 47 | } 48 | 49 | err = ngx_socket_errno; 50 | 51 | if (n == 0) { 52 | ngx_log_error(NGX_LOG_ALERT, c->log, err, "send() returned zero"); 53 | wev->ready = 0; 54 | return n; 55 | } 56 | 57 | if (err == NGX_EAGAIN || err == NGX_EINTR) { 58 | wev->ready = 0; 59 | 60 | ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, 61 | "send() not ready"); 62 | 63 | if (err == NGX_EAGAIN) { 64 | return NGX_AGAIN; 65 | } 66 | 67 | } else { 68 | wev->error = 1; 69 | (void) ngx_connection_error(c, err, "send() failed"); 70 | return NGX_ERROR; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/os/unix/ngx_setaffinity.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | 7 | #include 8 | #include 9 | 10 | 11 | #if (NGX_HAVE_CPUSET_SETAFFINITY) 12 | 13 | void 14 | ngx_setaffinity(ngx_cpuset_t *cpu_affinity, ngx_log_t *log) 15 | { 16 | ngx_uint_t i; 17 | 18 | for (i = 0; i < CPU_SETSIZE; i++) { 19 | if (CPU_ISSET(i, cpu_affinity)) { 20 | ngx_log_error(NGX_LOG_NOTICE, log, 0, 21 | "cpuset_setaffinity(): using cpu #%ui", i); 22 | } 23 | } 24 | 25 | if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, 26 | sizeof(cpuset_t), cpu_affinity) == -1) 27 | { 28 | ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, 29 | "cpuset_setaffinity() failed"); 30 | } 31 | } 32 | 33 | #elif (NGX_HAVE_SCHED_SETAFFINITY) 34 | 35 | void 36 | ngx_setaffinity(ngx_cpuset_t *cpu_affinity, ngx_log_t *log) 37 | { 38 | ngx_uint_t i; 39 | 40 | for (i = 0; i < CPU_SETSIZE; i++) { 41 | if (CPU_ISSET(i, cpu_affinity)) { 42 | ngx_log_error(NGX_LOG_NOTICE, log, 0, 43 | "sched_setaffinity(): using cpu #%ui", i); 44 | } 45 | } 46 | 47 | if (sched_setaffinity(0, sizeof(cpu_set_t), cpu_affinity) == -1) { 48 | ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, 49 | "sched_setaffinity() failed"); 50 | } 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/os/unix/ngx_setaffinity.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | #ifndef _NGX_SETAFFINITY_H_INCLUDED_ 7 | #define _NGX_SETAFFINITY_H_INCLUDED_ 8 | 9 | 10 | #if (NGX_HAVE_SCHED_SETAFFINITY || NGX_HAVE_CPUSET_SETAFFINITY) 11 | 12 | #define NGX_HAVE_CPU_AFFINITY 1 13 | 14 | #if (NGX_HAVE_SCHED_SETAFFINITY) 15 | 16 | typedef cpu_set_t ngx_cpuset_t; 17 | 18 | #elif (NGX_HAVE_CPUSET_SETAFFINITY) 19 | 20 | #include 21 | 22 | typedef cpuset_t ngx_cpuset_t; 23 | 24 | #endif 25 | 26 | void ngx_setaffinity(ngx_cpuset_t *cpu_affinity, ngx_log_t *log); 27 | 28 | #else 29 | 30 | #define ngx_setaffinity(cpu_affinity, log) 31 | 32 | typedef uint64_t ngx_cpuset_t; 33 | 34 | #endif 35 | 36 | 37 | #endif /* _NGX_SETAFFINITY_H_INCLUDED_ */ 38 | -------------------------------------------------------------------------------- /src/os/unix/ngx_setproctitle.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_SETPROCTITLE_H_INCLUDED_ 9 | #define _NGX_SETPROCTITLE_H_INCLUDED_ 10 | 11 | 12 | #if (NGX_HAVE_SETPROCTITLE) 13 | 14 | /* FreeBSD, NetBSD, OpenBSD */ 15 | 16 | #define ngx_init_setproctitle(log) NGX_OK 17 | #define ngx_setproctitle(title) setproctitle("%s", title) 18 | 19 | 20 | #else /* !NGX_HAVE_SETPROCTITLE */ 21 | 22 | #if !defined NGX_SETPROCTITLE_USES_ENV 23 | 24 | #if (NGX_SOLARIS) 25 | 26 | #define NGX_SETPROCTITLE_USES_ENV 1 27 | #define NGX_SETPROCTITLE_PAD ' ' 28 | 29 | ngx_int_t ngx_init_setproctitle(ngx_log_t *log); 30 | void ngx_setproctitle(char *title); 31 | 32 | #elif (NGX_LINUX) || (NGX_DARWIN) 33 | 34 | #define NGX_SETPROCTITLE_USES_ENV 1 35 | #define NGX_SETPROCTITLE_PAD '\0' 36 | 37 | ngx_int_t ngx_init_setproctitle(ngx_log_t *log); 38 | void ngx_setproctitle(char *title); 39 | 40 | #else 41 | 42 | #define ngx_init_setproctitle(log) NGX_OK 43 | #define ngx_setproctitle(title) 44 | 45 | #endif /* OSes */ 46 | 47 | #endif /* NGX_SETPROCTITLE_USES_ENV */ 48 | 49 | #endif /* NGX_HAVE_SETPROCTITLE */ 50 | 51 | 52 | #endif /* _NGX_SETPROCTITLE_H_INCLUDED_ */ 53 | -------------------------------------------------------------------------------- /src/os/unix/ngx_shmem.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_SHMEM_H_INCLUDED_ 9 | #define _NGX_SHMEM_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef struct { 17 | u_char *addr; 18 | size_t size; 19 | ngx_str_t name; 20 | ngx_log_t *log; 21 | ngx_uint_t exists; /* unsigned exists:1; */ 22 | } ngx_shm_t; 23 | 24 | 25 | ngx_int_t ngx_shm_alloc(ngx_shm_t *shm); 26 | void ngx_shm_free(ngx_shm_t *shm); 27 | 28 | 29 | #endif /* _NGX_SHMEM_H_INCLUDED_ */ 30 | -------------------------------------------------------------------------------- /src/os/unix/ngx_socket.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_SOCKET_H_INCLUDED_ 9 | #define _NGX_SOCKET_H_INCLUDED_ 10 | 11 | 12 | #include 13 | 14 | 15 | #define NGX_WRITE_SHUTDOWN SHUT_WR 16 | #define NGX_READ_SHUTDOWN SHUT_RD 17 | #define NGX_RDWR_SHUTDOWN SHUT_RDWR 18 | 19 | typedef int ngx_socket_t; 20 | 21 | #define ngx_socket socket 22 | #define ngx_socket_n "socket()" 23 | 24 | 25 | #if (NGX_HAVE_FIONBIO) 26 | 27 | int ngx_nonblocking(ngx_socket_t s); 28 | int ngx_blocking(ngx_socket_t s); 29 | 30 | #define ngx_nonblocking_n "ioctl(FIONBIO)" 31 | #define ngx_blocking_n "ioctl(!FIONBIO)" 32 | 33 | #else 34 | 35 | #define ngx_nonblocking(s) fcntl(s, F_SETFL, fcntl(s, F_GETFL) | O_NONBLOCK) 36 | #define ngx_nonblocking_n "fcntl(O_NONBLOCK)" 37 | 38 | #define ngx_blocking(s) fcntl(s, F_SETFL, fcntl(s, F_GETFL) & ~O_NONBLOCK) 39 | #define ngx_blocking_n "fcntl(!O_NONBLOCK)" 40 | 41 | #endif 42 | 43 | #if (NGX_HAVE_FIONREAD) 44 | 45 | #define ngx_socket_nread(s, n) ioctl(s, FIONREAD, n) 46 | #define ngx_socket_nread_n "ioctl(FIONREAD)" 47 | 48 | #endif 49 | 50 | int ngx_tcp_nopush(ngx_socket_t s); 51 | int ngx_tcp_push(ngx_socket_t s); 52 | 53 | #if (NGX_LINUX) 54 | 55 | #define ngx_tcp_nopush_n "setsockopt(TCP_CORK)" 56 | #define ngx_tcp_push_n "setsockopt(!TCP_CORK)" 57 | 58 | #else 59 | 60 | #define ngx_tcp_nopush_n "setsockopt(TCP_NOPUSH)" 61 | #define ngx_tcp_push_n "setsockopt(!TCP_NOPUSH)" 62 | 63 | #endif 64 | 65 | 66 | #define ngx_shutdown_socket shutdown 67 | #define ngx_shutdown_socket_n "shutdown()" 68 | 69 | #define ngx_close_socket close 70 | #define ngx_close_socket_n "close() socket" 71 | 72 | 73 | #endif /* _NGX_SOCKET_H_INCLUDED_ */ 74 | -------------------------------------------------------------------------------- /src/os/unix/ngx_solaris.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_SOLARIS_H_INCLUDED_ 9 | #define _NGX_SOLARIS_H_INCLUDED_ 10 | 11 | 12 | ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in, 13 | off_t limit); 14 | 15 | 16 | #endif /* _NGX_SOLARIS_H_INCLUDED_ */ 17 | -------------------------------------------------------------------------------- /src/os/unix/ngx_solaris_init.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | char ngx_solaris_sysname[20]; 13 | char ngx_solaris_release[10]; 14 | char ngx_solaris_version[50]; 15 | 16 | 17 | static ngx_os_io_t ngx_solaris_io = { 18 | ngx_unix_recv, 19 | ngx_readv_chain, 20 | ngx_udp_unix_recv, 21 | ngx_unix_send, 22 | ngx_udp_unix_send, 23 | ngx_udp_unix_sendmsg_chain, 24 | #if (NGX_HAVE_SENDFILE) 25 | ngx_solaris_sendfilev_chain, 26 | NGX_IO_SENDFILE 27 | #else 28 | ngx_writev_chain, 29 | 0 30 | #endif 31 | }; 32 | 33 | 34 | ngx_int_t 35 | ngx_os_specific_init(ngx_log_t *log) 36 | { 37 | if (sysinfo(SI_SYSNAME, ngx_solaris_sysname, sizeof(ngx_solaris_sysname)) 38 | == -1) 39 | { 40 | ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, 41 | "sysinfo(SI_SYSNAME) failed"); 42 | return NGX_ERROR; 43 | } 44 | 45 | if (sysinfo(SI_RELEASE, ngx_solaris_release, sizeof(ngx_solaris_release)) 46 | == -1) 47 | { 48 | ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, 49 | "sysinfo(SI_RELEASE) failed"); 50 | return NGX_ERROR; 51 | } 52 | 53 | if (sysinfo(SI_VERSION, ngx_solaris_version, sizeof(ngx_solaris_version)) 54 | == -1) 55 | { 56 | ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, 57 | "sysinfo(SI_SYSNAME) failed"); 58 | return NGX_ERROR; 59 | } 60 | 61 | 62 | ngx_os_io = ngx_solaris_io; 63 | 64 | return NGX_OK; 65 | } 66 | 67 | 68 | void 69 | ngx_os_specific_status(ngx_log_t *log) 70 | { 71 | 72 | ngx_log_error(NGX_LOG_NOTICE, log, 0, "OS: %s %s", 73 | ngx_solaris_sysname, ngx_solaris_release); 74 | 75 | ngx_log_error(NGX_LOG_NOTICE, log, 0, "version: %s", 76 | ngx_solaris_version); 77 | } 78 | -------------------------------------------------------------------------------- /src/os/unix/ngx_sunpro_amd64.il: -------------------------------------------------------------------------------- 1 | / 2 | / Copyright (C) Igor Sysoev 3 | / Copyright (C) Nginx, Inc. 4 | / 5 | 6 | / ngx_atomic_uint_t ngx_atomic_cmp_set(ngx_atomic_t *lock, 7 | / ngx_atomic_uint_t old, ngx_atomic_uint_t set); 8 | / 9 | / the arguments are passed in %rdi, %rsi, %rdx 10 | / the result is returned in the %rax 11 | 12 | .inline ngx_atomic_cmp_set,0 13 | movq %rsi, %rax 14 | lock 15 | cmpxchgq %rdx, (%rdi) 16 | setz %al 17 | movzbq %al, %rax 18 | .end 19 | 20 | 21 | / ngx_atomic_int_t ngx_atomic_fetch_add(ngx_atomic_t *value, 22 | / ngx_atomic_int_t add); 23 | / 24 | / the arguments are passed in %rdi, %rsi 25 | / the result is returned in the %rax 26 | 27 | .inline ngx_atomic_fetch_add,0 28 | movq %rsi, %rax 29 | lock 30 | xaddq %rax, (%rdi) 31 | .end 32 | 33 | 34 | / ngx_cpu_pause() 35 | / 36 | / the "rep; nop" is used instead of "pause" to avoid the "[ PAUSE ]" hardware 37 | / capability added by linker because Solaris/amd64 does not know about it: 38 | / 39 | / ld.so.1: nginx: fatal: hardware capability unsupported: 0x2000 [ PAUSE ] 40 | 41 | .inline ngx_cpu_pause,0 42 | rep; nop 43 | .end 44 | -------------------------------------------------------------------------------- /src/os/unix/ngx_sunpro_atomic_sparc64.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #if (NGX_PTR_SIZE == 4) 9 | #define NGX_CASA ngx_casa 10 | #else 11 | #define NGX_CASA ngx_casxa 12 | #endif 13 | 14 | 15 | ngx_atomic_uint_t 16 | ngx_casa(ngx_atomic_uint_t set, ngx_atomic_uint_t old, ngx_atomic_t *lock); 17 | 18 | ngx_atomic_uint_t 19 | ngx_casxa(ngx_atomic_uint_t set, ngx_atomic_uint_t old, ngx_atomic_t *lock); 20 | 21 | /* the code in src/os/unix/ngx_sunpro_sparc64.il */ 22 | 23 | 24 | static ngx_inline ngx_atomic_uint_t 25 | ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old, 26 | ngx_atomic_uint_t set) 27 | { 28 | set = NGX_CASA(set, old, lock); 29 | 30 | return (set == old); 31 | } 32 | 33 | 34 | static ngx_inline ngx_atomic_int_t 35 | ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) 36 | { 37 | ngx_atomic_uint_t old, res; 38 | 39 | old = *value; 40 | 41 | for ( ;; ) { 42 | 43 | res = old + add; 44 | 45 | res = NGX_CASA(res, old, value); 46 | 47 | if (res == old) { 48 | return res; 49 | } 50 | 51 | old = res; 52 | } 53 | } 54 | 55 | 56 | #define ngx_memory_barrier() \ 57 | __asm (".volatile"); \ 58 | __asm ("membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad"); \ 59 | __asm (".nonvolatile") 60 | 61 | #define ngx_cpu_pause() 62 | -------------------------------------------------------------------------------- /src/os/unix/ngx_sunpro_sparc64.il: -------------------------------------------------------------------------------- 1 | / 2 | / Copyright (C) Igor Sysoev 3 | / Copyright (C) Nginx, Inc. 4 | / 5 | 6 | 7 | / "casa [%o2] 0x80, %o1, %o0" and 8 | / "casxa [%o2] 0x80, %o1, %o0" do the following: 9 | / 10 | / if ([%o2] == %o1) { 11 | / swap(%o0, [%o2]); 12 | / } else { 13 | / %o0 = [%o2]; 14 | / } 15 | 16 | 17 | / ngx_atomic_uint_t ngx_casa(ngx_atomic_uint_t set, ngx_atomic_uint_t old, 18 | / ngx_atomic_t *lock); 19 | / 20 | / the arguments are passed in the %o0, %o1, %o2 21 | / the result is returned in the %o0 22 | 23 | .inline ngx_casa,0 24 | casa [%o2] 0x80, %o1, %o0 25 | .end 26 | 27 | 28 | / ngx_atomic_uint_t ngx_casxa(ngx_atomic_uint_t set, ngx_atomic_uint_t old, 29 | / ngx_atomic_t *lock); 30 | / 31 | / the arguments are passed in the %o0, %o1, %o2 32 | / the result is returned in the %o0 33 | 34 | .inline ngx_casxa,0 35 | casxa [%o2] 0x80, %o1, %o0 36 | .end 37 | -------------------------------------------------------------------------------- /src/os/unix/ngx_sunpro_x86.il: -------------------------------------------------------------------------------- 1 | / 2 | / Copyright (C) Igor Sysoev 3 | / Copyright (C) Nginx, Inc. 4 | / 5 | 6 | / ngx_atomic_uint_t ngx_atomic_cmp_set(ngx_atomic_t *lock, 7 | / ngx_atomic_uint_t old, ngx_atomic_uint_t set); 8 | / 9 | / the arguments are passed on stack (%esp), 4(%esp), 8(%esp) 10 | 11 | .inline ngx_atomic_cmp_set,0 12 | movl (%esp), %ecx 13 | movl 4(%esp), %eax 14 | movl 8(%esp), %edx 15 | lock 16 | cmpxchgl %edx, (%ecx) 17 | setz %al 18 | movzbl %al, %eax 19 | .end 20 | 21 | 22 | / ngx_atomic_int_t ngx_atomic_fetch_add(ngx_atomic_t *value, 23 | / ngx_atomic_int_t add); 24 | / 25 | / the arguments are passed on stack (%esp), 4(%esp) 26 | 27 | .inline ngx_atomic_fetch_add,0 28 | movl (%esp), %ecx 29 | movl 4(%esp), %eax 30 | lock 31 | xaddl %eax, (%ecx) 32 | .end 33 | 34 | 35 | / ngx_cpu_pause() 36 | / 37 | / the "rep; nop" is used instead of "pause" to avoid the "[ PAUSE ]" hardware 38 | / capability added by linker because Solaris/i386 does not know about it: 39 | / 40 | / ld.so.1: nginx: fatal: hardware capability unsupported: 0x2000 [ PAUSE ] 41 | 42 | .inline ngx_cpu_pause,0 43 | rep; nop 44 | .end 45 | -------------------------------------------------------------------------------- /src/os/unix/ngx_thread.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_THREAD_H_INCLUDED_ 9 | #define _NGX_THREAD_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | #if (NGX_THREADS) 16 | 17 | #include 18 | 19 | 20 | typedef pthread_mutex_t ngx_thread_mutex_t; 21 | 22 | ngx_int_t ngx_thread_mutex_create(ngx_thread_mutex_t *mtx, ngx_log_t *log); 23 | ngx_int_t ngx_thread_mutex_destroy(ngx_thread_mutex_t *mtx, ngx_log_t *log); 24 | ngx_int_t ngx_thread_mutex_lock(ngx_thread_mutex_t *mtx, ngx_log_t *log); 25 | ngx_int_t ngx_thread_mutex_unlock(ngx_thread_mutex_t *mtx, ngx_log_t *log); 26 | 27 | 28 | typedef pthread_cond_t ngx_thread_cond_t; 29 | 30 | ngx_int_t ngx_thread_cond_create(ngx_thread_cond_t *cond, ngx_log_t *log); 31 | ngx_int_t ngx_thread_cond_destroy(ngx_thread_cond_t *cond, ngx_log_t *log); 32 | ngx_int_t ngx_thread_cond_signal(ngx_thread_cond_t *cond, ngx_log_t *log); 33 | ngx_int_t ngx_thread_cond_wait(ngx_thread_cond_t *cond, ngx_thread_mutex_t *mtx, 34 | ngx_log_t *log); 35 | 36 | 37 | #if (NGX_LINUX) 38 | 39 | typedef pid_t ngx_tid_t; 40 | #define NGX_TID_T_FMT "%P" 41 | 42 | #elif (NGX_FREEBSD) 43 | 44 | typedef uint32_t ngx_tid_t; 45 | #define NGX_TID_T_FMT "%uD" 46 | 47 | #elif (NGX_DARWIN) 48 | 49 | typedef uint64_t ngx_tid_t; 50 | #define NGX_TID_T_FMT "%uL" 51 | 52 | #else 53 | 54 | typedef uint64_t ngx_tid_t; 55 | #define NGX_TID_T_FMT "%uL" 56 | 57 | #endif 58 | 59 | ngx_tid_t ngx_thread_tid(void); 60 | 61 | #define ngx_log_tid ngx_thread_tid() 62 | 63 | #else 64 | 65 | #define ngx_log_tid 0 66 | #define NGX_TID_T_FMT "%d" 67 | 68 | #endif 69 | 70 | 71 | #endif /* _NGX_THREAD_H_INCLUDED_ */ 72 | -------------------------------------------------------------------------------- /src/os/unix/ngx_thread_cond.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | ngx_int_t 13 | ngx_thread_cond_create(ngx_thread_cond_t *cond, ngx_log_t *log) 14 | { 15 | ngx_err_t err; 16 | 17 | err = pthread_cond_init(cond, NULL); 18 | if (err == 0) { 19 | return NGX_OK; 20 | } 21 | 22 | ngx_log_error(NGX_LOG_EMERG, log, err, "pthread_cond_init() failed"); 23 | return NGX_ERROR; 24 | } 25 | 26 | 27 | ngx_int_t 28 | ngx_thread_cond_destroy(ngx_thread_cond_t *cond, ngx_log_t *log) 29 | { 30 | ngx_err_t err; 31 | 32 | err = pthread_cond_destroy(cond); 33 | if (err == 0) { 34 | return NGX_OK; 35 | } 36 | 37 | ngx_log_error(NGX_LOG_EMERG, log, err, "pthread_cond_destroy() failed"); 38 | return NGX_ERROR; 39 | } 40 | 41 | 42 | ngx_int_t 43 | ngx_thread_cond_signal(ngx_thread_cond_t *cond, ngx_log_t *log) 44 | { 45 | ngx_err_t err; 46 | 47 | err = pthread_cond_signal(cond); 48 | if (err == 0) { 49 | return NGX_OK; 50 | } 51 | 52 | ngx_log_error(NGX_LOG_EMERG, log, err, "pthread_cond_signal() failed"); 53 | return NGX_ERROR; 54 | } 55 | 56 | 57 | ngx_int_t 58 | ngx_thread_cond_wait(ngx_thread_cond_t *cond, ngx_thread_mutex_t *mtx, 59 | ngx_log_t *log) 60 | { 61 | ngx_err_t err; 62 | 63 | err = pthread_cond_wait(cond, mtx); 64 | 65 | #if 0 66 | ngx_time_update(); 67 | #endif 68 | 69 | if (err == 0) { 70 | return NGX_OK; 71 | } 72 | 73 | ngx_log_error(NGX_LOG_ALERT, log, err, "pthread_cond_wait() failed"); 74 | 75 | return NGX_ERROR; 76 | } 77 | -------------------------------------------------------------------------------- /src/os/unix/ngx_thread_id.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | #if (NGX_LINUX) 14 | 15 | /* 16 | * Linux thread id is a pid of thread created by clone(2), 17 | * glibc does not provide a wrapper for gettid(). 18 | */ 19 | 20 | ngx_tid_t 21 | ngx_thread_tid(void) 22 | { 23 | return syscall(SYS_gettid); 24 | } 25 | 26 | #elif (NGX_FREEBSD) && (__FreeBSD_version >= 900031) 27 | 28 | #include 29 | 30 | ngx_tid_t 31 | ngx_thread_tid(void) 32 | { 33 | return pthread_getthreadid_np(); 34 | } 35 | 36 | #elif (NGX_DARWIN) 37 | 38 | /* 39 | * MacOSX thread has two thread ids: 40 | * 41 | * 1) MacOSX 10.6 (Snow Leoprad) has pthread_threadid_np() returning 42 | * an uint64_t value, which is obtained using the __thread_selfid() 43 | * syscall. It is a number above 300,000. 44 | */ 45 | 46 | ngx_tid_t 47 | ngx_thread_tid(void) 48 | { 49 | uint64_t tid; 50 | 51 | (void) pthread_threadid_np(NULL, &tid); 52 | return tid; 53 | } 54 | 55 | /* 56 | * 2) Kernel thread mach_port_t returned by pthread_mach_thread_np(). 57 | * It is a number in range 100-100,000. 58 | * 59 | * return pthread_mach_thread_np(pthread_self()); 60 | */ 61 | 62 | #else 63 | 64 | ngx_tid_t 65 | ngx_thread_tid(void) 66 | { 67 | return (uint64_t) (uintptr_t) pthread_self(); 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/os/unix/ngx_time.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_TIME_H_INCLUDED_ 9 | #define _NGX_TIME_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef ngx_rbtree_key_t ngx_msec_t; 17 | typedef ngx_rbtree_key_int_t ngx_msec_int_t; 18 | 19 | typedef struct tm ngx_tm_t; 20 | 21 | #define ngx_tm_sec tm_sec 22 | #define ngx_tm_min tm_min 23 | #define ngx_tm_hour tm_hour 24 | #define ngx_tm_mday tm_mday 25 | #define ngx_tm_mon tm_mon 26 | #define ngx_tm_year tm_year 27 | #define ngx_tm_wday tm_wday 28 | #define ngx_tm_isdst tm_isdst 29 | 30 | #define ngx_tm_sec_t int 31 | #define ngx_tm_min_t int 32 | #define ngx_tm_hour_t int 33 | #define ngx_tm_mday_t int 34 | #define ngx_tm_mon_t int 35 | #define ngx_tm_year_t int 36 | #define ngx_tm_wday_t int 37 | 38 | 39 | #if (NGX_HAVE_GMTOFF) 40 | #define ngx_tm_gmtoff tm_gmtoff 41 | #define ngx_tm_zone tm_zone 42 | #endif 43 | 44 | 45 | #if (NGX_SOLARIS) 46 | 47 | #define ngx_timezone(isdst) (- (isdst ? altzone : timezone) / 60) 48 | 49 | #else 50 | 51 | #define ngx_timezone(isdst) (- (isdst ? timezone + 3600 : timezone) / 60) 52 | 53 | #endif 54 | 55 | 56 | void ngx_timezone_update(void); 57 | void ngx_localtime(time_t s, ngx_tm_t *tm); 58 | void ngx_libc_localtime(time_t s, struct tm *tm); 59 | void ngx_libc_gmtime(time_t s, struct tm *tm); 60 | 61 | #define ngx_gettimeofday(tp) (void) gettimeofday(tp, NULL); 62 | #define ngx_msleep(ms) (void) usleep(ms * 1000) 63 | #define ngx_sleep(s) (void) sleep(s) 64 | 65 | 66 | #endif /* _NGX_TIME_H_INCLUDED_ */ 67 | -------------------------------------------------------------------------------- /src/os/unix/ngx_udp_recv.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | ssize_t 14 | ngx_udp_unix_recv(ngx_connection_t *c, u_char *buf, size_t size) 15 | { 16 | ssize_t n; 17 | ngx_err_t err; 18 | ngx_event_t *rev; 19 | 20 | rev = c->read; 21 | 22 | do { 23 | n = recv(c->fd, buf, size, 0); 24 | 25 | ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, 26 | "recv: fd:%d %z of %uz", c->fd, n, size); 27 | 28 | if (n >= 0) { 29 | 30 | #if (NGX_HAVE_KQUEUE) 31 | 32 | if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { 33 | rev->available -= n; 34 | 35 | /* 36 | * rev->available may be negative here because some additional 37 | * bytes may be received between kevent() and recv() 38 | */ 39 | 40 | if (rev->available <= 0) { 41 | rev->ready = 0; 42 | rev->available = 0; 43 | } 44 | } 45 | 46 | #endif 47 | 48 | return n; 49 | } 50 | 51 | err = ngx_socket_errno; 52 | 53 | if (err == NGX_EAGAIN || err == NGX_EINTR) { 54 | ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, 55 | "recv() not ready"); 56 | n = NGX_AGAIN; 57 | 58 | } else { 59 | n = ngx_connection_error(c, err, "recv() failed"); 60 | break; 61 | } 62 | 63 | } while (err == NGX_EINTR); 64 | 65 | rev->ready = 0; 66 | 67 | if (n == NGX_ERROR) { 68 | rev->error = 1; 69 | } 70 | 71 | return n; 72 | } 73 | -------------------------------------------------------------------------------- /src/os/unix/ngx_udp_send.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | ssize_t 14 | ngx_udp_unix_send(ngx_connection_t *c, u_char *buf, size_t size) 15 | { 16 | ssize_t n; 17 | ngx_err_t err; 18 | ngx_event_t *wev; 19 | 20 | wev = c->write; 21 | 22 | for ( ;; ) { 23 | n = sendto(c->fd, buf, size, 0, c->sockaddr, c->socklen); 24 | 25 | ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, 26 | "sendto: fd:%d %z of %uz to \"%V\"", 27 | c->fd, n, size, &c->addr_text); 28 | 29 | if (n >= 0) { 30 | if ((size_t) n != size) { 31 | wev->error = 1; 32 | (void) ngx_connection_error(c, 0, "sendto() incomplete"); 33 | return NGX_ERROR; 34 | } 35 | 36 | c->sent += n; 37 | 38 | return n; 39 | } 40 | 41 | err = ngx_socket_errno; 42 | 43 | if (err == NGX_EAGAIN) { 44 | wev->ready = 0; 45 | ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, NGX_EAGAIN, 46 | "sendto() not ready"); 47 | return NGX_AGAIN; 48 | } 49 | 50 | if (err != NGX_EINTR) { 51 | wev->error = 1; 52 | (void) ngx_connection_error(c, err, "sendto() failed"); 53 | return NGX_ERROR; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/os/unix/ngx_user.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | #if (NGX_CRYPT) 13 | 14 | #if (NGX_HAVE_GNU_CRYPT_R) 15 | 16 | ngx_int_t 17 | ngx_libc_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted) 18 | { 19 | char *value; 20 | size_t len; 21 | struct crypt_data cd; 22 | 23 | cd.initialized = 0; 24 | 25 | value = crypt_r((char *) key, (char *) salt, &cd); 26 | 27 | if (value) { 28 | len = ngx_strlen(value) + 1; 29 | 30 | *encrypted = ngx_pnalloc(pool, len); 31 | if (*encrypted == NULL) { 32 | return NGX_ERROR; 33 | } 34 | 35 | ngx_memcpy(*encrypted, value, len); 36 | return NGX_OK; 37 | } 38 | 39 | ngx_log_error(NGX_LOG_CRIT, pool->log, ngx_errno, "crypt_r() failed"); 40 | 41 | return NGX_ERROR; 42 | } 43 | 44 | #else 45 | 46 | ngx_int_t 47 | ngx_libc_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted) 48 | { 49 | char *value; 50 | size_t len; 51 | ngx_err_t err; 52 | 53 | value = crypt((char *) key, (char *) salt); 54 | 55 | if (value) { 56 | len = ngx_strlen(value) + 1; 57 | 58 | *encrypted = ngx_pnalloc(pool, len); 59 | if (*encrypted == NULL) { 60 | return NGX_ERROR; 61 | } 62 | 63 | ngx_memcpy(*encrypted, value, len); 64 | return NGX_OK; 65 | } 66 | 67 | err = ngx_errno; 68 | 69 | ngx_log_error(NGX_LOG_CRIT, pool->log, err, "crypt() failed"); 70 | 71 | return NGX_ERROR; 72 | } 73 | 74 | #endif 75 | 76 | #endif /* NGX_CRYPT */ 77 | -------------------------------------------------------------------------------- /src/os/unix/ngx_user.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_USER_H_INCLUDED_ 9 | #define _NGX_USER_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef uid_t ngx_uid_t; 17 | typedef gid_t ngx_gid_t; 18 | 19 | 20 | ngx_int_t ngx_libc_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, 21 | u_char **encrypted); 22 | 23 | 24 | #endif /* _NGX_USER_H_INCLUDED_ */ 25 | -------------------------------------------------------------------------------- /src/os/win32/nginx.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/asynch_mode_nginx/c37d7ef11d34ed82988d232f1545dcbbe868ed57/src/os/win32/nginx.ico -------------------------------------------------------------------------------- /src/os/win32/nginx.rc: -------------------------------------------------------------------------------- 1 | 2 | // Copyright (C) Igor Sysoev 3 | // Copyright (C) Nginx, Inc. 4 | 5 | 6 | nginx icon discardable "src\\os\\win32\\nginx.ico" 7 | -------------------------------------------------------------------------------- /src/os/win32/nginx_icon16.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char * nginx_xpm[] = { 3 | "16 16 2 2", 4 | /* colors */ 5 | " c none", 6 | "GG c #009900", 7 | /* pixels */ 8 | " ", 9 | " GGGGGGGGGGGGGGGG ", 10 | " GGGGGGGGGGGGGGGG ", 11 | " GGGGGGGGGGGGGGGGGGGG ", 12 | " GGGGGG GGGGGG ", 13 | " GGGGGG GGGGGG ", 14 | " GGGGGG ", 15 | " GGGGGG GGGGGGGGGGGGGGGG ", 16 | " GGGGGG GGGGGGGGGGGGGGGGGG ", 17 | " GGGGGG GGGGGGGGGGGGGG ", 18 | " GGGGGG GGGGGG ", 19 | " GGGGGG GGGGGG ", 20 | " GGGGGGGGGGGGGGGGGGGG ", 21 | " GGGGGGGGGGGGGGGG ", 22 | " GGGGGGGGGGGGGGGG ", 23 | " " 24 | }; 25 | -------------------------------------------------------------------------------- /src/os/win32/ngx_alloc.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | ngx_uint_t ngx_pagesize; 13 | ngx_uint_t ngx_pagesize_shift; 14 | ngx_uint_t ngx_cacheline_size; 15 | 16 | 17 | void *ngx_alloc(size_t size, ngx_log_t *log) 18 | { 19 | void *p; 20 | 21 | p = malloc(size); 22 | if (p == NULL) { 23 | ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, 24 | "malloc(%uz) failed", size); 25 | } 26 | 27 | ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, "malloc: %p:%uz", p, size); 28 | 29 | return p; 30 | } 31 | 32 | 33 | void *ngx_calloc(size_t size, ngx_log_t *log) 34 | { 35 | void *p; 36 | 37 | p = ngx_alloc(size, log); 38 | 39 | if (p) { 40 | ngx_memzero(p, size); 41 | } 42 | 43 | return p; 44 | } 45 | -------------------------------------------------------------------------------- /src/os/win32/ngx_alloc.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_ALLOC_H_INCLUDED_ 9 | #define _NGX_ALLOC_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | void *ngx_alloc(size_t size, ngx_log_t *log); 17 | void *ngx_calloc(size_t size, ngx_log_t *log); 18 | 19 | #define ngx_free free 20 | #define ngx_memalign(alignment, size, log) ngx_alloc(size, log) 21 | 22 | extern ngx_uint_t ngx_pagesize; 23 | extern ngx_uint_t ngx_pagesize_shift; 24 | extern ngx_uint_t ngx_cacheline_size; 25 | 26 | 27 | #endif /* _NGX_ALLOC_H_INCLUDED_ */ 28 | -------------------------------------------------------------------------------- /src/os/win32/ngx_atomic.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_ATOMIC_H_INCLUDED_ 9 | #define _NGX_ATOMIC_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | #define NGX_HAVE_ATOMIC_OPS 1 17 | 18 | typedef int32_t ngx_atomic_int_t; 19 | typedef uint32_t ngx_atomic_uint_t; 20 | typedef volatile ngx_atomic_uint_t ngx_atomic_t; 21 | #define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1) 22 | 23 | 24 | #if defined( __WATCOMC__ ) || defined( __BORLANDC__ ) || defined(__GNUC__) \ 25 | || ( _MSC_VER >= 1300 ) 26 | 27 | /* the new SDK headers */ 28 | 29 | #define ngx_atomic_cmp_set(lock, old, set) \ 30 | ((ngx_atomic_uint_t) InterlockedCompareExchange((long *) lock, set, old) \ 31 | == old) 32 | 33 | #else 34 | 35 | /* the old MS VC6.0SP2 SDK headers */ 36 | 37 | #define ngx_atomic_cmp_set(lock, old, set) \ 38 | (InterlockedCompareExchange((void **) lock, (void *) set, (void *) old) \ 39 | == (void *) old) 40 | 41 | #endif 42 | 43 | 44 | #define ngx_atomic_fetch_add(p, add) InterlockedExchangeAdd((long *) p, add) 45 | 46 | 47 | #define ngx_memory_barrier() 48 | 49 | 50 | #if defined( __BORLANDC__ ) || ( __WATCOMC__ < 1230 ) 51 | 52 | /* 53 | * Borland C++ 5.5 (tasm32) and Open Watcom C prior to 1.3 54 | * do not understand the "pause" instruction 55 | */ 56 | 57 | #define ngx_cpu_pause() 58 | #else 59 | #define ngx_cpu_pause() __asm { pause } 60 | #endif 61 | 62 | 63 | void ngx_spinlock(ngx_atomic_t *lock, ngx_atomic_int_t value, ngx_uint_t spin); 64 | 65 | #define ngx_trylock(lock) (*(lock) == 0 && ngx_atomic_cmp_set(lock, 0, 1)) 66 | #define ngx_unlock(lock) *(lock) = 0 67 | 68 | 69 | #endif /* _NGX_ATOMIC_H_INCLUDED_ */ 70 | -------------------------------------------------------------------------------- /src/os/win32/ngx_dlopen.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Maxim Dounin 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | char * 13 | ngx_dlerror(void) 14 | { 15 | u_char *p; 16 | static u_char errstr[NGX_MAX_ERROR_STR]; 17 | 18 | p = ngx_strerror(ngx_errno, errstr, NGX_MAX_ERROR_STR); 19 | *p = '\0'; 20 | 21 | return (char *) errstr; 22 | } 23 | -------------------------------------------------------------------------------- /src/os/win32/ngx_dlopen.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Maxim Dounin 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_DLOPEN_H_INCLUDED_ 9 | #define _NGX_DLOPEN_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | #define NGX_HAVE_DLOPEN 1 17 | 18 | 19 | #define ngx_dlopen(path) LoadLibrary((char *) path) 20 | #define ngx_dlopen_n "LoadLibrary()" 21 | 22 | #define ngx_dlsym(handle, symbol) (void *) GetProcAddress(handle, symbol) 23 | #define ngx_dlsym_n "GetProcAddress()" 24 | 25 | #define ngx_dlclose(handle) (FreeLibrary(handle) ? 0 : -1) 26 | #define ngx_dlclose_n "FreeLibrary()" 27 | 28 | 29 | char *ngx_dlerror(void); 30 | 31 | 32 | #endif /* _NGX_DLOPEN_H_INCLUDED_ */ 33 | -------------------------------------------------------------------------------- /src/os/win32/ngx_errno.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | u_char * 13 | ngx_strerror(ngx_err_t err, u_char *errstr, size_t size) 14 | { 15 | u_int len; 16 | static u_long lang = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); 17 | 18 | if (size == 0) { 19 | return errstr; 20 | } 21 | 22 | len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 23 | NULL, err, lang, (char *) errstr, size, NULL); 24 | 25 | if (len == 0 && lang) { 26 | 27 | /* 28 | * Try to use English messages first and fallback to a language, 29 | * based on locale: non-English Windows have no English messages 30 | * at all. This way allows to use English messages at least on 31 | * Windows with MUI. 32 | */ 33 | 34 | lang = 0; 35 | 36 | len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 37 | NULL, err, lang, (char *) errstr, size, NULL); 38 | } 39 | 40 | if (len == 0) { 41 | return ngx_snprintf(errstr, size, 42 | "FormatMessage() error:(%d)", GetLastError()); 43 | } 44 | 45 | /* remove ".\r\n\0" */ 46 | while (errstr[len] == '\0' || errstr[len] == CR 47 | || errstr[len] == LF || errstr[len] == '.') 48 | { 49 | --len; 50 | } 51 | 52 | return &errstr[++len]; 53 | } 54 | 55 | 56 | ngx_int_t 57 | ngx_strerror_init(void) 58 | { 59 | return NGX_OK; 60 | } 61 | -------------------------------------------------------------------------------- /src/os/win32/ngx_process_cycle.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_PROCESS_CYCLE_H_INCLUDED_ 9 | #define _NGX_PROCESS_CYCLE_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | #define NGX_PROCESS_SINGLE 0 17 | #define NGX_PROCESS_MASTER 1 18 | #define NGX_PROCESS_SIGNALLER 2 19 | #define NGX_PROCESS_WORKER 3 20 | 21 | 22 | void ngx_master_process_cycle(ngx_cycle_t *cycle); 23 | void ngx_single_process_cycle(ngx_cycle_t *cycle); 24 | void ngx_close_handle(HANDLE h); 25 | 26 | 27 | extern ngx_uint_t ngx_process; 28 | extern ngx_uint_t ngx_worker; 29 | extern ngx_pid_t ngx_pid; 30 | extern ngx_uint_t ngx_exiting; 31 | 32 | extern sig_atomic_t ngx_quit; 33 | extern sig_atomic_t ngx_terminate; 34 | extern sig_atomic_t ngx_reopen; 35 | 36 | extern ngx_uint_t ngx_inherited; 37 | extern ngx_pid_t ngx_new_binary; 38 | 39 | 40 | extern HANDLE ngx_master_process_event; 41 | extern char ngx_master_process_event_name[]; 42 | 43 | 44 | #endif /* _NGX_PROCESS_CYCLE_H_INCLUDED_ */ 45 | -------------------------------------------------------------------------------- /src/os/win32/ngx_shmem.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_SHMEM_H_INCLUDED_ 9 | #define _NGX_SHMEM_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef struct { 17 | u_char *addr; 18 | size_t size; 19 | ngx_str_t name; 20 | HANDLE handle; 21 | ngx_log_t *log; 22 | ngx_uint_t exists; /* unsigned exists:1; */ 23 | } ngx_shm_t; 24 | 25 | 26 | ngx_int_t ngx_shm_alloc(ngx_shm_t *shm); 27 | ngx_int_t ngx_shm_remap(ngx_shm_t *shm, u_char *addr); 28 | void ngx_shm_free(ngx_shm_t *shm); 29 | 30 | extern ngx_uint_t ngx_allocation_granularity; 31 | 32 | 33 | #endif /* _NGX_SHMEM_H_INCLUDED_ */ 34 | -------------------------------------------------------------------------------- /src/os/win32/ngx_socket.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | int 13 | ngx_nonblocking(ngx_socket_t s) 14 | { 15 | unsigned long nb = 1; 16 | 17 | return ioctlsocket(s, FIONBIO, &nb); 18 | } 19 | 20 | 21 | int 22 | ngx_blocking(ngx_socket_t s) 23 | { 24 | unsigned long nb = 0; 25 | 26 | return ioctlsocket(s, FIONBIO, &nb); 27 | } 28 | 29 | 30 | int 31 | ngx_socket_nread(ngx_socket_t s, int *n) 32 | { 33 | unsigned long nread; 34 | 35 | if (ioctlsocket(s, FIONREAD, &nread) == -1) { 36 | return -1; 37 | } 38 | 39 | *n = nread; 40 | 41 | return 0; 42 | } 43 | 44 | 45 | int 46 | ngx_tcp_push(ngx_socket_t s) 47 | { 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /src/os/win32/ngx_stat.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | int ngx_file_type(char *file, ngx_file_info_t *sb) 13 | { 14 | sb->dwFileAttributes = GetFileAttributes(file); 15 | 16 | if (sb->dwFileAttributes == INVALID_FILE_ATTRIBUTES) { 17 | return -1; 18 | } 19 | 20 | return 0; 21 | } 22 | 23 | /* 24 | int ngx_stat(char *file, ngx_stat_t *sb) 25 | { 26 | *sb = GetFileAttributes(file); 27 | 28 | if (*sb == INVALID_FILE_ATTRIBUTES) { 29 | return -1; 30 | } 31 | 32 | return 0; 33 | } 34 | */ 35 | -------------------------------------------------------------------------------- /src/os/win32/ngx_thread.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | ngx_err_t 13 | ngx_create_thread(ngx_tid_t *tid, 14 | ngx_thread_value_t (__stdcall *func)(void *arg), void *arg, ngx_log_t *log) 15 | { 16 | u_long id; 17 | ngx_err_t err; 18 | 19 | *tid = CreateThread(NULL, 0, func, arg, 0, &id); 20 | 21 | if (*tid != NULL) { 22 | ngx_log_error(NGX_LOG_NOTICE, log, 0, 23 | "create thread " NGX_TID_T_FMT, id); 24 | return 0; 25 | } 26 | 27 | err = ngx_errno; 28 | ngx_log_error(NGX_LOG_ALERT, log, err, "CreateThread() failed"); 29 | return err; 30 | } 31 | -------------------------------------------------------------------------------- /src/os/win32/ngx_thread.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_THREAD_H_INCLUDED_ 9 | #define _NGX_THREAD_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef HANDLE ngx_tid_t; 17 | typedef DWORD ngx_thread_value_t; 18 | 19 | 20 | ngx_err_t ngx_create_thread(ngx_tid_t *tid, 21 | ngx_thread_value_t (__stdcall *func)(void *arg), void *arg, ngx_log_t *log); 22 | 23 | #define ngx_log_tid GetCurrentThreadId() 24 | #define NGX_TID_T_FMT "%ud" 25 | 26 | 27 | #endif /* _NGX_THREAD_H_INCLUDED_ */ 28 | -------------------------------------------------------------------------------- /src/os/win32/ngx_time.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #include 9 | #include 10 | 11 | 12 | void 13 | ngx_gettimeofday(struct timeval *tp) 14 | { 15 | uint64_t intervals; 16 | FILETIME ft; 17 | 18 | GetSystemTimeAsFileTime(&ft); 19 | 20 | /* 21 | * A file time is a 64-bit value that represents the number 22 | * of 100-nanosecond intervals that have elapsed since 23 | * January 1, 1601 12:00 A.M. UTC. 24 | * 25 | * Between January 1, 1970 (Epoch) and January 1, 1601 there were 26 | * 134774 days, 27 | * 11644473600 seconds or 28 | * 11644473600,000,000,0 100-nanosecond intervals. 29 | * 30 | * See also MSKB Q167296. 31 | */ 32 | 33 | intervals = ((uint64_t) ft.dwHighDateTime << 32) | ft.dwLowDateTime; 34 | intervals -= 116444736000000000; 35 | 36 | tp->tv_sec = (long) (intervals / 10000000); 37 | tp->tv_usec = (long) ((intervals % 10000000) / 10); 38 | } 39 | 40 | 41 | void 42 | ngx_libc_localtime(time_t s, struct tm *tm) 43 | { 44 | struct tm *t; 45 | 46 | t = localtime(&s); 47 | *tm = *t; 48 | } 49 | 50 | 51 | void 52 | ngx_libc_gmtime(time_t s, struct tm *tm) 53 | { 54 | struct tm *t; 55 | 56 | t = gmtime(&s); 57 | *tm = *t; 58 | } 59 | 60 | 61 | ngx_int_t 62 | ngx_gettimezone(void) 63 | { 64 | u_long n; 65 | TIME_ZONE_INFORMATION tz; 66 | 67 | n = GetTimeZoneInformation(&tz); 68 | 69 | switch (n) { 70 | 71 | case TIME_ZONE_ID_UNKNOWN: 72 | return -tz.Bias; 73 | 74 | case TIME_ZONE_ID_STANDARD: 75 | return -(tz.Bias + tz.StandardBias); 76 | 77 | case TIME_ZONE_ID_DAYLIGHT: 78 | return -(tz.Bias + tz.DaylightBias); 79 | 80 | default: /* TIME_ZONE_ID_INVALID */ 81 | return 0; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/os/win32/ngx_time.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_TIME_H_INCLUDED_ 9 | #define _NGX_TIME_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | typedef ngx_rbtree_key_t ngx_msec_t; 17 | typedef ngx_rbtree_key_int_t ngx_msec_int_t; 18 | 19 | typedef SYSTEMTIME ngx_tm_t; 20 | typedef FILETIME ngx_mtime_t; 21 | 22 | #define ngx_tm_sec wSecond 23 | #define ngx_tm_min wMinute 24 | #define ngx_tm_hour wHour 25 | #define ngx_tm_mday wDay 26 | #define ngx_tm_mon wMonth 27 | #define ngx_tm_year wYear 28 | #define ngx_tm_wday wDayOfWeek 29 | 30 | #define ngx_tm_sec_t u_short 31 | #define ngx_tm_min_t u_short 32 | #define ngx_tm_hour_t u_short 33 | #define ngx_tm_mday_t u_short 34 | #define ngx_tm_mon_t u_short 35 | #define ngx_tm_year_t u_short 36 | #define ngx_tm_wday_t u_short 37 | 38 | 39 | #define ngx_msleep Sleep 40 | 41 | #define NGX_HAVE_GETTIMEZONE 1 42 | 43 | #define ngx_timezone_update() 44 | 45 | ngx_int_t ngx_gettimezone(void); 46 | void ngx_libc_localtime(time_t s, struct tm *tm); 47 | void ngx_libc_gmtime(time_t s, struct tm *tm); 48 | void ngx_gettimeofday(struct timeval *tp); 49 | 50 | 51 | #endif /* _NGX_TIME_H_INCLUDED_ */ 52 | -------------------------------------------------------------------------------- /src/os/win32/ngx_user.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Igor Sysoev 3 | * Copyright (C) Nginx, Inc. 4 | */ 5 | 6 | 7 | #include 8 | #include 9 | 10 | 11 | #if (NGX_CRYPT) 12 | 13 | ngx_int_t 14 | ngx_libc_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted) 15 | { 16 | /* STUB: a plain text password */ 17 | 18 | *encrypted = key; 19 | 20 | return NGX_OK; 21 | } 22 | 23 | #endif /* NGX_CRYPT */ 24 | -------------------------------------------------------------------------------- /src/os/win32/ngx_user.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | */ 6 | 7 | 8 | #ifndef _NGX_USER_H_INCLUDED_ 9 | #define _NGX_USER_H_INCLUDED_ 10 | 11 | 12 | #include 13 | #include 14 | 15 | 16 | /* STUB */ 17 | #define ngx_uid_t ngx_int_t 18 | #define ngx_gid_t ngx_int_t 19 | 20 | 21 | ngx_int_t ngx_libc_crypt(ngx_pool_t *pool, u_char *key, u_char *salt, 22 | u_char **encrypted); 23 | 24 | 25 | #endif /* _NGX_USER_H_INCLUDED_ */ 26 | -------------------------------------------------------------------------------- /src/stream/ngx_stream_ssl_module.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (C) Igor Sysoev 4 | * Copyright (C) Nginx, Inc. 5 | * Copyright (C) Intel, Inc. 6 | */ 7 | 8 | 9 | #ifndef _NGX_STREAM_SSL_H_INCLUDED_ 10 | #define _NGX_STREAM_SSL_H_INCLUDED_ 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | typedef struct { 19 | ngx_msec_t handshake_timeout; 20 | 21 | ngx_flag_t prefer_server_ciphers; 22 | ngx_flag_t reject_handshake; 23 | 24 | ngx_ssl_t ssl; 25 | 26 | ngx_flag_t asynch; 27 | 28 | ngx_uint_t protocols; 29 | 30 | ngx_uint_t verify; 31 | ngx_uint_t verify_depth; 32 | 33 | ssize_t builtin_session_cache; 34 | 35 | time_t session_timeout; 36 | 37 | ngx_array_t *certificates; 38 | ngx_array_t *certificate_keys; 39 | 40 | ngx_array_t *certificate_values; 41 | ngx_array_t *certificate_key_values; 42 | 43 | ngx_str_t dhparam; 44 | ngx_str_t ecdh_curve; 45 | ngx_str_t client_certificate; 46 | ngx_str_t trusted_certificate; 47 | ngx_str_t crl; 48 | ngx_str_t alpn; 49 | 50 | ngx_str_t ciphers; 51 | 52 | ngx_array_t *passwords; 53 | ngx_array_t *conf_commands; 54 | 55 | ngx_shm_zone_t *shm_zone; 56 | 57 | ngx_flag_t session_tickets; 58 | ngx_array_t *session_ticket_keys; 59 | } ngx_stream_ssl_srv_conf_t; 60 | 61 | 62 | extern ngx_module_t ngx_stream_ssl_module; 63 | 64 | 65 | #endif /* _NGX_STREAM_SSL_H_INCLUDED_ */ 66 | -------------------------------------------------------------------------------- /test/nginx-tests/LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | * BSD LICENSE 3 | * 4 | * Copyright (C) 2008-2011 Maxim Dounin 5 | * Copyright (C) 2014-2024 Intel, Inc. 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of Intel Corporation nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | -------------------------------------------------------------------------------- /test/nginx-tests/README: -------------------------------------------------------------------------------- 1 | # Copyright (C) Intel, Inc. 2 | Test suite for nginx. 3 | 4 | Use prove to run tests as one usually do for perl tests. Individual tests 5 | may be run as well. 6 | 7 | Note: tests run nginx (and backend daemons if needed) listening on localhost 8 | and may use various ports in 8000 .. 8999 range. 9 | 10 | Usage: 11 | 12 | $ TEST_NGINX_BINARY=/path/to/nginx prove . 13 | 14 | By default tests expect nginx binary to be at ../nginx/objs/nginx. 15 | 16 | Environment variables: 17 | 18 | TEST_NGINX_BINARY 19 | 20 | Sets path to nginx binary to be tested, defaults to "../nginx/objs/nginx". 21 | 22 | TEST_NGINX_MODULES 23 | 24 | Sets path to modules directory, defaults to dirname of TEST_NGINX_BINARY. 25 | 26 | TEST_NGINX_VERBOSE 27 | 28 | Be a bit more verbose (in particular, print requests sent and responses 29 | got from nginx). Note that this requires prove -v (or HARNESS_VERBOSE). 30 | 31 | TEST_NGINX_LEAVE 32 | 33 | If set, temporary directory with configs and logs won't be deleted on test 34 | completion. Useful for debugging. 35 | 36 | TEST_NGINX_CATLOG 37 | 38 | Cat error log to stdout after test completion. Useful for debugging. 39 | 40 | TEST_NGINX_UNSAFE 41 | 42 | Run unsafe tests. 43 | 44 | TEST_NGINX_GLOBALS 45 | 46 | Sets additional directives in main context for async. 47 | 48 | TEST_NGINX_SYNC_GLOBALS 49 | 50 | Sets additional directives in main context for sync. 51 | 52 | TEST_NGINX_GLOBALS_HTTP 53 | 54 | Sets additional directives in http context. 55 | 56 | TEST_NGINX_GLOBALS_STREAM 57 | 58 | Sets additional directives in stream context. 59 | 60 | Happy testing! 61 | -------------------------------------------------------------------------------- /test/nginx-tests/addition_buffered.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for addition module with buffered data from other filters. 8 | 9 | # In particular, sub filter may have a partial match buffered. 10 | 11 | ############################################################################### 12 | 13 | use warnings; 14 | use strict; 15 | 16 | use Test::More; 17 | 18 | BEGIN { use FindBin; chdir($FindBin::Bin); } 19 | 20 | use lib 'lib'; 21 | use Test::Nginx; 22 | 23 | ############################################################################### 24 | 25 | select STDERR; $| = 1; 26 | select STDOUT; $| = 1; 27 | 28 | my $t = Test::Nginx->new()->has(qw/http proxy sub addition/)->plan(1); 29 | 30 | $t->write_file_expand('nginx.conf', <<'EOF'); 31 | 32 | %%TEST_GLOBALS%% 33 | 34 | daemon off; 35 | 36 | events { 37 | } 38 | 39 | http { 40 | %%TEST_GLOBALS_HTTP%% 41 | 42 | server { 43 | listen 127.0.0.1:8080; 44 | server_name localhost; 45 | 46 | location / { } 47 | location /proxy/ { 48 | sub_filter foo bar; 49 | add_after_body /after.html; 50 | proxy_pass http://127.0.0.1:8080/; 51 | } 52 | } 53 | } 54 | 55 | EOF 56 | 57 | $t->write_file('after.html', 'after'); 58 | $t->write_file('body.html', 'XXXXX'); 59 | 60 | $t->run(); 61 | 62 | ############################################################################### 63 | 64 | # if data is buffered, there should be no interleaved data in output 65 | 66 | like(http_get('/proxy/body.html'), qr/^XXXXXafter$/m, 'request'); 67 | 68 | ############################################################################### 69 | -------------------------------------------------------------------------------- /test/nginx-tests/debug_connection.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Nginx, Inc. 5 | 6 | # Tests for debug_connection. 7 | 8 | ############################################################################### 9 | 10 | use warnings; 11 | use strict; 12 | 13 | use Test::More; 14 | 15 | BEGIN { use FindBin; chdir($FindBin::Bin); } 16 | 17 | use lib 'lib'; 18 | use Test::Nginx; 19 | 20 | ############################################################################### 21 | 22 | select STDERR; $| = 1; 23 | select STDOUT; $| = 1; 24 | 25 | my $t = Test::Nginx->new()->has(qw/http --with-debug proxy/); 26 | 27 | $t->write_file_expand('nginx.conf', <<'EOF'); 28 | 29 | %%TEST_GLOBALS%% 30 | 31 | daemon off; 32 | 33 | events { 34 | debug_connection ::1; 35 | } 36 | 37 | http { 38 | %%TEST_GLOBALS_HTTP%% 39 | 40 | error_log %%TESTDIR%%/debug1.log alert; 41 | error_log %%TESTDIR%%/debug2.log alert; 42 | 43 | server { 44 | listen 127.0.0.1:8080; 45 | listen [::1]:%%PORT_8080%%; 46 | server_name localhost; 47 | 48 | location /debug { 49 | proxy_pass http://[::1]:%%PORT_8080%%/; 50 | } 51 | } 52 | } 53 | 54 | EOF 55 | 56 | $t->try_run('no inet6 support')->plan(5); 57 | 58 | ############################################################################### 59 | 60 | http_get('/'); 61 | 62 | select undef, undef, undef, 0.1; 63 | is($t->read_file('debug1.log'), '', 'no debug_connection file 1'); 64 | is($t->read_file('debug2.log'), '', 'no debug_connection file 2'); 65 | 66 | http_get('/debug'); 67 | 68 | select undef, undef, undef, 0.1; 69 | like($t->read_file('debug1.log'), qr/\[debug\]/, 'debug_connection file 1'); 70 | like($t->read_file('debug2.log'), qr/\[debug\]/, 'debug_connection file 2'); 71 | is($t->read_file('debug1.log'), $t->read_file('debug2.log'), 72 | 'debug_connection file1 file2 match'); 73 | 74 | ############################################################################### 75 | -------------------------------------------------------------------------------- /test/nginx-tests/gunzip_perl.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Maxim Dounin 5 | 6 | # Tests for gunzip filter module with perl module. 7 | 8 | ############################################################################### 9 | 10 | use warnings; 11 | use strict; 12 | 13 | use Test::More; 14 | 15 | BEGIN { use FindBin; chdir($FindBin::Bin); } 16 | 17 | use lib 'lib'; 18 | use Test::Nginx qw/ :DEFAULT :gzip /; 19 | 20 | ############################################################################### 21 | 22 | select STDERR; $| = 1; 23 | select STDOUT; $| = 1; 24 | 25 | eval { require IO::Compress::Gzip; }; 26 | plan(skip_all => "IO::Compress::Gzip not found") if $@; 27 | 28 | my $t = Test::Nginx->new()->has(qw/http gunzip perl/)->plan(2) 29 | ->write_file_expand('nginx.conf', <<'EOF'); 30 | 31 | %%TEST_GLOBALS%% 32 | 33 | daemon off; 34 | 35 | events { 36 | } 37 | 38 | http { 39 | %%TEST_GLOBALS_HTTP%% 40 | 41 | server { 42 | listen 127.0.0.1:8080; 43 | server_name localhost; 44 | 45 | gunzip on; 46 | 47 | location / { 48 | perl 'sub { 49 | my $r = shift; 50 | $r->header_out("Content-Encoding", "gzip"); 51 | $r->send_http_header("text/plain"); 52 | return OK if $r->header_only; 53 | use IO::Compress::Gzip; 54 | my $in = "TEST"; 55 | my $out; 56 | IO::Compress::Gzip::gzip(\\$in => \\$out); 57 | $r->print($out); 58 | return OK; 59 | }'; 60 | } 61 | } 62 | } 63 | 64 | EOF 65 | 66 | $t->run(); 67 | 68 | ############################################################################### 69 | 70 | http_gzip_like(http_gzip_request('/'), qr/TEST/, 'perl response gzipped'); 71 | like(http_get('/'), qr/TEST/, 'perl response gunzipped'); 72 | 73 | ############################################################################### 74 | -------------------------------------------------------------------------------- /test/nginx-tests/gzip_flush.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Maxim Dounin 5 | 6 | # Tests for gzip filter module. 7 | 8 | ############################################################################### 9 | 10 | use warnings; 11 | use strict; 12 | 13 | use Test::More; 14 | 15 | BEGIN { use FindBin; chdir($FindBin::Bin); } 16 | 17 | use lib 'lib'; 18 | use Test::Nginx qw/ :DEFAULT :gzip /; 19 | 20 | ############################################################################### 21 | 22 | select STDERR; $| = 1; 23 | select STDOUT; $| = 1; 24 | 25 | my $t = Test::Nginx->new()->has(qw/http gzip perl/)->plan(2) 26 | ->write_file_expand('nginx.conf', <<'EOF'); 27 | 28 | %%TEST_GLOBALS%% 29 | 30 | daemon off; 31 | 32 | events { 33 | } 34 | 35 | http { 36 | %%TEST_GLOBALS_HTTP%% 37 | 38 | server { 39 | listen 127.0.0.1:8080; 40 | server_name localhost; 41 | 42 | gzip on; 43 | gzip_min_length 0; 44 | %%QATZIP_ENABLE%% 45 | %%QATZIP_MIN_LENGTH_0%% 46 | 47 | location / { 48 | perl 'sub { 49 | my $r = shift; 50 | $r->send_http_header("text/html"); 51 | return OK if $r->header_only; 52 | $r->print("DA"); 53 | $r->flush(); 54 | $r->flush(); 55 | $r->print("TA"); 56 | return OK; 57 | }'; 58 | } 59 | } 60 | } 61 | 62 | EOF 63 | 64 | $t->run(); 65 | 66 | ############################################################################### 67 | 68 | like(http_get('/'), qr/DATA/, 'request with flush'); 69 | 70 | # gzip filter wasn't able to handle empty flush buffers, see 71 | # http://nginx.org/pipermail/nginx/2010-November/023693.html 72 | 73 | http_gzip_like(http_gzip_request('/'), qr/DATA/, 'gzip request with flush'); 74 | 75 | ############################################################################### 76 | -------------------------------------------------------------------------------- /test/nginx-tests/http_keepalive_shutdown.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for http keepalive connections on worker shutdown. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx qw/ :DEFAULT http_end /; 20 | 21 | ############################################################################### 22 | 23 | select STDERR; $| = 1; 24 | select STDOUT; $| = 1; 25 | 26 | my $t = Test::Nginx->new()->has(qw/http limit_req/)->plan(1); 27 | 28 | $t->write_file_expand('nginx.conf', <<'EOF'); 29 | 30 | %%TEST_GLOBALS%% 31 | 32 | daemon off; 33 | 34 | events { 35 | } 36 | 37 | http { 38 | %%TEST_GLOBALS_HTTP%% 39 | 40 | limit_req_zone $binary_remote_addr zone=one:1m rate=1r/s; 41 | 42 | server { 43 | listen 127.0.0.1:8080; 44 | server_name localhost; 45 | 46 | location / { 47 | limit_req zone=one burst=5; 48 | } 49 | } 50 | } 51 | 52 | EOF 53 | 54 | $t->write_file('test.html', 'XtestX'); 55 | $t->run(); 56 | 57 | ############################################################################### 58 | 59 | # signaling on graceful shutdown to client that keepalive connection is closing 60 | 61 | my $s = http(< 1); 62 | HEAD /test.html HTTP/1.1 63 | Host: localhost 64 | 65 | HEAD /test.html HTTP/1.1 66 | Host: localhost 67 | 68 | EOF 69 | 70 | select undef, undef, undef, 0.1; 71 | 72 | $t->stop(); 73 | 74 | like(http_end($s), qr/Connection: close/, 'connection close on exit'); 75 | 76 | ############################################################################### 77 | -------------------------------------------------------------------------------- /test/nginx-tests/http_method.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for HTTP methods. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | 21 | ############################################################################### 22 | 23 | select STDERR; $| = 1; 24 | select STDOUT; $| = 1; 25 | 26 | my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(2) 27 | ->write_file_expand('nginx.conf', <<'EOF')->run(); 28 | 29 | %%TEST_GLOBALS%% 30 | 31 | daemon off; 32 | 33 | events { 34 | } 35 | 36 | http { 37 | %%TEST_GLOBALS_HTTP%% 38 | 39 | server { 40 | listen 127.0.0.1:8080; 41 | server_name localhost; 42 | 43 | location / { 44 | return 200; 45 | } 46 | } 47 | } 48 | 49 | EOF 50 | 51 | ############################################################################### 52 | 53 | like(http(<new()->has(qw/http limit_req/)->plan(4); 27 | 28 | $t->write_file_expand('nginx.conf', <<'EOF'); 29 | 30 | %%TEST_GLOBALS%% 31 | 32 | daemon off; 33 | 34 | events { 35 | } 36 | 37 | http { 38 | %%TEST_GLOBALS_HTTP%% 39 | 40 | limit_req_zone $binary_remote_addr zone=one:1m rate=30r/m; 41 | 42 | server { 43 | listen 127.0.0.1:8080; 44 | server_name localhost; 45 | 46 | location / { 47 | limit_req zone=one delay=1 burst=2; 48 | add_header X-Time $request_time; 49 | } 50 | } 51 | } 52 | 53 | EOF 54 | 55 | $t->write_file('delay.html', 'XtestX'); 56 | $t->run(); 57 | 58 | ############################################################################### 59 | 60 | like(http_get('/delay.html'), qr/^HTTP\/1.. 200 /m, 'request'); 61 | like(http_get('/delay.html'), qr/X-Time: 0.000/, 'not yet delayed'); 62 | my $s = http_get('/delay.html', start => 1, sleep => 0.2); 63 | like(http_get('/delay.html'), qr/^HTTP\/1.. 503 /m, 'rejected'); 64 | like(http_end($s), qr/^HTTP\/1.. 200 .*X-Time: (?!0.000)/ms, 'delayed'); 65 | 66 | ############################################################################### 67 | -------------------------------------------------------------------------------- /test/nginx-tests/mail_smtp_greeting_delay.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Maxim Dounin 5 | 6 | ############################################################################### 7 | 8 | use warnings; 9 | use strict; 10 | 11 | use Test::More; 12 | 13 | BEGIN { use FindBin; chdir($FindBin::Bin); } 14 | 15 | use lib 'lib'; 16 | use Test::Nginx; 17 | use Test::Nginx::SMTP; 18 | 19 | ############################################################################### 20 | 21 | select STDERR; $| = 1; 22 | select STDOUT; $| = 1; 23 | 24 | local $SIG{PIPE} = 'IGNORE'; 25 | 26 | my $t = Test::Nginx->new()->has(qw/mail smtp/)->plan(2) 27 | ->write_file_expand('nginx.conf', <<'EOF')->run(); 28 | 29 | %%TEST_GLOBALS%% 30 | 31 | daemon off; 32 | 33 | events { 34 | } 35 | 36 | mail { 37 | proxy_pass_error_message on; 38 | proxy_timeout 15s; 39 | auth_http http://127.0.0.1:8080/mail/auth; 40 | xclient off; 41 | 42 | server { 43 | listen 127.0.0.1:8025; 44 | protocol smtp; 45 | smtp_greeting_delay 1s; 46 | } 47 | } 48 | 49 | EOF 50 | 51 | ############################################################################### 52 | 53 | # With smtp_greeting_delay session expected to be closed after first error 54 | # message if client sent something before greeting. 55 | 56 | my $s = Test::Nginx::SMTP->new(); 57 | $s->send('HELO example.com'); 58 | $s->check(qr/^5.. /, "command before greeting - session must be rejected"); 59 | ok($s->eof(), "session have to be closed"); 60 | 61 | ############################################################################### 62 | -------------------------------------------------------------------------------- /test/nginx-tests/map_complex.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for map module with complex value. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | 21 | ############################################################################### 22 | 23 | select STDERR; $| = 1; 24 | select STDOUT; $| = 1; 25 | 26 | my $t = Test::Nginx->new()->has(qw/http map rewrite/); 27 | 28 | $t->write_file_expand('nginx.conf', <<'EOF'); 29 | 30 | %%TEST_GLOBALS%% 31 | 32 | daemon off; 33 | 34 | events { 35 | } 36 | 37 | http { 38 | %%TEST_GLOBALS_HTTP%% 39 | 40 | map $args $x { 41 | var foo:$y; 42 | var2 $y:foo; 43 | default foo:$y; 44 | } 45 | 46 | map $args $y { 47 | default bar; 48 | same baz; 49 | } 50 | 51 | server { 52 | listen 127.0.0.1:8080; 53 | server_name localhost; 54 | 55 | location / { 56 | add_header X-Foo $x; 57 | return 204; 58 | } 59 | } 60 | } 61 | 62 | EOF 63 | 64 | $t->run()->plan(3); 65 | 66 | ############################################################################### 67 | 68 | like(http_get('/?var'), qr/foo:bar/, 'map cv'); 69 | like(http_get('/?var2'), qr/bar:foo/, 'map cv 2'); 70 | like(http_get('/?same'), qr/foo:baz/, 'map cv key'); 71 | 72 | ############################################################################### 73 | -------------------------------------------------------------------------------- /test/nginx-tests/map_volatile.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for map module with volatile. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | 21 | ############################################################################### 22 | 23 | select STDERR; $| = 1; 24 | select STDOUT; $| = 1; 25 | 26 | my $t = Test::Nginx->new()->has(qw/http map/); 27 | 28 | $t->write_file_expand('nginx.conf', <<'EOF'); 29 | 30 | %%TEST_GLOBALS%% 31 | 32 | daemon off; 33 | 34 | events { 35 | } 36 | 37 | http { 38 | %%TEST_GLOBALS_HTTP%% 39 | 40 | map $uri $uri_cached { 41 | /1/ /1/redirect; 42 | /1/redirect uncached; 43 | } 44 | 45 | map $uri $uri_uncached { 46 | volatile; 47 | 48 | /2/ /2/redirect; 49 | /2/redirect uncached; 50 | } 51 | 52 | server { 53 | listen 127.0.0.1:8080; 54 | server_name localhost; 55 | 56 | location /1 { 57 | index $uri_cached; 58 | } 59 | location /1/redirect { 60 | add_header X-URI $uri_cached always; 61 | } 62 | 63 | location /2 { 64 | index $uri_uncached; 65 | } 66 | location /2/redirect { 67 | add_header X-URI $uri_uncached always; 68 | } 69 | } 70 | } 71 | 72 | EOF 73 | 74 | mkdir($t->testdir() . '/1'); 75 | mkdir($t->testdir() . '/2'); 76 | 77 | $t->run()->plan(2); 78 | 79 | ############################################################################### 80 | 81 | like(http_get('/1/'), qr!X-URI: /1/redirect!, 'map'); 82 | like(http_get('/2/'), qr/X-URI: uncached/, 'map volatile'); 83 | 84 | ############################################################################### 85 | -------------------------------------------------------------------------------- /test/nginx-tests/merge_slashes.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for URI normalization, merge_slashes off. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | 21 | ############################################################################### 22 | 23 | select STDERR; $| = 1; 24 | select STDOUT; $| = 1; 25 | 26 | my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(2) 27 | ->write_file_expand('nginx.conf', <<'EOF')->run(); 28 | 29 | %%TEST_GLOBALS%% 30 | 31 | daemon off; 32 | 33 | events { 34 | } 35 | 36 | http { 37 | %%TEST_GLOBALS_HTTP%% 38 | 39 | server { 40 | listen 127.0.0.1:8080; 41 | server_name localhost; 42 | 43 | merge_slashes off; 44 | 45 | location / { 46 | add_header X-URI "x $uri x"; 47 | return 204; 48 | } 49 | } 50 | } 51 | 52 | EOF 53 | 54 | ############################################################################### 55 | 56 | like(http_get('/foo//../bar'), qr!x /foo/bar x!, 'merge slashes'); 57 | like(http_get('/foo///../bar'), qr!x /foo//bar x!, 'merge slashes 2'); 58 | 59 | ############################################################################### 60 | -------------------------------------------------------------------------------- /test/nginx-tests/perl_sleep.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Maxim Dounin 5 | 6 | # Tests for embedded perl module, $r->sleep(). 7 | 8 | ############################################################################### 9 | 10 | use warnings; 11 | use strict; 12 | 13 | use Test::More; 14 | 15 | BEGIN { use FindBin; chdir($FindBin::Bin); } 16 | 17 | use lib 'lib'; 18 | use Test::Nginx; 19 | 20 | ############################################################################### 21 | 22 | select STDERR; $| = 1; 23 | select STDOUT; $| = 1; 24 | 25 | my $t = Test::Nginx->new()->has(qw/http perl ssi/)->plan(2) 26 | ->write_file_expand('nginx.conf', <<'EOF'); 27 | 28 | %%TEST_GLOBALS%% 29 | 30 | daemon off; 31 | 32 | events { 33 | } 34 | 35 | http { 36 | %%TEST_GLOBALS_HTTP%% 37 | 38 | server { 39 | listen 127.0.0.1:8080; 40 | server_name localhost; 41 | 42 | location / { 43 | ssi on; 44 | sendfile_max_chunk 100; 45 | postpone_output 0; 46 | } 47 | 48 | location /sleep { 49 | perl 'sub { 50 | my $r = shift; 51 | 52 | $r->sleep(100, sub { 53 | my $r = shift; 54 | $r->send_http_header; 55 | $r->print("it works"); 56 | return OK; 57 | }); 58 | 59 | return OK; 60 | }'; 61 | } 62 | } 63 | } 64 | 65 | EOF 66 | 67 | $t->write_file('subrequest.html', ('x' x 200) . 68 | 'XX'); 69 | 70 | $t->run(); 71 | 72 | ############################################################################### 73 | 74 | like(http_get('/sleep'), qr/works/, 'perl sleep'); 75 | like(http_get('/subrequest.html'), qr/works/, 'perl sleep in subrequest'); 76 | 77 | ############################################################################### 78 | -------------------------------------------------------------------------------- /test/nginx-tests/perl_ssi.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Maxim Dounin 5 | 6 | # Tests for embedded perl module. 7 | 8 | ############################################################################### 9 | 10 | use warnings; 11 | use strict; 12 | 13 | use Test::More; 14 | 15 | BEGIN { use FindBin; chdir($FindBin::Bin); } 16 | 17 | use lib 'lib'; 18 | use Test::Nginx; 19 | 20 | ############################################################################### 21 | 22 | select STDERR; $| = 1; 23 | select STDOUT; $| = 1; 24 | 25 | my $t = Test::Nginx->new()->has(qw/http perl ssi/)->plan(3) 26 | ->write_file_expand('nginx.conf', <<'EOF'); 27 | 28 | %%TEST_GLOBALS%% 29 | 30 | daemon off; 31 | 32 | events { 33 | } 34 | 35 | http { 36 | %%TEST_GLOBALS_HTTP%% 37 | 38 | server { 39 | listen 127.0.0.1:8080; 40 | server_name localhost; 41 | 42 | location / { 43 | ssi on; 44 | } 45 | 46 | location /dummy { 47 | perl 'sub foo { my $r = shift; $r->print(join ",", @_); }'; 48 | } 49 | } 50 | } 51 | 52 | EOF 53 | 54 | $t->write_file('t1.html', 'XX'); 55 | $t->write_file('t2.html', 'XX'); 56 | $t->write_file('noargs.html', 'XX'); 57 | 58 | $t->run(); 59 | 60 | ############################################################################### 61 | 62 | like(http_get('/t1.html'), qr/Xarg1X/, 'perl ssi response'); 63 | like(http_get('/t2.html'), qr/Xarg1,arg2X/, 'perl ssi two args'); 64 | like(http_get('/noargs.html'), qr/XX/, 'perl ssi noargs'); 65 | 66 | ############################################################################### 67 | -------------------------------------------------------------------------------- /test/nginx-tests/proxy_bind_transparent.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for http proxy_bind transparent. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | 21 | ############################################################################### 22 | 23 | select STDERR; $| = 1; 24 | select STDOUT; $| = 1; 25 | 26 | plan(skip_all => 'win32') if $^O eq 'MSWin32'; 27 | plan(skip_all => 'must be root') if $> != 0; 28 | plan(skip_all => '127.0.0.2 local address required') 29 | unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' ); 30 | 31 | my $t = Test::Nginx->new()->has(qw/http proxy/) 32 | ->write_file_expand('nginx.conf', <<'EOF'); 33 | 34 | %%TEST_GLOBALS%% 35 | 36 | daemon off; 37 | user root wheel; 38 | 39 | events { 40 | } 41 | 42 | http { 43 | %%TEST_GLOBALS_HTTP%% 44 | 45 | server { 46 | listen 127.0.0.1:8080; 47 | server_name localhost; 48 | 49 | location / { 50 | proxy_bind 127.0.0.2 transparent; 51 | proxy_pass http://127.0.0.1:8081/; 52 | } 53 | } 54 | 55 | server { 56 | listen 127.0.0.1:8081; 57 | server_name localhost; 58 | 59 | location / { 60 | add_header X-IP $remote_addr always; 61 | } 62 | } 63 | } 64 | 65 | EOF 66 | 67 | $t->run()->plan(1); 68 | 69 | ############################################################################### 70 | 71 | like(http_get('/'), qr/X-IP: 127.0.0.2/, 'transparent'); 72 | 73 | ############################################################################### 74 | -------------------------------------------------------------------------------- /test/nginx-tests/proxy_bind_transparent_capability.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for http proxy_bind transparent with Linux CAP_NET_RAW capability. 8 | # Ensure that such configuration isn't broken under a non-priveleged user. 9 | 10 | ############################################################################### 11 | 12 | use warnings; 13 | use strict; 14 | 15 | use Test::More; 16 | 17 | BEGIN { use FindBin; chdir($FindBin::Bin); } 18 | 19 | use lib 'lib'; 20 | use Test::Nginx; 21 | 22 | ############################################################################### 23 | 24 | select STDERR; $| = 1; 25 | select STDOUT; $| = 1; 26 | 27 | plan(skip_all => 'no linux capability') if $^O ne 'linux'; 28 | plan(skip_all => 'must be root') if $> != 0; 29 | plan(skip_all => '127.0.0.2 local address required') 30 | unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' ); 31 | 32 | my $t = Test::Nginx->new()->has(qw/http proxy/) 33 | ->write_file_expand('nginx.conf', <<'EOF'); 34 | 35 | %%TEST_GLOBALS%% 36 | 37 | daemon off; 38 | 39 | events { 40 | } 41 | 42 | http { 43 | %%TEST_GLOBALS_HTTP%% 44 | 45 | server { 46 | listen 127.0.0.1:8080; 47 | server_name localhost; 48 | 49 | location / { 50 | proxy_bind 127.0.0.2 transparent; 51 | proxy_pass http://127.0.0.1:8081/; 52 | } 53 | } 54 | 55 | server { 56 | listen 127.0.0.1:8081; 57 | server_name localhost; 58 | 59 | location / { 60 | add_header X-IP $remote_addr always; 61 | } 62 | } 63 | } 64 | 65 | EOF 66 | 67 | $t->run()->plan(1); 68 | 69 | ############################################################################### 70 | 71 | like(http_get('/'), qr/X-IP: 127.0.0.2/, 'transparent'); 72 | 73 | ############################################################################### 74 | -------------------------------------------------------------------------------- /test/nginx-tests/proxy_cache_min_free.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for http proxy cache, min_free parameter. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | 21 | ############################################################################### 22 | 23 | select STDERR; $| = 1; 24 | select STDOUT; $| = 1; 25 | 26 | my $t = Test::Nginx->new()->has(qw/http proxy cache/) 27 | ->write_file_expand('nginx.conf', <<'EOF'); 28 | 29 | %%TEST_GLOBALS%% 30 | 31 | daemon off; 32 | 33 | events { 34 | } 35 | 36 | http { 37 | %%TEST_GLOBALS_HTTP%% 38 | 39 | proxy_cache_path %%TESTDIR%%/cache levels=1:2 min_free=4k 40 | keys_zone=NAME:1m; 41 | 42 | server { 43 | listen 127.0.0.1:8080; 44 | server_name localhost; 45 | 46 | location / { 47 | proxy_pass http://127.0.0.1:8081; 48 | 49 | proxy_cache NAME; 50 | 51 | proxy_cache_valid any 1m; 52 | 53 | add_header X-Cache-Status $upstream_cache_status; 54 | } 55 | } 56 | 57 | server { 58 | listen 127.0.0.1:8081; 59 | server_name localhost; 60 | 61 | location / { } 62 | } 63 | } 64 | 65 | EOF 66 | 67 | $t->write_file('t.html', 'SEE-THIS'); 68 | $t->run()->plan(2); 69 | 70 | ############################################################################### 71 | 72 | like(http_get('/t.html'), qr/SEE-THIS/, 'proxy request'); 73 | 74 | $t->write_file('t.html', 'NOOP'); 75 | like(http_get('/t.html'), qr/SEE-THIS/, 'proxy request cached'); 76 | 77 | ############################################################################### 78 | -------------------------------------------------------------------------------- /test/nginx-tests/proxy_protocol_ipv6.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for haproxy protocol on IPv6 listening socket. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | 21 | ############################################################################### 22 | 23 | select STDERR; $| = 1; 24 | select STDOUT; $| = 1; 25 | 26 | my $t = Test::Nginx->new()->has(qw/http realip stream/); 27 | 28 | $t->write_file_expand('nginx.conf', <<'EOF'); 29 | 30 | %%TEST_GLOBALS%% 31 | 32 | daemon off; 33 | 34 | events { 35 | } 36 | 37 | http { 38 | %%TEST_GLOBALS_HTTP%% 39 | 40 | server { 41 | listen [::1]:%%PORT_8080%% proxy_protocol; 42 | server_name localhost; 43 | 44 | add_header X-IP $remote_addr; 45 | add_header X-PP $proxy_protocol_addr; 46 | real_ip_header proxy_protocol; 47 | 48 | location / { } 49 | location /pp { 50 | set_real_ip_from ::1/128; 51 | error_page 404 =200 /t; 52 | } 53 | } 54 | } 55 | 56 | stream { 57 | %%TEST_GLOBALS_STREAM%% 58 | 59 | server { 60 | listen 127.0.0.1:8080; 61 | proxy_pass [::1]:%%PORT_8080%%; 62 | 63 | proxy_protocol on; 64 | } 65 | } 66 | 67 | EOF 68 | 69 | $t->write_file('t', 'SEE-THIS'); 70 | $t->try_run('no inet6 support')->plan(3); 71 | 72 | ############################################################################### 73 | 74 | my $r = http_get('/t'); 75 | like($r, qr/X-IP: ::1/, 'realip'); 76 | like($r, qr/X-PP: 127.0.0.1/, 'proxy protocol'); 77 | 78 | $r = http_get('/pp'); 79 | like($r, qr/X-IP: 127.0.0.1/, 'proxy protocol realip'); 80 | 81 | ############################################################################### 82 | -------------------------------------------------------------------------------- /test/nginx-tests/random_index.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Maxim Dounin 5 | 6 | # Tests for random index module. 7 | 8 | ############################################################################### 9 | 10 | use warnings; 11 | use strict; 12 | 13 | use Test::More; 14 | 15 | BEGIN { use FindBin; chdir($FindBin::Bin); } 16 | 17 | use lib 'lib'; 18 | use Test::Nginx; 19 | 20 | ############################################################################### 21 | 22 | select STDERR; $| = 1; 23 | select STDOUT; $| = 1; 24 | 25 | my $t = Test::Nginx->new()->has(qw/http random_index symlink/)->plan(1) 26 | ->write_file_expand('nginx.conf', <<'EOF'); 27 | 28 | %%TEST_GLOBALS%% 29 | 30 | daemon off; 31 | 32 | events { 33 | } 34 | 35 | http { 36 | %%TEST_GLOBALS_HTTP%% 37 | 38 | server { 39 | listen 127.0.0.1:8080; 40 | server_name localhost; 41 | 42 | location / { 43 | random_index on; 44 | } 45 | } 46 | } 47 | 48 | EOF 49 | 50 | my $d = $t->testdir(); 51 | 52 | mkdir("$d/x"); 53 | mkdir("$d/x/test-dir"); 54 | symlink("$d/x/test-dir", "$d/x/test-dir-link"); 55 | 56 | $t->write_file('test-file', 'RIGHT'); 57 | symlink("$d/test-file", "$d/x/test-file-link"); 58 | 59 | $t->run(); 60 | 61 | ############################################################################### 62 | 63 | like(http_get('/x/'), qr/RIGHT/s, 'file'); 64 | 65 | ############################################################################### 66 | -------------------------------------------------------------------------------- /test/nginx-tests/ssi_waited.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Maxim Dounin 5 | 6 | # Tests for nginx ssi module, waited subrequests. 7 | 8 | ############################################################################### 9 | 10 | use warnings; 11 | use strict; 12 | 13 | use Test::More; 14 | 15 | BEGIN { use FindBin; chdir($FindBin::Bin); } 16 | 17 | use lib 'lib'; 18 | use Test::Nginx; 19 | 20 | ############################################################################### 21 | 22 | select STDERR; $| = 1; 23 | select STDOUT; $| = 1; 24 | 25 | my $t = Test::Nginx->new()->has(qw/http ssi/)->plan(1); 26 | 27 | $t->write_file_expand('nginx.conf', <<'EOF'); 28 | 29 | %%TEST_GLOBALS%% 30 | 31 | daemon off; 32 | 33 | events { 34 | } 35 | 36 | http { 37 | %%TEST_GLOBALS_HTTP%% 38 | 39 | server { 40 | listen 127.0.0.1:8080; 41 | server_name localhost; 42 | location / { 43 | ssi on; 44 | } 45 | } 46 | } 47 | 48 | EOF 49 | 50 | $t->write_file('index.html', 'x' . 51 | 'xx'); 52 | $t->write_file('first.html', 'FIRST'); 53 | $t->write_file('second.html', 54 | 'xSECOND'); 55 | $t->write_file('waited.html', 'WAITED'); 56 | 57 | $t->run(); 58 | 59 | ############################################################################### 60 | 61 | like(http_get('/'), qr/^xFIRSTxWAITEDxSECONDx$/m, 'waited non-active'); 62 | 63 | ############################################################################### 64 | -------------------------------------------------------------------------------- /test/nginx-tests/stream_access_log_escape.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Stream tests for access_log with escape parameter. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | 21 | ############################################################################### 22 | 23 | select STDERR; $| = 1; 24 | select STDOUT; $| = 1; 25 | 26 | my $t = Test::Nginx->new()->has(qw/stream stream_map stream_return/) 27 | ->write_file_expand('nginx.conf', <<'EOF'); 28 | 29 | %%TEST_GLOBALS%% 30 | 31 | daemon off; 32 | 33 | events { 34 | } 35 | 36 | stream { 37 | %%TEST_GLOBALS_STREAM%% 38 | 39 | map $pid $a { 40 | default '" \ "'; 41 | } 42 | map $pid $b { 43 | default "foo"; 44 | } 45 | 46 | log_format json escape=json $a$b$upstream_addr; 47 | log_format default escape=default $a$b$upstream_addr; 48 | 49 | server { 50 | listen 127.0.0.1:8080; 51 | return ok; 52 | 53 | access_log %%TESTDIR%%/json.log json; 54 | access_log %%TESTDIR%%/test.log default; 55 | } 56 | } 57 | 58 | EOF 59 | 60 | $t->run()->plan(2); 61 | 62 | ############################################################################### 63 | 64 | http_get('/'); 65 | 66 | $t->stop(); 67 | 68 | is($t->read_file('json.log'), '\" \\\\ \"foo' . "\n", 'json'); 69 | is($t->read_file('test.log'), '\x22 \x5C \x22foo-' . "\n", 'default'); 70 | 71 | ############################################################################### 72 | -------------------------------------------------------------------------------- /test/nginx-tests/stream_access_log_none.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Stream tests for access_log with escape parameter. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | 21 | ############################################################################### 22 | 23 | select STDERR; $| = 1; 24 | select STDOUT; $| = 1; 25 | 26 | my $t = Test::Nginx->new()->has(qw/stream stream_map stream_return/)->plan(1) 27 | ->write_file_expand('nginx.conf', <<'EOF'); 28 | 29 | %%TEST_GLOBALS%% 30 | 31 | daemon off; 32 | 33 | events { 34 | } 35 | 36 | stream { 37 | %%TEST_GLOBALS_STREAM%% 38 | 39 | map $pid $a { 40 | default '" \ "'; 41 | } 42 | map $pid $b { 43 | default "foo"; 44 | } 45 | 46 | log_format none escape=none $a$b$upstream_addr; 47 | 48 | server { 49 | listen 127.0.0.1:8080; 50 | return ok; 51 | 52 | access_log %%TESTDIR%%/none.log none; 53 | } 54 | } 55 | 56 | EOF 57 | 58 | $t->run(); 59 | 60 | ############################################################################### 61 | 62 | http_get('/'); 63 | 64 | $t->stop(); 65 | 66 | is($t->read_file('none.log'), '" \\ "foo' . "\n", 'none'); 67 | 68 | ############################################################################### 69 | -------------------------------------------------------------------------------- /test/nginx-tests/stream_proxy_bind.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Andrey Zelenkov 5 | # (C) Nginx, Inc. 6 | 7 | # Test for stream proxy_bind directive. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | 21 | ############################################################################### 22 | 23 | select STDERR; $| = 1; 24 | select STDOUT; $| = 1; 25 | 26 | plan(skip_all => 'win32') if $^O eq 'MSWin32'; 27 | plan(skip_all => '127.0.0.2 local address required') 28 | unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' ); 29 | 30 | my $t = Test::Nginx->new()->has(qw/http proxy stream/)->plan(1) 31 | ->write_file_expand('nginx.conf', <<'EOF'); 32 | 33 | %%TEST_GLOBALS%% 34 | 35 | daemon off; 36 | 37 | events { 38 | } 39 | 40 | stream { 41 | %%TEST_GLOBALS_STREAM%% 42 | 43 | server { 44 | listen 127.0.0.1:8081; 45 | proxy_bind 127.0.0.2; 46 | proxy_pass 127.0.0.1:8082; 47 | } 48 | } 49 | 50 | http { 51 | %%TEST_GLOBALS_HTTP%% 52 | 53 | server { 54 | listen 127.0.0.1:8080; 55 | server_name localhost; 56 | 57 | location / { 58 | proxy_pass http://127.0.0.1:8081; 59 | } 60 | } 61 | 62 | server { 63 | listen 127.0.0.1:8082; 64 | 65 | location / { 66 | add_header X-IP $remote_addr; 67 | } 68 | } 69 | } 70 | 71 | EOF 72 | 73 | $t->write_file('index.html', ''); 74 | $t->run(); 75 | 76 | ############################################################################### 77 | 78 | like(http_get('/'), qr/X-IP: 127.0.0.2/, 'bind'); 79 | 80 | ############################################################################### 81 | -------------------------------------------------------------------------------- /test/nginx-tests/stream_set.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Vladimir Kokshenev 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for stream set directive. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | use Test::Nginx::Stream qw/ stream /; 21 | 22 | ############################################################################### 23 | 24 | select STDERR; $| = 1; 25 | select STDOUT; $| = 1; 26 | 27 | my $t = Test::Nginx->new() 28 | ->has(qw/stream stream_return stream_map stream_set/); 29 | 30 | $t->write_file_expand('nginx.conf', <<'EOF'); 31 | 32 | %%TEST_GLOBALS%% 33 | 34 | daemon off; 35 | 36 | events { 37 | } 38 | 39 | stream { 40 | %%TEST_GLOBALS_STREAM%% 41 | 42 | map 0 $map_var { 43 | default "original"; 44 | } 45 | 46 | server { 47 | listen 127.0.0.1:8082; 48 | return $map_var:$set_var; 49 | 50 | set $set_var $map_var; 51 | set $map_var "new"; 52 | } 53 | 54 | server { 55 | listen 127.0.0.1:8083; 56 | return $set_var; 57 | } 58 | } 59 | 60 | EOF 61 | 62 | $t->run()->plan(2); 63 | 64 | ############################################################################### 65 | 66 | is(stream('127.0.0.1:' . port(8082))->read(), 'new:original', 'set'); 67 | is(stream('127.0.0.1:' . port(8083))->read(), '', 'uninitialized variable'); 68 | 69 | ############################################################################### 70 | -------------------------------------------------------------------------------- /test/nginx-tests/stream_split_clients.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for stream split_client module. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | use Test::Nginx::Stream qw/ stream /; 21 | 22 | ############################################################################### 23 | 24 | select STDERR; $| = 1; 25 | select STDOUT; $| = 1; 26 | 27 | my $t = Test::Nginx->new()->has(qw/stream stream_split_clients stream_return/); 28 | 29 | $t->write_file_expand('nginx.conf', <<'EOF'); 30 | 31 | %%TEST_GLOBALS%% 32 | 33 | daemon off; 34 | 35 | events { 36 | } 37 | 38 | stream { 39 | %%TEST_GLOBALS_STREAM%% 40 | 41 | split_clients $connection $variant { 42 | 51.2% "first"; 43 | 10% "second"; 44 | * "third"; 45 | } 46 | 47 | server { 48 | listen 127.0.0.1:8080; 49 | return $variant; 50 | } 51 | } 52 | 53 | EOF 54 | 55 | $t->run(); 56 | $t->plan(1); 57 | 58 | ############################################################################### 59 | 60 | # NB: split_clients distribution is a subject to implementation details 61 | 62 | like(many('/', 20), qr/first: 12, second: 2, third: 6/, 'split'); 63 | 64 | ############################################################################### 65 | 66 | sub many { 67 | my ($uri, $count) = @_; 68 | my %dist; 69 | 70 | for (1 .. $count) { 71 | if (my $data = stream('127.0.0.1:' . port(8080))->read()) { 72 | $dist{$data} = 0 unless defined $data; 73 | $dist{$data}++; 74 | } 75 | } 76 | 77 | return join ', ', map { $_ . ": " . $dist{$_} } sort keys %dist; 78 | } 79 | 80 | ############################################################################### 81 | -------------------------------------------------------------------------------- /test/nginx-tests/stream_udp_wildcard.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for stream proxy module with datagrams, source address selection. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | use Test::Nginx::Stream qw/ dgram /; 21 | 22 | ############################################################################### 23 | 24 | select STDERR; $| = 1; 25 | select STDOUT; $| = 1; 26 | 27 | plan(skip_all => '127.0.0.2 local address required') 28 | unless defined IO::Socket::INET->new( LocalAddr => '127.0.0.2' ); 29 | 30 | plan(skip_all => 'listen on wildcard address') 31 | unless $ENV{TEST_NGINX_UNSAFE}; 32 | 33 | my $t = Test::Nginx->new()->has(qw/stream stream_return udp/)->plan(1) 34 | ->write_file_expand('nginx.conf', <<'EOF'); 35 | 36 | %%TEST_GLOBALS%% 37 | 38 | daemon off; 39 | 40 | events { 41 | } 42 | 43 | stream { 44 | %%TEST_GLOBALS_STREAM%% 45 | 46 | server { 47 | listen %%PORT_8999_UDP%% udp; 48 | return $server_addr; 49 | } 50 | } 51 | 52 | EOF 53 | 54 | $t->run(); 55 | 56 | ############################################################################### 57 | 58 | my $s = dgram( 59 | LocalAddr => '127.0.0.1', 60 | PeerAddr => '127.0.0.2:' . port(8999) 61 | ); 62 | 63 | is($s->io('test'), '127.0.0.2', 'stream udp wildcard'); 64 | 65 | ############################################################################### 66 | -------------------------------------------------------------------------------- /test/nginx-tests/sub_filter_merge.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Test for sub_filter inheritance from http context. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | 21 | ############################################################################### 22 | 23 | select STDERR; $| = 1; 24 | select STDOUT; $| = 1; 25 | 26 | my $t = Test::Nginx->new()->has(qw/http sub/); 27 | 28 | $t->plan(1)->write_file_expand('nginx.conf', <<'EOF'); 29 | 30 | %%TEST_GLOBALS%% 31 | 32 | daemon off; 33 | 34 | events { 35 | } 36 | 37 | http { 38 | %%TEST_GLOBALS_HTTP%% 39 | 40 | sub_filter foo bar; 41 | 42 | server { 43 | listen 127.0.0.1:8080; 44 | server_name localhost; 45 | 46 | location / { } 47 | } 48 | } 49 | 50 | EOF 51 | 52 | $t->write_file('foo.html', 'foo'); 53 | $t->run(); 54 | 55 | ############################################################################### 56 | 57 | like(http_get('/foo.html'), qr/bar/, 'sub_filter inheritance'); 58 | 59 | ############################################################################### 60 | -------------------------------------------------------------------------------- /test/nginx-tests/upstream_zone.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for upstream zone. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | 21 | ############################################################################### 22 | 23 | select STDERR; $| = 1; 24 | select STDOUT; $| = 1; 25 | 26 | my $t = Test::Nginx->new()->has(qw/http proxy upstream_zone/)->plan(2) 27 | ->write_file_expand('nginx.conf', <<'EOF'); 28 | 29 | %%TEST_GLOBALS%% 30 | 31 | daemon off; 32 | 33 | events { 34 | } 35 | 36 | http { 37 | %%TEST_GLOBALS_HTTP%% 38 | 39 | upstream u { 40 | zone u 1m; 41 | server 127.0.0.1:8081; 42 | } 43 | 44 | upstream u2 { 45 | zone u; 46 | server 127.0.0.1:8081 down; 47 | server 127.0.0.1:8081 backup down; 48 | } 49 | 50 | server { 51 | listen 127.0.0.1:8081; 52 | server_name localhost; 53 | 54 | location / {} 55 | } 56 | 57 | server { 58 | listen 127.0.0.1:8080; 59 | server_name localhost; 60 | 61 | add_header X-Name $upstream_addr always; 62 | 63 | location / { 64 | proxy_pass http://u/; 65 | } 66 | 67 | location /down { 68 | proxy_pass http://u2/; 69 | } 70 | } 71 | } 72 | 73 | EOF 74 | 75 | $t->write_file('index.html', ''); 76 | $t->run(); 77 | 78 | ############################################################################### 79 | 80 | my $p = port(8081); 81 | 82 | like(http_get('/'), qr/X-Name: 127.0.0.1:$p/, 'upstream name'); 83 | like(http_get('/down'), qr/X-Name: u2/, 'no live upstreams'); 84 | 85 | ############################################################################### 86 | -------------------------------------------------------------------------------- /test/nginx-tests/worker_shutdown_timeout.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for worker_shutdown_timeout directive. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | use IO::Select; 17 | 18 | BEGIN { use FindBin; chdir($FindBin::Bin); } 19 | 20 | use lib 'lib'; 21 | use Test::Nginx; 22 | 23 | ############################################################################### 24 | 25 | select STDERR; $| = 1; 26 | select STDOUT; $| = 1; 27 | 28 | my $t = Test::Nginx->new()->has(qw/http/) 29 | ->write_file_expand('nginx.conf', <<'EOF'); 30 | 31 | %%TEST_GLOBALS%% 32 | 33 | daemon off; 34 | worker_shutdown_timeout 10ms; 35 | 36 | events { 37 | } 38 | 39 | http { 40 | %%TEST_GLOBALS_HTTP%% 41 | 42 | server { 43 | listen 127.0.0.1:8080; 44 | server_name localhost; 45 | 46 | location / { } 47 | } 48 | } 49 | 50 | EOF 51 | 52 | $t->run()->plan(1); 53 | 54 | ############################################################################### 55 | 56 | my $s = http('', start => 1); 57 | 58 | select undef, undef, undef, 10; 59 | 60 | $t->reload(); 61 | 62 | if (IO::Select->new($s)->can_read(5)) { 63 | Test::Nginx::log_core('||', "select: can_read"); 64 | } 65 | 66 | is(http_get('/', socket => $s) || '', '', 'worker_shutdown_timeout'); 67 | 68 | ############################################################################### 69 | -------------------------------------------------------------------------------- /test/nginx-tests/worker_shutdown_timeout_stream.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Copyright (C) Intel, Inc. 4 | # (C) Sergey Kandaurov 5 | # (C) Nginx, Inc. 6 | 7 | # Tests for worker_shutdown_timeout directive within the stream module. 8 | 9 | ############################################################################### 10 | 11 | use warnings; 12 | use strict; 13 | 14 | use Test::More; 15 | 16 | BEGIN { use FindBin; chdir($FindBin::Bin); } 17 | 18 | use lib 'lib'; 19 | use Test::Nginx; 20 | use Test::Nginx::SMTP; 21 | 22 | ############################################################################### 23 | 24 | select STDERR; $| = 1; 25 | select STDOUT; $| = 1; 26 | 27 | local $SIG{PIPE} = 'IGNORE'; 28 | 29 | my $t = Test::Nginx->new()->has(qw/stream/)->plan(3) 30 | ->write_file_expand('nginx.conf', <<'EOF'); 31 | 32 | %%TEST_GLOBALS%% 33 | 34 | daemon off; 35 | worker_shutdown_timeout 10ms; 36 | 37 | events { 38 | } 39 | 40 | stream { 41 | %%TEST_GLOBALS_STREAM%% 42 | 43 | server { 44 | listen 127.0.0.1:8025; 45 | proxy_pass 127.0.0.1:8026; 46 | } 47 | } 48 | 49 | EOF 50 | 51 | $t->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon); 52 | $t->run()->waitforsocket('127.0.0.1:' . port(8026)); 53 | 54 | ############################################################################### 55 | 56 | my $s = Test::Nginx::SMTP->new(); 57 | $s->check(qr/^220 /, "greeting"); 58 | 59 | $s->send('EHLO example.com'); 60 | $s->check(qr/^250 /, "ehlo"); 61 | 62 | $t->reload(); 63 | 64 | ok($s->can_read(), 'stream connection shutdown'); 65 | 66 | undef $s; 67 | 1; 68 | 69 | ############################################################################### 70 | --------------------------------------------------------------------------------