diff --git a/.gitignore b/.gitignore index 2e4c5c58..c6b9ea1d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ libhttp *-cache -out *.dmg *.msi *.exe @@ -10,6 +9,11 @@ out [tT]esting *~ +obj/*.o +obj/*.obj +lib/*.lib +lib/*.a + ################# ## Eclipse diff --git a/Makefile b/Makefile index 141f249e..0af240d9 100644 --- a/Makefile +++ b/Makefile @@ -1,45 +1,391 @@ # +# Library: libhttp +# File: Makefile +# Author: Lammert Bies +# +# This file is licensed under the MIT License as stated below +# # Copyright (c) 2016 Lammert Bies -# Copyright (c) 2013 No Face Press, LLC -# License http://opensource.org/licenses/mit-license.php MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# Description +# ----------- +# This Makefile is used to build the libhttp library. The only action you should +# normally have to do is to run the make program from the command line, +# independent on the Operating System you are working on. +# +# This Makefile is manually maintained. No autoconf or automake involved. This +# was a deliberate decision due to the absense of these tools on some systems, +# in particular in Windows environments. +# +# Dependencies +# ------------ +# This Makefile is known to be functional with GNU Make. Other make utilities +# may work or may have problems. GNU Make is available both in source code +# and precompiled binaries for a large number of environments and therefore +# you are recommended to install a version of GNU Make if you encounter +# problems with the default make utility in your development chain. +# +# Aside from GNU Make and the standard C compiler headers and libraries which +# should have been installed already together with your compiler there are no +# other known dependencies. +# +# Library Type +# ------------ +# The generated library is a library useable for static linking in this +# source directory structure. The decision for a static linkable library +# was deliberate because of the relatively small size of the library and the +# routines and to avoid version and dependency issues when distributing the +# end application to different environments. # -# -# For help try, "make help" -# - -include resources/Makefile.in-os - -CPROG = libhttp -#CXXPROG = libhttp -UNIT_TEST_PROG = libhttp_test - -BUILD_DIR = out - -# Installation directories by convention -# http://www.gnu.org/prep/standards/html_node/Directory-Variables.html -PREFIX = /usr/local -EXEC_PREFIX = $(PREFIX) -BINDIR = $(EXEC_PREFIX)/bin -DATAROOTDIR = $(PREFIX)/share -DOCDIR = $(DATAROOTDIR)/doc/$(CPROG) -SYSCONFDIR = $(PREFIX)/etc -HTMLDIR = $(DOCDIR) - -# build tools -MKDIR = mkdir -p -RMF = rm -f -RMRF = rm -rf - -# desired configuration of the document root -# never assume that the document_root actually -# exists on the build machine. When building -# a chroot, PREFIX if just a directory which -# later becomes /. DOCUMENT_ROOT = $(HTMLDIR) PORTS = 8080 -BUILD_DIRS = $(BUILD_DIR) $(BUILD_DIR)/src $(BUILD_DIR)/resources +# only set main compile options if none were chosen + +LIBS = -lpthread -lm + +ifdef CONFIG_FILE + CFLAGS += -DCONFIG_FILE=\"$(CONFIG_FILE)\" +endif + +ifdef CONFIG_FILE2 + CFLAGS += -DCONFIG_FILE2=\"$(CONFIG_FILE2)\" +endif + +ifdef SSL_LIB + CFLAGS += -DSSL_LIB=\"$(SSL_LIB)\" +endif + +ifdef CRYPTO_LIB + CFLAGS += -DCRYPTO_LIB=\"$(CRYPTO_LIB)\" +endif + +ifneq ($(OS),Windows_NT) +OS:=$(shell uname -s) +endif + +DFLAGS = -DUSE_STACK_SIZE=102400 -DUSE_WEBSOCKET -DUSE_IPV6 + +INCDIR = include/ +LIBDIR = lib/ +OBJDIR = obj/ +SRCDIR = src/ +CC = cc +RM = /bin/rm -f +OBJEXT = .o +LIBEXT = .a +OFLAG = -o +AR = ar +ARQC = qc +ARQ = q +RANLIB = ranlib + +CFLAGS= -Wall \ + -Wextra \ + -Wstrict-prototypes \ + -Wshadow \ + -Wpointer-arith \ + -Wformat-security \ + -Winit-self \ + -Wcast-qual \ + -Wcast-align \ + -Wwrite-strings \ + -Wnested-externs \ + -Wredundant-decls \ + -Werror \ + -O3 \ + -funsigned-char \ + -I${INCDIR} + +ifeq ($(OS),Windows_NT) +INCDIR = include\\ +LIBDIR = lib\\ +OBJDIR = obj\\ +SRCDIR = src\\ +CC = cl +RM = del /q +OBJEXT = .obj +LIBEXT = .lib +OFLAG = -Fo +AR = lib +ARQC = /NOLOGO /OUT: +ARQ = /NOLOGO +RANLIB = dir + +CFLAGS = -Ox -Ot -MT -GT -volatile:iso -I${INCDIR} -nologo -J -sdl -Wall -WX -wd4464 -wd4710 -wd4711 -wd4201 -wd4820 +endif + +${OBJDIR}%${OBJEXT} : ${SRCDIR}%.c + ${CC} -c ${CPPFLAGS} ${CFLAGS} ${DFLAGS} ${OFLAG}$@ $< + +all: ${LIBDIR}libhttp${LIBEXT} + +clean: + ${RM} ${OBJDIR}*${OBJEXT} + ${RM} ${LIBDIR}libhttp${LIBEXT} + +OBJLIST = \ + ${OBJDIR}extern_md5${OBJEXT} \ + ${OBJDIR}extern_sha1${OBJEXT} \ + ${OBJDIR}extern_ssl_lut${OBJEXT} \ + ${OBJDIR}httplib_accept_new_connection${OBJEXT} \ + ${OBJDIR}httplib_addenv${OBJEXT} \ + ${OBJDIR}httplib_atomic_dec${OBJEXT} \ + ${OBJDIR}httplib_atomic_inc${OBJEXT} \ + ${OBJDIR}httplib_authorize${OBJEXT} \ + ${OBJDIR}httplib_base64_encode${OBJEXT} \ + ${OBJDIR}httplib_check_acl${OBJEXT} \ + ${OBJDIR}httplib_check_authorization${OBJEXT} \ + ${OBJDIR}httplib_check_feature${OBJEXT} \ + ${OBJDIR}httplib_check_password${OBJEXT} \ + ${OBJDIR}httplib_close_all_listening_sockets${OBJEXT} \ + ${OBJDIR}httplib_close_connection${OBJEXT} \ + ${OBJDIR}httplib_close_socket_gracefully${OBJEXT} \ + ${OBJDIR}httplib_closedir${OBJEXT} \ + ${OBJDIR}httplib_compare_dir_entries${OBJEXT} \ + ${OBJDIR}httplib_config_options${OBJEXT} \ + ${OBJDIR}httplib_connect_client${OBJEXT} \ + ${OBJDIR}httplib_connect_socket${OBJEXT} \ + ${OBJDIR}httplib_connect_websocket_client${OBJEXT} \ + ${OBJDIR}httplib_construct_etag${OBJEXT} \ + ${OBJDIR}httplib_consume_socket${OBJEXT} \ + ${OBJDIR}httplib_cry${OBJEXT} \ + ${OBJDIR}httplib_delete_file${OBJEXT} \ + ${OBJDIR}httplib_difftimespec${OBJEXT} \ + ${OBJDIR}httplib_dir_scan_callback${OBJEXT} \ + ${OBJDIR}httplib_discard_unread_request_data${OBJEXT} \ + ${OBJDIR}httplib_download${OBJEXT} \ + ${OBJDIR}httplib_event_queue${OBJEXT} \ + ${OBJDIR}httplib_fc${OBJEXT} \ + ${OBJDIR}httplib_fclose${OBJEXT} \ + ${OBJDIR}httplib_fclose_on_exec${OBJEXT} \ + ${OBJDIR}httplib_fgets${OBJEXT} \ + ${OBJDIR}httplib_fopen${OBJEXT} \ + ${OBJDIR}httplib_forward_body_data${OBJEXT} \ + ${OBJDIR}httplib_free_context${OBJEXT} \ + ${OBJDIR}httplib_get_builtin_mime_type${OBJEXT} \ + ${OBJDIR}httplib_get_context${OBJEXT} \ + ${OBJDIR}httplib_get_cookie${OBJEXT} \ + ${OBJDIR}httplib_get_first_ssl_listener_index${OBJEXT} \ + ${OBJDIR}httplib_get_header${OBJEXT} \ + ${OBJDIR}httplib_get_mime_type${OBJEXT} \ + ${OBJDIR}httplib_get_option${OBJEXT} \ + ${OBJDIR}httplib_get_option_index${OBJEXT} \ + ${OBJDIR}httplib_get_random${OBJEXT} \ + ${OBJDIR}httplib_get_rel_url_at_current_server${OBJEXT} \ + ${OBJDIR}httplib_get_remote_ip${OBJEXT} \ + ${OBJDIR}httplib_get_request_handler${OBJEXT} \ + ${OBJDIR}httplib_get_request_info${OBJEXT} \ + ${OBJDIR}httplib_get_request_len${OBJEXT} \ + ${OBJDIR}httplib_get_response${OBJEXT} \ + ${OBJDIR}httplib_get_response_code_text${OBJEXT} \ + ${OBJDIR}httplib_get_server_ports${OBJEXT} \ + ${OBJDIR}httplib_get_system_name${OBJEXT} \ + ${OBJDIR}httplib_get_uri_type${OBJEXT} \ + ${OBJDIR}httplib_get_user_connection_data${OBJEXT} \ + ${OBJDIR}httplib_get_user_data${OBJEXT} \ + ${OBJDIR}httplib_get_valid_options${OBJEXT} \ + ${OBJDIR}httplib_get_var${OBJEXT} \ + ${OBJDIR}httplib_getreq${OBJEXT} \ + ${OBJDIR}httplib_global_data${OBJEXT} \ + ${OBJDIR}httplib_gmt_time_string${OBJEXT} \ + ${OBJDIR}httplib_handle_cgi_request${OBJEXT} \ + ${OBJDIR}httplib_handle_directory_request${OBJEXT} \ + ${OBJDIR}httplib_handle_file_based_request${OBJEXT} \ + ${OBJDIR}httplib_handle_form_request${OBJEXT} \ + ${OBJDIR}httplib_handle_not_modified_static_file_request${OBJEXT} \ + ${OBJDIR}httplib_handle_propfind${OBJEXT} \ + ${OBJDIR}httplib_handle_request${OBJEXT} \ + ${OBJDIR}httplib_handle_static_file_request${OBJEXT} \ + ${OBJDIR}httplib_handle_websocket_request${OBJEXT} \ + ${OBJDIR}httplib_header_has_option${OBJEXT} \ + ${OBJDIR}httplib_inet_pton${OBJEXT} \ + ${OBJDIR}httplib_initialize_ssl${OBJEXT} \ + ${OBJDIR}httplib_interpret_uri${OBJEXT} \ + ${OBJDIR}httplib_is_authorized_for_put${OBJEXT} \ + ${OBJDIR}httplib_is_file_in_memory${OBJEXT} \ + ${OBJDIR}httplib_is_file_opened${OBJEXT} \ + ${OBJDIR}httplib_is_not_modified${OBJEXT} \ + ${OBJDIR}httplib_is_put_or_delete_method${OBJEXT} \ + ${OBJDIR}httplib_is_valid_http_method${OBJEXT} \ + ${OBJDIR}httplib_is_valid_port${OBJEXT} \ + ${OBJDIR}httplib_is_websocket_protocol${OBJEXT} \ + ${OBJDIR}httplib_join_thread${OBJEXT} \ + ${OBJDIR}httplib_load_dll${OBJEXT} \ + ${OBJDIR}httplib_lock_unlock_connection${OBJEXT} \ + ${OBJDIR}httplib_lock_unlock_context${OBJEXT} \ + ${OBJDIR}httplib_log_access${OBJEXT} \ + ${OBJDIR}httplib_lowercase${OBJEXT} \ + ${OBJDIR}httplib_malloc${OBJEXT} \ + ${OBJDIR}httplib_master_thread${OBJEXT} \ + ${OBJDIR}httplib_match_prefix${OBJEXT} \ + ${OBJDIR}httplib_md5${OBJEXT} \ + ${OBJDIR}httplib_mkcol${OBJEXT} \ + ${OBJDIR}httplib_mkdir${OBJEXT} \ + ${OBJDIR}httplib_modify_passwords_file${OBJEXT} \ + ${OBJDIR}httplib_must_hide_file${OBJEXT} \ + ${OBJDIR}httplib_next_option${OBJEXT} \ + ${OBJDIR}httplib_open_auth_file${OBJEXT} \ + ${OBJDIR}httplib_opendir${OBJEXT} \ + ${OBJDIR}httplib_parse_auth_header${OBJEXT} \ + ${OBJDIR}httplib_parse_date_string${OBJEXT} \ + ${OBJDIR}httplib_parse_http_headers${OBJEXT} \ + ${OBJDIR}httplib_parse_http_message${OBJEXT} \ + ${OBJDIR}httplib_parse_net${OBJEXT} \ + ${OBJDIR}httplib_parse_range_header${OBJEXT} \ + ${OBJDIR}httplib_path_to_unicode${OBJEXT} \ + ${OBJDIR}httplib_poll${OBJEXT} \ + ${OBJDIR}httplib_prepare_cgi_environment${OBJEXT} \ + ${OBJDIR}httplib_print_dir_entry${OBJEXT} \ + ${OBJDIR}httplib_printf${OBJEXT} \ + ${OBJDIR}httplib_process_new_connection${OBJEXT} \ + ${OBJDIR}httplib_produce_socket${OBJEXT} \ + ${OBJDIR}httplib_pull${OBJEXT} \ + ${OBJDIR}httplib_pull_all${OBJEXT} \ + ${OBJDIR}httplib_push_all${OBJEXT} \ + ${OBJDIR}httplib_put_dir${OBJEXT} \ + ${OBJDIR}httplib_put_file${OBJEXT} \ + ${OBJDIR}httplib_read${OBJEXT} \ + ${OBJDIR}httplib_read_auth_file${OBJEXT} \ + ${OBJDIR}httplib_read_request${OBJEXT} \ + ${OBJDIR}httplib_read_websocket${OBJEXT} \ + ${OBJDIR}httplib_readdir${OBJEXT} \ + ${OBJDIR}httplib_realloc2${OBJEXT} \ + ${OBJDIR}httplib_redirect_to_https_port${OBJEXT} \ + ${OBJDIR}httplib_refresh_trust${OBJEXT} \ + ${OBJDIR}httplib_remove${OBJEXT} \ + ${OBJDIR}httplib_remove_bad_file${OBJEXT} \ + ${OBJDIR}httplib_remove_directory${OBJEXT} \ + ${OBJDIR}httplib_remove_double_dots${OBJEXT} \ + ${OBJDIR}httplib_reset_per_request_attributes${OBJEXT} \ + ${OBJDIR}httplib_scan_directory${OBJEXT} \ + ${OBJDIR}httplib_send_authorization_request${OBJEXT} \ + ${OBJDIR}httplib_send_file${OBJEXT} \ + ${OBJDIR}httplib_send_file_data${OBJEXT} \ + ${OBJDIR}httplib_send_http_error${OBJEXT} \ + ${OBJDIR}httplib_send_no_cache_header${OBJEXT} \ + ${OBJDIR}httplib_send_options${OBJEXT} \ + ${OBJDIR}httplib_send_static_cache_header${OBJEXT} \ + ${OBJDIR}httplib_send_websocket_handshake${OBJEXT} \ + ${OBJDIR}httplib_set_acl_option${OBJEXT} \ + ${OBJDIR}httplib_set_auth_handler${OBJEXT} \ + ${OBJDIR}httplib_set_close_on_exec${OBJEXT} \ + ${OBJDIR}httplib_set_gpass_option${OBJEXT} \ + ${OBJDIR}httplib_set_handler_type${OBJEXT} \ + ${OBJDIR}httplib_set_non_blocking_mode${OBJEXT} \ + ${OBJDIR}httplib_set_ports_option${OBJEXT} \ + ${OBJDIR}httplib_set_request_handler${OBJEXT} \ + ${OBJDIR}httplib_set_ssl_option${OBJEXT} \ + ${OBJDIR}httplib_set_sock_timeout${OBJEXT} \ + ${OBJDIR}httplib_set_tcp_nodelay${OBJEXT} \ + ${OBJDIR}httplib_set_thread_name${OBJEXT} \ + ${OBJDIR}httplib_set_throttle${OBJEXT} \ + ${OBJDIR}httplib_set_uid_option${OBJEXT} \ + ${OBJDIR}httplib_set_user_connection_data${OBJEXT} \ + ${OBJDIR}httplib_set_websocket_handler${OBJEXT} \ + ${OBJDIR}httplib_should_decode_url${OBJEXT} \ + ${OBJDIR}httplib_should_keep_alive${OBJEXT} \ + ${OBJDIR}httplib_skip${OBJEXT} \ + ${OBJDIR}httplib_skip_quoted${OBJEXT} \ + ${OBJDIR}httplib_snprintf${OBJEXT} \ + ${OBJDIR}httplib_sockaddr_to_string${OBJEXT} \ + ${OBJDIR}httplib_spawn_process${OBJEXT} \ + ${OBJDIR}httplib_ssi${OBJEXT} \ + ${OBJDIR}httplib_ssl_error${OBJEXT} \ + ${OBJDIR}httplib_ssl_get_client_cert_info${OBJEXT} \ + ${OBJDIR}httplib_ssl_get_protocol${OBJEXT} \ + ${OBJDIR}httplib_ssl_id_callback${OBJEXT} \ + ${OBJDIR}httplib_ssl_locking_callback${OBJEXT} \ + ${OBJDIR}httplib_ssl_use_pem_file${OBJEXT} \ + ${OBJDIR}httplib_sslize${OBJEXT} \ + ${OBJDIR}httplib_start${OBJEXT} \ + ${OBJDIR}httplib_start_thread${OBJEXT} \ + ${OBJDIR}httplib_start_thread_with_id${OBJEXT} \ + ${OBJDIR}httplib_stat${OBJEXT} \ + ${OBJDIR}httplib_stop${OBJEXT} \ + ${OBJDIR}httplib_store_body${OBJEXT} \ + ${OBJDIR}httplib_strlcpy${OBJEXT} \ + ${OBJDIR}httplib_strcasecmp${OBJEXT} \ + ${OBJDIR}httplib_strcasestr${OBJEXT} \ + ${OBJDIR}httplib_strdup${OBJEXT} \ + ${OBJDIR}httplib_strncasecmp${OBJEXT} \ + ${OBJDIR}httplib_strndup${OBJEXT} \ + ${OBJDIR}httplib_substitute_index_file${OBJEXT} \ + ${OBJDIR}httplib_suggest_connection_header${OBJEXT} \ + ${OBJDIR}httplib_timer${OBJEXT} \ + ${OBJDIR}httplib_tls_dtor${OBJEXT} \ + ${OBJDIR}httplib_uninitialize_ssl${OBJEXT} \ + ${OBJDIR}httplib_url_decode${OBJEXT} \ + ${OBJDIR}httplib_url_encode${OBJEXT} \ + ${OBJDIR}httplib_version${OBJEXT} \ + ${OBJDIR}httplib_vprintf${OBJEXT} \ + ${OBJDIR}httplib_vsnprintf${OBJEXT} \ + ${OBJDIR}httplib_websocket_client_thread${OBJEXT} \ + ${OBJDIR}httplib_websocket_client_write${OBJEXT} \ + ${OBJDIR}httplib_websocket_write${OBJEXT} \ + ${OBJDIR}httplib_websocket_write_exec${OBJEXT} \ + ${OBJDIR}httplib_worker_thread${OBJEXT} \ + ${OBJDIR}httplib_write${OBJEXT} \ + ${OBJDIR}osx_clock_gettime${OBJEXT} \ + ${OBJDIR}win32_clock_gettime${OBJEXT} \ + ${OBJDIR}win32_pthread_cond_broadcast${OBJEXT} \ + ${OBJDIR}win32_pthread_cond_destroy${OBJEXT} \ + ${OBJDIR}win32_pthread_cond_init${OBJEXT} \ + ${OBJDIR}win32_pthread_cond_signal${OBJEXT} \ + ${OBJDIR}win32_pthread_cond_timedwait${OBJEXT} \ + ${OBJDIR}win32_pthread_cond_wait${OBJEXT} \ + ${OBJDIR}win32_pthread_getspecific${OBJEXT} \ + ${OBJDIR}win32_pthread_key_create${OBJEXT} \ + ${OBJDIR}win32_pthread_key_delete${OBJEXT} \ + ${OBJDIR}win32_pthread_mutex_destroy${OBJEXT} \ + ${OBJDIR}win32_pthread_mutex_init${OBJEXT} \ + ${OBJDIR}win32_pthread_mutex_lock${OBJEXT} \ + ${OBJDIR}win32_pthread_mutex_trylock${OBJEXT} \ + ${OBJDIR}win32_pthread_mutex_unlock${OBJEXT} \ + ${OBJDIR}win32_pthread_self${OBJEXT} \ + ${OBJDIR}win32_pthread_setspecific${OBJEXT} \ + ${OBJDIR}wince_gmtime${OBJEXT} \ + ${OBJDIR}wince_gmtime_s${OBJEXT} \ + ${OBJDIR}wince_localtime${OBJEXT} \ + ${OBJDIR}wince_localtime_s${OBJEXT} \ + ${OBJDIR}wince_rename${OBJEXT} \ + ${OBJDIR}wince_stat${OBJEXT} \ + ${OBJDIR}wince_strftime${OBJEXT} \ + ${OBJDIR}wince_time${OBJEXT} + +# +# Creation of the library from the individually compiled object files +# + +${LIBDIR}libhttp${LIBEXT} : \ + ${OBJLIST} \ + Makefile + ${RM} ${LIBDIR}libhttp${LIBEXT} + ${AR} ${ARQC}${LIBDIR}libhttp${LIBEXT} ${OBJLIST} + ${RANLIB} ${LIBDIR}libhttp${LIBEXT} + +# +# Individual source files with their header dependencies +# LIB_SOURCES = src/extern_md5.c \ src/extern_sha1.c \ @@ -55,17 +401,31 @@ LIB_SOURCES = src/extern_md5.c \ src/httplib_check_feature.c \ src/httplib_check_password.c \ src/httplib_close_all_listening_sockets.c \ - src/httplib_close_connection.c \ - src/httplib_close_socket_gracefully.c \ + +${OBJDIR}httplib_close_connection${OBJEXT} : ${SRCDIR}httplib_close_connection.c \ + ${SRCDIR}httplib_pthread.h + +TEST= src/httplib_close_socket_gracefully.c \ src/httplib_closedir.c \ src/httplib_compare_dir_entries.c \ src/httplib_config_options.c \ - src/httplib_connect_client.c \ - src/httplib_connect_socket.c \ + + + +${OBJDIR}httplib_connect_client${OBJEXT} : ${SRCDIR}httplib_connect_client.c \ + ${SRCDIR}httplib_pthread.h + +TEST= src/httplib_connect_socket.c \ src/httplib_connect_websocket_client.c \ src/httplib_construct_etag.c \ - src/httplib_consume_socket.c \ - src/httplib_cry.c \ + + +${OBJDIR}httplib_consume_socket${OBJEXT} : ${SRCDIR}httplib_consume_socket.c \ + ${SRCDIR}httplib_pthread.h + + + +TEST= src/httplib_cry.c \ src/httplib_delete_file.c \ src/httplib_difftimespec.c \ src/httplib_dir_scan_callback.c \ @@ -78,8 +438,14 @@ LIB_SOURCES = src/extern_md5.c \ src/httplib_fgets.c \ src/httplib_fopen.c \ src/httplib_forward_body_data.c \ - src/httplib_free_context.c \ - src/httplib_get_builtin_mime_type.c \ + + +${OBJDIR}httplib_free_context${OBJEXT} : ${SRCDIR}httplib_free_context.c \ + ${SRCDIR}httplib_pthread.h + + + +TEST= src/httplib_get_builtin_mime_type.c \ src/httplib_get_context.c \ src/httplib_get_cookie.c \ src/httplib_get_first_ssl_listener_index.c \ @@ -116,8 +482,13 @@ LIB_SOURCES = src/extern_md5.c \ src/httplib_handle_websocket_request.c \ src/httplib_header_has_option.c \ src/httplib_inet_pton.c \ - src/httplib_initialize_ssl.c \ - src/httplib_interpret_uri.c \ + + +${OBJDIR}httplib_initialize_ssl${OBJEXT} : ${SRCDIR}httplib_initialize_ssl.c \ + ${SRCDIR}httplib_pthread.h + + +TEST= src/httplib_interpret_uri.c \ src/httplib_is_authorized_for_put.c \ src/httplib_is_file_in_memory.c \ src/httplib_is_file_opened.c \ @@ -128,13 +499,30 @@ LIB_SOURCES = src/extern_md5.c \ src/httplib_is_websocket_protocol.c \ src/httplib_join_thread.c \ src/httplib_load_dll.c \ - src/httplib_lock_unlock_connection.c \ - src/httplib_lock_unlock_context.c \ - src/httplib_log_access.c \ + + + +${OBJDIR}httplib_lock_unlock_connection${OBJEXT} : ${SRCDIR}httplib_lock_unlock_connection.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}httplib_lock_unlock_context${OBJEXT} : ${SRCDIR}httplib_lock_unlock_context.c \ + ${SRCDIR}httplib_pthread.h + + + +TEST= src/httplib_log_access.c \ src/httplib_lowercase.c \ src/httplib_malloc.c \ - src/httplib_master_thread.c \ - src/httplib_match_prefix.c \ + + + +${OBJDIR}httplib_master_thread${OBJEXT} : ${SRCDIR}httplib_master_thread.c \ + ${SRCDIR}httplib_pthread.h + + + + +TEST= src/httplib_match_prefix.c \ src/httplib_md5.c \ src/httplib_mkcol.c \ src/httplib_mkdir.c \ @@ -155,8 +543,15 @@ LIB_SOURCES = src/extern_md5.c \ src/httplib_print_dir_entry.c \ src/httplib_printf.c \ src/httplib_process_new_connection.c \ - src/httplib_produce_socket.c \ - src/httplib_pull.c \ + + + +${OBJDIR}httplib_produce_socket${OBJEXT} : ${SRCDIR}httplib_produce_socket.c \ + ${SRCDIR}httplib_pthread.h + + + +TEST= src/httplib_pull.c \ src/httplib_pull_all.c \ src/httplib_push_all.c \ src/httplib_put_dir.c \ @@ -175,8 +570,14 @@ LIB_SOURCES = src/extern_md5.c \ src/httplib_remove_double_dots.c \ src/httplib_reset_per_request_attributes.c \ src/httplib_scan_directory.c \ - src/httplib_send_authorization_request.c \ - src/httplib_send_file.c \ + + + +${OBJDIR}httplib_send_authorization_request${OBJEXT} : ${SRCDIR}httplib_send_authorization_request.c \ + ${SRCDIR}httplib_pthread.h + + +TEST= src/httplib_send_file.c \ src/httplib_send_file_data.c \ src/httplib_send_http_error.c \ src/httplib_send_no_cache_header.c \ @@ -211,11 +612,23 @@ LIB_SOURCES = src/extern_md5.c \ src/httplib_ssl_get_client_cert_info.c \ src/httplib_ssl_get_protocol.c \ src/httplib_ssl_id_callback.c \ - src/httplib_ssl_locking_callback.c \ - src/httplib_ssl_use_pem_file.c \ + + +${OBJDIR}httplib_ssl_locking_callback${OBJEXT} : ${SRCDIR}httplib_ssl_locking_callback.c \ + ${SRCDIR}httplib_pthread.h + + +TEST= src/httplib_ssl_use_pem_file.c \ src/httplib_sslize.c \ - src/httplib_start.c \ - src/httplib_start_thread.c \ + + + +${OBJDIR}httplib_start${OBJEXT} : ${SRCDIR}httplib_start.c \ + ${SRCDIR}httplib_pthread.h + + + +TEST= src/httplib_start_thread.c \ src/httplib_start_thread_with_id.c \ src/httplib_stat.c \ src/httplib_stop.c \ @@ -229,9 +642,18 @@ LIB_SOURCES = src/extern_md5.c \ src/httplib_substitute_index_file.c \ src/httplib_suggest_connection_header.c \ src/httplib_timer.c \ - src/httplib_tls_dtor.c \ - src/httplib_uninitialize_ssl.c \ - src/httplib_url_decode.c \ + + + +${OBJDIR}httplib_tls_dtor${OBJEXT} : ${SRCDIR}httplib_tls_dtor.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}httplib_uninitialize_ssl${OBJEXT} : ${SRCDIR}httplib_uninitialize_ssl.c \ + ${SRCDIR}httplib_pthread.h + + + +TEST= src/httplib_url_decode.c \ src/httplib_url_encode.c \ src/httplib_version.c \ src/httplib_vprintf.c \ @@ -240,27 +662,70 @@ LIB_SOURCES = src/extern_md5.c \ src/httplib_websocket_client_write.c \ src/httplib_websocket_write.c \ src/httplib_websocket_write_exec.c \ - src/httplib_worker_thread.c \ - src/httplib_write.c \ + + + +${OBJDIR}httplib_worker_thread${OBJEXT} : ${SRCDIR}httplib_worker_thread.c \ + ${SRCDIR}httplib_pthread.h + + + +TEST= src/httplib_write.c \ src/osx_clock_gettime.c \ src/win32_clock_gettime.c \ - src/win32_pthread_cond_broadcast.c \ - src/win32_pthread_cond_destroy.c \ - src/win32_pthread_cond_init.c \ - src/win32_pthread_cond_signal.c \ - src/win32_pthread_cond_timedwait.c \ - src/win32_pthread_cond_wait.c \ - src/win32_pthread_getspecific.c \ - src/win32_pthread_key_create.c \ - src/win32_pthread_key_delete.c \ - src/win32_pthread_mutex_destroy.c \ - src/win32_pthread_mutex_init.c \ - src/win32_pthread_mutex_lock.c \ - src/win32_pthread_mutex_trylock.c \ - src/win32_pthread_mutex_unlock.c \ - src/win32_pthread_self.c \ - src/win32_pthread_setspecific.c \ - src/wince_gmtime.c \ + + +${OBJDIR}win32_pthread_cond_broadcast${OBJEXT} : ${SRCDIR}win32_pthread_cond_broadcast.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_cond_destroy${OBJEXT} : ${SRCDIR}win32_pthread_cond_destroy.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_cond_init${OBJEXT} : ${SRCDIR}win32_pthread_cond_init.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_cond_signal${OBJEXT} : ${SRCDIR}win32_pthread_cond_signal.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_cond_timedwait${OBJEXT} : ${SRCDIR}win32_pthread_cond_timedwait.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_cond_wait${OBJEXT} : ${SRCDIR}win32_pthread_cond_wait.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_getspecific${OBJEXT} : ${SRCDIR}win32_pthread_getspecific.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_key_create${OBJEXT} : ${SRCDIR}win32_pthread_key_create.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_key_delete${OBJEXT} : ${SRCDIR}win32_pthread_key_delete.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_mutex_destroy${OBJEXT} : ${SRCDIR}win32_pthread_mutex_destroy.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_mutex_init${OBJEXT} : ${SRCDIR}win32_pthread_mutex_init.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_mutex_lock${OBJEXT} : ${SRCDIR}win32_pthread_mutex_lock.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_mutex_trylock${OBJEXT} : ${SRCDIR}win32_pthread_mutex_trylock.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_mutex_unlock${OBJEXT} : ${SRCDIR}win32_pthread_mutex_unlock.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_self${OBJEXT} : ${SRCDIR}win32_pthread_self.c \ + ${SRCDIR}httplib_pthread.h + +${OBJDIR}win32_pthread_setspecific${OBJEXT} : ${SRCDIR}win32_pthread_setspecific.c \ + ${SRCDIR}httplib_pthread.h + + + +TEST= src/wince_gmtime.c \ src/wince_gmtime_s.c \ src/wince_localtime.c \ src/wince_localtime_s.c \ @@ -268,229 +733,3 @@ LIB_SOURCES = src/extern_md5.c \ src/wince_stat.c \ src/wince_strftime.c \ src/wince_time.c -LIB_INLINE = src/mod_lua.inl src/md5.inl -APP_SOURCES = src/main.c -WINDOWS_RESOURCES = resources/res.rc -UNIT_TEST_SOURCES = test/unit_test.c -SOURCE_DIRS = - -OBJECTS = $(LIB_SOURCES:.c=.o) $(APP_SOURCES:.c=.o) -BUILD_RESOURCES = - -# The unit tests include the source files directly to get visibility to the -# static functions. So we clear OBJECTS so that we don't try to build or link -# with any external object. -ifeq ($(MAKECMDGOALS), unit_test) -OBJECTS = -BUILD_DIRS += $(BUILD_DIR)/test -endif - -# only set main compile options if none were chosen -CFLAGS += -Wall -Wextra -Werror -Wshadow -Wformat-security -Winit-self -Wmissing-prototypes -D$(TARGET_OS) -Iinclude $(COPT) -DUSE_STACK_SIZE=102400 -DUSE_WEBSOCKET - -LIBS = -lpthread -lm - -ifdef WITH_DEBUG - CFLAGS += -g -DDEBUG -else - CFLAGS += -O2 -DNDEBUG -endif - -ifdef WITH_CPP - OBJECTS += src/LibHTTPtServer.o - LCC = $(CXX) -else - LCC = $(CC) -endif - -ifdef WITH_IPV6 - CFLAGS += -DUSE_IPV6 -endif - -ifdef WITH_WEBSOCKET - CFLAGS += -DUSE_WEBSOCKET -endif - -ifdef CONFIG_FILE - CFLAGS += -DCONFIG_FILE=\"$(CONFIG_FILE)\" -endif - -ifdef CONFIG_FILE2 - CFLAGS += -DCONFIG_FILE2=\"$(CONFIG_FILE2)\" -endif - -ifdef SSL_LIB - CFLAGS += -DSSL_LIB=\"$(SSL_LIB)\" -endif - -ifdef CRYPTO_LIB - CFLAGS += -DCRYPTO_LIB=\"$(CRYPTO_LIB)\" -endif - -BUILD_DIRS += $(addprefix $(BUILD_DIR)/, $(SOURCE_DIRS)) -BUILD_OBJECTS = $(addprefix $(BUILD_DIR)/, $(OBJECTS)) -MAIN_OBJECTS = $(addprefix $(BUILD_DIR)/, $(APP_SOURCES:.c=.o)) -LIB_OBJECTS = $(filter-out $(MAIN_OBJECTS), $(BUILD_OBJECTS)) - -ifeq ($(TARGET_OS),LINUX) - LIBS += -lrt -ldl - CAN_INSTALL = 1 -endif - -ifeq ($(TARGET_OS),WIN32) - MKDIR = mkdir - RMF = del /q - RMRF = rmdir /s /q -endif - -ifneq (, $(findstring mingw32, $(shell $(CC) -dumpmachine))) - BUILD_RESOURCES = $(BUILD_DIR)/$(WINDOWS_RESOURCES:.rc=.o) - LIBS += -lws2_32 -mwindows - SHARED_LIB = dll -else - SHARED_LIB = so -endif - -all: build - -help: - @echo "make help show this message" - @echo "make build compile" - @echo "make install install on the system" - @echo "make clean clean up the mess" - @echo "make lib build a static library" - @echo "make slib build a shared library" - @echo "make unit_test build unit tests executable" - @echo "" - @echo " Make Options" - @echo " WITH_DEBUG=1 build with GDB debug support" - @echo " WITH_IPV6=1 with IPV6 support" - @echo " WITH_WEBSOCKET=1 build with web socket support" - @echo " WITH_CPP=1 build library with c++ classes" - @echo " CONFIG_FILE=file use 'file' as the config file" - @echo " CONFIG_FILE2=file use 'file' as the backup config file" - @echo " DOCUMENT_ROOT=/path document root override when installing" - @echo " PORTS=8080 listening ports override when installing" - @echo " SSL_LIB=libssl.so.0 use versioned SSL library" - @echo " CRYPTO_LIB=libcrypto.so.0 system versioned CRYPTO library" - @echo " PREFIX=/usr/local sets the install directory" - @echo " COPT='-DNO_SSL' method to insert compile flags" - @echo "" - @echo " Compile Flags" - @echo " NDEBUG strip off all debug code" - @echo " DEBUG build debug version (very noisy)" - @echo " NO_CGI disable CGI support" - @echo " NO_SSL disable SSL functionality" - @echo " NO_SSL_DL link against system libssl library" - @echo " NO_FILES do not serve files from a directory" - @echo " NO_CACHING disable caching (usefull for systems without timegm())" - @echo " MAX_REQUEST_SIZE maximum header size, default 16384" - @echo "" - @echo " Variables" - @echo " TARGET_OS='$(TARGET_OS)'" - @echo " CFLAGS='$(CFLAGS)'" - @echo " CXXFLAGS='$(CXXFLAGS)'" - @echo " LDFLAGS='$(LDFLAGS)'" - @echo " CC='$(CC)'" - @echo " CXX='$(CXX)'" - -build: $(CPROG) $(CXXPROG) - -unit_test: $(UNIT_TEST_PROG) - -ifeq ($(CAN_INSTALL),1) -install: $(HTMLDIR)/index.html $(SYSCONFDIR)/libhttp.conf - install -d -m 755 "$(DOCDIR)" - install -m 644 *.md "$(DOCDIR)" - install -d -m 755 "$(BINDIR)" - install -m 755 $(CPROG) "$(BINDIR)/" - -# Install target we do not want to overwrite -# as it may be an upgrade -$(HTMLDIR)/index.html: - install -d -m 755 "$(HTMLDIR)" - install -m 644 resources/itworks.html $(HTMLDIR)/index.html - install -m 644 resources/civetweb_64x64.png $(HTMLDIR)/ - -# Install target we do not want to overwrite -# as it may be an upgrade -$(SYSCONFDIR)/libhttp.conf: - install -d -m 755 "$(SYSCONFDIR)" - install -m 644 resources/libhttp.conf "$(SYSCONFDIR)/" - @sed -i 's#^document_root.*$$#document_root $(DOCUMENT_ROOT)#' "$(SYSCONFDIR)/libhttp.conf" - @sed -i 's#^listening_ports.*$$#listening_ports $(PORTS)#' "$(SYSCONFDIR)/libhttp.conf" - -else -install: - @echo "Target not flagged for installation. Use CAN_INSTALL=1 to force" - @echo "As a precaution only LINUX targets are set as installable." - @echo "If the target is linux-like, use CAN_INSTALL=1 option." -endif - -lib: lib$(CPROG).a - -slib: lib$(CPROG).$(SHARED_LIB) - -clean: - $(RMRF) $(BUILD_DIR) - $(eval version=$(shell grep "define LIBHTTP_VERSION" include/libhttp.h | sed 's|.*VERSION "\(.*\)"|\1|g')) - $(eval major=$(shell echo $(version) | cut -d'.' -f1)) - $(RMRF) lib$(CPROG).a - $(RMRF) lib$(CPROG).so - $(RMRF) lib$(CPROG).so.$(major) - $(RMRF) lib$(CPROG).so.$(version).0 - $(RMRF) $(CPROG) - $(RMF) $(UNIT_TEST_PROG) - -distclean: clean - $(RMF) $(CPROG) lib$(CPROG).so lib$(CPROG).a *.dmg *.msi *.exe lib$(CPROG).dll lib$(CPROG).dll.a - $(RMF) $(UNIT_TEST_PROG) - -lib$(CPROG).a: CFLAGS += -fPIC -lib$(CPROG).a: $(LIB_OBJECTS) - @$(RMF) $@ - ar cq $@ $(LIB_OBJECTS) - -lib$(CPROG).so: CFLAGS += -fPIC -lib$(CPROG).so: $(LIB_OBJECTS) - $(eval version=$(shell grep "define LIBHTTP_VERSION" include/libhttp.h | sed 's|.*VERSION "\(.*\)"|\1|g')) - $(eval major=$(shell echo $(version) | cut -d'.' -f1)) - $(LCC) -shared -Wl,-soname,$@.$(major) -o $@.$(version).0 $(CFLAGS) $(LDFLAGS) $(LIB_OBJECTS) - ln -s -f $@.$(major) $@ - ln -s -f $@.$(version).0 $@.$(major) - -lib$(CPROG).dll: CFLAGS += -fPIC -lib$(CPROG).dll: $(LIB_OBJECTS) - $(LCC) -shared -o $@ $(CFLAGS) $(LDFLAGS) $(LIB_OBJECTS) $(LIBS) -Wl,--out-implib,lib$(CPROG).dll.a - -$(UNIT_TEST_PROG): CFLAGS += -Isrc -g -$(UNIT_TEST_PROG): $(LIB_SOURCES) $(LIB_INLINE) $(UNIT_TEST_SOURCES) $(BUILD_OBJECTS) - $(LCC) -o $@ $(CFLAGS) $(LDFLAGS) $(UNIT_TEST_SOURCES) $(BUILD_OBJECTS) $(LIBS) - -$(CPROG): $(BUILD_OBJECTS) $(BUILD_RESOURCES) - $(LCC) -o $@ $(CFLAGS) $(LDFLAGS) $(BUILD_OBJECTS) $(BUILD_RESOURCES) $(LIBS) - -$(CXXPROG): $(BUILD_OBJECTS) - $(CXX) -o $@ $(CFLAGS) $(LDFLAGS) $(BUILD_OBJECTS) $(LIBS) - -$(BUILD_OBJECTS): $(BUILD_DIRS) - -$(BUILD_DIRS): - -@$(MKDIR) "$@" - -$(BUILD_DIR)/%.o : %.cpp - $(CXX) -c $(CFLAGS) $(CXXFLAGS) $< -o $@ - -$(BUILD_DIR)/%.o : %.c - $(CC) -c $(CFLAGS) $< -o $@ - -$(BUILD_RESOURCES) : $(WINDOWS_RESOURCES) - windres $(WINDRES_FLAGS) $< $@ - -# This rules is used to keep the code formatted in a reasonable manor -# For this to work astyle must be installed and in the path -# http://sourceforge.net/projects/astyle -indent: - astyle --suffix=none --style=linux --indent=spaces=4 --lineend=linux include/*.h src/*.c src/*.cpp src/*.inl examples/*/*.c examples/*/*.cpp - -.PHONY: all help build install clean lib so diff --git a/build b/build deleted file mode 100755 index 2b423108..00000000 --- a/build +++ /dev/null @@ -1,138 +0,0 @@ -#!/bin/sh -set -euo pipefail -IFS=$'\n\t' - -stdout() { - cat <<< "$@" -} - -stderr() { - cat <<< "$@" 1>&2 -} - -prereqs () { - local E_BADARGS=65 - if [ $# -eq 0 ]; then - stderr "Usage: $(basename $0) [prerequisite_program] [another_program...]" - return $E_BADARGS - fi - for prog in $@; do - hash $prog 2>&- - if [ $? -ne 0 ]; then - return 1 - fi - done -} - -usage() { - if [ $# -ne 0 ]; then - stdout $@ - fi - stdout "Usage: $(basename $0) [options]" - stdout - stdout "A convenience script to quickly build the library with CMake." - stdout - stdout "Options:" - stdout " [--shared|(--static)] Builds either a static or a shared library" - stdout " [--debug|(--release)] Builds a certain variant of the library" - stdout " -g,--generator name The CMake generator to use ('Unix Makefiles')" - stdout " -o,--output folder The place to output the build files (./output)" - stdout - stdout "Examples:" - stdout " ./build" - stdout " ./build --shared --debug" - stdout " ./build --static --release -o ~/my-output-folder" -} - -check() { - local E_BADARGS=65 - if [ $# -ne 1 ]; then - stderr "Usage: check prerequisite_program" - return $E_BADARGS - fi - prereqs $1 - if [ $? -ne 0 ]; then - stderr "Failed to find `$1` on the command line:" - stderr "Please install it with your package manager" - return 1 - fi -} - -sanitize() { - local E_BADARGS=65 - if [ $# -ne 1 ]; then - stderr "Usage: sanitize string_to_clean" - return $E_BADARGS - fi - echo $(echo "$1" | sed "s|[^A-Za-z]\+|-|g" | tr '[:upper:]' '[:lower:]') - return 0 -} - -build () { - # Get the build locations - local src_dir=$(cd $(dirname $0); pwd -P) - - # Arguments - local E_BADARGS=65 - local generator="Unix Makefiles" - local shared=NO - local build_type=Release - local output_dir="${src_dir}/output" - while (( "$#" )); do - case "$1" in - --debug) build_type=Release;; - --release) build_type=Debug;; - --shared) shared=YES;; - --static) shared=NO;; - --output) shift; out="$1";; - -o) shift; output_dir="$1";; - --generator) shift; generator="$1";; - -g) shift; generator="$1";; - --help) usage; return 0;; - --) shift; break;; - -*) usage "Bad argument $1"; return ${E_BADARGS};; - *) break;; - esac - shift - done - - # Update the build folder - local build_dir=${output_dir}/build - local install_dir=${output_dir}/install - - # Create the build folder - mkdir -p ${build_dir} - - # Enter the build folder - cd ${build_dir} - trap 'cd ${src_dir}' INT TERM EXIT - - # Do the CMake configuration - check cmake - cmake -G ${generator} -DCMAKE_BUILD_TYPE=${build_type} -DBUILD_SHARED_LIBS:BOOL=${shared} ${src_dir} - - # Do the build - if [ "${generator}" = "Unix Makefiles" ]; then - check make - make all test - else - stderr "Unknown build system for ${generator}, go to ${build_dir} and run the correct build program" - fi - - # Do the install - cmake -DCMAKE_INSTALL_PREFIX="${install_dir}" -P "${build_dir}/cmake_install.cmake" - - # Return to the correct folder - trap - INT TERM EXIT - cd ${src_dir} - - # Notify the user - stdout "Built files are available at ${install_dir}" -} - -# If the script was not sourced we need to run the function -case "$0" in - *"build") - build "$@" - ;; -esac diff --git a/lib/README b/lib/README new file mode 100644 index 00000000..9e7a4eb8 --- /dev/null +++ b/lib/README @@ -0,0 +1,3 @@ +# +# Directory for the library file +# diff --git a/obj/README b/obj/README new file mode 100644 index 00000000..5c5d4ee6 --- /dev/null +++ b/obj/README @@ -0,0 +1,3 @@ +# +# Directory for object files +# diff --git a/src/httplib_close_connection.c b/src/httplib_close_connection.c index a61b60ef..791a846e 100644 --- a/src/httplib_close_connection.c +++ b/src/httplib_close_connection.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + /* diff --git a/src/httplib_close_socket_gracefully.c b/src/httplib_close_socket_gracefully.c index d3ff3103..8af9fc58 100644 --- a/src/httplib_close_socket_gracefully.c +++ b/src/httplib_close_socket_gracefully.c @@ -74,7 +74,7 @@ void XX_httplib_close_socket_gracefully( struct mg_connection *conn ) { * when server decides to close the connection; then when client * does recv() it gets no data back. */ do { - n = pull( NULL, conn, buf, sizeof(buf), 1E-10 /* TODO: allow 0 as timeout */); + n = XX_httplib_pull( NULL, conn, buf, sizeof(buf), 1E-10 /* TODO: allow 0 as timeout */); } while (n > 0); #endif diff --git a/src/httplib_closedir.c b/src/httplib_closedir.c index 5687d038..6b3ba3cf 100644 --- a/src/httplib_closedir.c +++ b/src/httplib_closedir.c @@ -30,7 +30,7 @@ #if defined(_WIN32) -int mg_closedir(DIR *dir) { +int XX_httplib_closedir( DIR *dir ) { int result = 0; @@ -46,6 +46,6 @@ int mg_closedir(DIR *dir) { return result; -} /* mg_closedir */ +} /* XX_httplib_closedir */ #endif /* _WIN32 */ diff --git a/src/httplib_connect_client.c b/src/httplib_connect_client.c index f5f55a60..390fcf33 100644 --- a/src/httplib_connect_client.c +++ b/src/httplib_connect_client.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + static struct mg_connection * mg_connect_client_impl( const struct mg_client_options *client_options, int use_ssl, char *ebuf, size_t ebuf_len ); diff --git a/src/httplib_consume_socket.c b/src/httplib_consume_socket.c index 32474452..c09fb8e1 100644 --- a/src/httplib_consume_socket.c +++ b/src/httplib_consume_socket.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + /* diff --git a/src/httplib_delete_file.c b/src/httplib_delete_file.c index c9234e62..53ed073b 100644 --- a/src/httplib_delete_file.c +++ b/src/httplib_delete_file.c @@ -74,7 +74,7 @@ void XX_httplib_delete_file( struct mg_connection *conn, const char *path ) { } /* Try to delete it. */ - if (mg_remove(conn, path) == 0) { + if (XX_httplib_remove(conn, path) == 0) { /* Delete was successful: Return 204 without content. */ XX_httplib_send_http_error(conn, 204, "%s", ""); } else { diff --git a/src/httplib_free_context.c b/src/httplib_free_context.c index 3305b1b0..0e9e3b32 100644 --- a/src/httplib_free_context.c +++ b/src/httplib_free_context.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + /* diff --git a/src/httplib_global_data.c b/src/httplib_global_data.c index e0964842..c8491477 100644 --- a/src/httplib_global_data.c +++ b/src/httplib_global_data.c @@ -31,7 +31,7 @@ #ifdef _WIN32 CRITICAL_SECTION global_log_file_lock; -pthread_mutex_undefined_struct * XX_httplib_pthread_mutex_attr = NULL; +struct pthread_mutex_undefined_struct * XX_httplib_pthread_mutex_attr = NULL; #else /* _WIN32 */ pthread_mutexattr_t XX_httplib_pthread_mutex_attr; #endif /* _WIN32 */ diff --git a/src/httplib_handle_cgi_request.c b/src/httplib_handle_cgi_request.c index 4df2faba..7a744574 100644 --- a/src/httplib_handle_cgi_request.c +++ b/src/httplib_handle_cgi_request.c @@ -242,7 +242,7 @@ done: XX_httplib_free(blk.buf); if (pid != (pid_t)-1) { - kill(pid, SIGKILL); + XX_httplib_kill(pid, SIGKILL); #if !defined(_WIN32) { int st; diff --git a/src/httplib_initialize_ssl.c b/src/httplib_initialize_ssl.c index 2f0f87dc..b4514941 100644 --- a/src/httplib_initialize_ssl.c +++ b/src/httplib_initialize_ssl.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #if !defined(NO_SSL) diff --git a/src/httplib_is_websocket_protocol.c b/src/httplib_is_websocket_protocol.c index de7be283..49005adb 100644 --- a/src/httplib_is_websocket_protocol.c +++ b/src/httplib_is_websocket_protocol.c @@ -68,6 +68,8 @@ int XX_httplib_is_websocket_protocol( const struct mg_connection *conn ) { #else /* defined(USE_WEBSOCKET) */ + (void)conn; + return 0; #endif /* defined(USE_WEBSOCKET) */ diff --git a/src/httplib_load_dll.c b/src/httplib_load_dll.c index 37b11c8b..6e41d9e4 100644 --- a/src/httplib_load_dll.c +++ b/src/httplib_load_dll.c @@ -28,6 +28,42 @@ + +#if defined(_WIN32) + +#if !defined(NO_SSL_DL) && !defined(NO_SSL) +/* If SSL is loaded dynamically, dlopen/dlclose is required. */ +/* Create substitutes for POSIX functions in Win32. */ + + +static HANDLE dlopen( const char *dll_name, int flags ) { + + wchar_t wbuf[PATH_MAX]; + + (void)flags; + XX_httplib_path_to_unicode(NULL, dll_name, wbuf, ARRAY_SIZE(wbuf)); + return LoadLibraryW(wbuf); + +} /* dlopen */ + + +static int dlclose( void *handle ) { + + int result; + + if ( FreeLibrary((HMODULE)handle) != 0 ) result = 0; + else result = -1; + + return result; + +} /* dlclose */ + +#endif + +#endif + + + /* * XX_httplib_load_dll( struct mg_context *ctx, const char *dll_name, struct ssl_func *sw ); * @@ -76,38 +112,3 @@ void *XX_httplib_load_dll( struct mg_context *ctx, const char *dll_name, struct #endif /* NO_SSL_DL */ #endif /* !NO_SSL */ - - - -#if defined(_WIN32) - -#if !defined(NO_SSL_DL) && !defined(NO_SSL) -/* If SSL is loaded dynamically, dlopen/dlclose is required. */ -/* Create substitutes for POSIX functions in Win32. */ - - -static HANDLE dlopen( const char *dll_name, int flags ) { - - wchar_t wbuf[PATH_MAX]; - - (void)flags; - XX_httplib_path_to_unicode(NULL, dll_name, wbuf, ARRAY_SIZE(wbuf)); - return LoadLibraryW(wbuf); - -} /* dlopen */ - - -static int dlclose( void *handle ) { - - int result; - - if ( FreeLibrary((HMODULE)handle) != 0 ) result = 0; - else result = -1; - - return result; - -} /* dlclose */ - -#endif - -#endif diff --git a/src/httplib_lock_unlock_connection.c b/src/httplib_lock_unlock_connection.c index ecc5886b..e8d15db3 100644 --- a/src/httplib_lock_unlock_connection.c +++ b/src/httplib_lock_unlock_connection.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + /* diff --git a/src/httplib_lock_unlock_context.c b/src/httplib_lock_unlock_context.c index 23754db3..34afd5b3 100644 --- a/src/httplib_lock_unlock_context.c +++ b/src/httplib_lock_unlock_context.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + /* diff --git a/src/httplib_malloc.c b/src/httplib_malloc.c index ae960b82..f268f333 100644 --- a/src/httplib_malloc.c +++ b/src/httplib_malloc.c @@ -24,8 +24,6 @@ -#define NO_HTTPLIB_MALLOC_OVERRIDE - #include "libhttp-private.h" diff --git a/src/httplib_master_thread.c b/src/httplib_master_thread.c index 607e573f..387e5bc9 100644 --- a/src/httplib_master_thread.c +++ b/src/httplib_master_thread.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + static void master_thread_run( void *thread_func_param ); diff --git a/src/httplib_mkcol.c b/src/httplib_mkcol.c index d8f8bfd5..44904e40 100644 --- a/src/httplib_mkcol.c +++ b/src/httplib_mkcol.c @@ -68,7 +68,7 @@ void XX_httplib_mkcol( struct mg_connection *conn, const char *path ) { return; } - rc = mg_mkdir( conn, path, 0755 ); + rc = XX_httplib_mkdir( conn, path, 0755 ); if ( rc == 0 ) { diff --git a/src/httplib_mkdir.c b/src/httplib_mkdir.c index 5839bd29..12e024d0 100644 --- a/src/httplib_mkdir.c +++ b/src/httplib_mkdir.c @@ -29,7 +29,7 @@ #if defined(_WIN32) -static int mg_mkdir(const struct mg_connection *conn, const char *path, int mode) { +int XX_httplib_mkdir( const struct mg_connection *conn, const char *path, int mode ) { wchar_t wbuf[PATH_MAX]; @@ -37,6 +37,6 @@ static int mg_mkdir(const struct mg_connection *conn, const char *path, int mode XX_httplib_path_to_unicode(conn, path, wbuf, ARRAY_SIZE(wbuf)); return CreateDirectoryW(wbuf, NULL) ? 0 : -1; -} /* mg_mkdir */ +} /* XX_httplib_mkdir */ #endif /* _WIN32 */ diff --git a/src/httplib_opendir.c b/src/httplib_opendir.c index d5546eb1..6b8f381e 100644 --- a/src/httplib_opendir.c +++ b/src/httplib_opendir.c @@ -31,7 +31,7 @@ #if defined(_WIN32) /* Implementation of POSIX opendir/closedir/readdir for Windows. */ -static DIR * mg_opendir(const struct mg_connection *conn, const char *name) { +DIR *XX_httplib_opendir( const struct mg_connection *conn, const char *name ) { DIR *dir = NULL; wchar_t wpath[PATH_MAX]; @@ -50,13 +50,13 @@ static DIR * mg_opendir(const struct mg_connection *conn, const char *name) { dir->handle = FindFirstFileW(wpath, &dir->info); dir->result.d_name[0] = '\0'; } else { - XX_http_free(dir); + XX_httplib_free(dir); dir = NULL; } } return dir; -} /* mg_opendir */ +} /* XX_httplib_opendir */ #endif /* _WIN32 */ diff --git a/src/httplib_produce_socket.c b/src/httplib_produce_socket.c index 1bbd2fbc..b5ab9c8b 100644 --- a/src/httplib_produce_socket.c +++ b/src/httplib_produce_socket.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + /* diff --git a/src/httplib_pthread.h b/src/httplib_pthread.h new file mode 100644 index 00000000..cd268de8 --- /dev/null +++ b/src/httplib_pthread.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2016 Lammert Bies + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + + +extern pthread_mutex_t * XX_httplib_ssl_mutexes; +extern pthread_key_t XX_httplib_sTlsKey; +extern int XX_httplib_thread_idx_max; + + + +#if defined(_WIN32) + +int pthread_cond_broadcast( pthread_cond_t *cv ); +int pthread_cond_destroy( pthread_cond_t *cv ); +int pthread_cond_init( pthread_cond_t *cv, const void *unused ); +int pthread_cond_signal( pthread_cond_t *cv ); +int pthread_cond_timedwait( pthread_cond_t *cv, pthread_mutex_t *mutex, const struct timespec *abstime ); +int pthread_cond_wait( pthread_cond_t *cv, pthread_mutex_t *mutex ); + +int pthread_key_create( pthread_key_t *key, void (*_ignored)(void *) ); +int pthread_key_delete( pthread_key_t key ); + +int pthread_mutex_destroy( pthread_mutex_t *mutex ); +int pthread_mutex_init( pthread_mutex_t *mutex, void *unused ); +int pthread_mutex_lock( pthread_mutex_t *mutex ); +int pthread_mutex_trylock( pthread_mutex_t *mutex ); +int pthread_mutex_unlock( pthread_mutex_t *mutex ); + +void * pthread_getspecific( pthread_key_t key ); +int pthread_setspecific( pthread_key_t key, void *value ); +DWORD pthread_self( void ); + +#endif /* _WIN32 */ diff --git a/src/httplib_put_dir.c b/src/httplib_put_dir.c index 8fe8d232..4654b6a9 100644 --- a/src/httplib_put_dir.c +++ b/src/httplib_put_dir.c @@ -60,7 +60,7 @@ int XX_httplib_put_dir( struct mg_connection *conn, const char *path ) { buf[len] = '\0'; /* Try to create intermediate directory */ - if (!XX_httplib_stat(conn, buf, &file) && mg_mkdir(conn, buf, 0755) != 0) { + if (!XX_httplib_stat(conn, buf, &file) && XX_httplib_mkdir(conn, buf, 0755) != 0) { /* path does not exixt and can not be created */ res = -2; break; diff --git a/src/httplib_readdir.c b/src/httplib_readdir.c index dd535e00..d7da2411 100644 --- a/src/httplib_readdir.c +++ b/src/httplib_readdir.c @@ -30,7 +30,7 @@ #if defined(_WIN32) -struct dirent * mg_readdir(DIR *dir) { +struct dirent *XX_httplib_readdir( DIR *dir ) { struct dirent *result = 0; @@ -52,6 +52,6 @@ struct dirent * mg_readdir(DIR *dir) { return result; -} /* mg_readdir */ +} /* XX_httplib_readdir */ #endif /* _WIN32 */ diff --git a/src/httplib_remove.c b/src/httplib_remove.c index 72cfdc1e..f1a6196f 100644 --- a/src/httplib_remove.c +++ b/src/httplib_remove.c @@ -28,13 +28,18 @@ -#if defined(_WIN32) +int XX_httplib_remove( const struct mg_connection *conn, const char *path ) { -static int mg_remove(const struct mg_connection *conn, const char *path) { +#if defined(_WIN32) wchar_t wbuf[PATH_MAX]; XX_httplib_path_to_unicode(conn, path, wbuf, ARRAY_SIZE(wbuf)); return DeleteFileW(wbuf) ? 0 : -1; -} -#endif /* _WIN32 */ +#else /* _WIN32 */ + + return remove( path ); + +#endif /* _WIN32 */ + +} /* XX_httplib_remove */ diff --git a/src/httplib_remove_bad_file.c b/src/httplib_remove_bad_file.c index e58dc809..50e82162 100644 --- a/src/httplib_remove_bad_file.c +++ b/src/httplib_remove_bad_file.c @@ -37,7 +37,7 @@ void XX_httplib_remove_bad_file( const struct mg_connection *conn, const char *path ) { - int r = mg_remove(conn, path); + int r = XX_httplib_remove( conn, path ); if (r != 0) mg_cry(conn, "%s: Cannot remove invalid file %s", __func__, path); diff --git a/src/httplib_remove_directory.c b/src/httplib_remove_directory.c index 27774d0f..c1e5e82d 100644 --- a/src/httplib_remove_directory.c +++ b/src/httplib_remove_directory.c @@ -35,12 +35,12 @@ int XX_httplib_remove_directory( struct mg_connection *conn, const char *dir ) { int truncated; int ok = 1; - if ((dirp = mg_opendir(conn, dir)) == NULL) { + if ((dirp = XX_httplib_opendir(conn, dir)) == NULL) { return 0; } else { de.conn = conn; - while ((dp = mg_readdir(dirp)) != NULL) { + while ((dp = XX_httplib_readdir(dirp)) != NULL) { /* Do not show current dir (but show hidden files as they will * also be removed) */ if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue; @@ -69,14 +69,14 @@ int XX_httplib_remove_directory( struct mg_connection *conn, const char *dir ) { if (de.file.is_directory) { if (XX_httplib_remove_directory(conn, path) == 0) ok = 0; } else { - if (mg_remove(conn, path) == 0) ok = 0; + if (XX_httplib_remove(conn, path) == 0) ok = 0; } } else { /* file is in memory. It can not be deleted. */ ok = 0; } } - mg_closedir(dirp); + XX_httplib_closedir(dirp); IGNORE_UNUSED_RESULT(rmdir(dir)); } diff --git a/src/httplib_scan_directory.c b/src/httplib_scan_directory.c index d01f3ab4..224086d8 100644 --- a/src/httplib_scan_directory.c +++ b/src/httplib_scan_directory.c @@ -36,12 +36,12 @@ int XX_httplib_scan_directory( struct mg_connection *conn, const char *dir, void struct de de; int truncated; - if ((dirp = mg_opendir(conn, dir)) == NULL) { + if ((dirp = XX_httplib_opendir(conn, dir)) == NULL) { return 0; } else { de.conn = conn; - while ((dp = mg_readdir(dirp)) != NULL) { + while ((dp = XX_httplib_readdir(dirp)) != NULL) { /* Do not show current dir and hidden files */ if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..") || XX_httplib_must_hide_file(conn, dp->d_name)) continue; @@ -65,7 +65,7 @@ int XX_httplib_scan_directory( struct mg_connection *conn, const char *dir, void de.file_name = dp->d_name; cb(&de, data); } - (void)mg_closedir(dirp); + (void)XX_httplib_closedir(dirp); } return 1; diff --git a/src/httplib_send_authorization_request.c b/src/httplib_send_authorization_request.c index b14a2dd1..741d8653 100644 --- a/src/httplib_send_authorization_request.c +++ b/src/httplib_send_authorization_request.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + void XX_httplib_send_authorization_request( struct mg_connection *conn ) { diff --git a/src/httplib_set_ports_option.c b/src/httplib_set_ports_option.c index 4fb5ce19..4f1ee833 100644 --- a/src/httplib_set_ports_option.c +++ b/src/httplib_set_ports_option.c @@ -276,8 +276,7 @@ static int parse_port_string( const struct vec *vec, struct socket *so, int *ip_ #if defined(USE_IPV6) } else if (sscanf(vec->ptr, "[%49[^]]]:%u%n", buf, &port, &len) == 2 - && mg_inet_pton( - AF_INET6, buf, &so->lsa.sin6, sizeof(so->lsa.sin6))) { + && XX_httplib_inet_pton( AF_INET6, buf, &so->lsa.sin6, sizeof(so->lsa.sin6))) { /* IPv6 address, examples: see above */ /* so->lsa.sin6.sin6_family = AF_INET6; already set by mg_inet_pton */ diff --git a/src/httplib_spawn_process.c b/src/httplib_spawn_process.c index ef385480..0ee4a860 100644 --- a/src/httplib_spawn_process.c +++ b/src/httplib_spawn_process.c @@ -33,7 +33,7 @@ #define SIGKILL (0) -static int kill(pid_t pid, int sig_num) { +int XX_httplib_kill(pid_t pid, int sig_num) { TerminateProcess((HANDLE)pid, (UINT)sig_num); CloseHandle((HANDLE)pid); diff --git a/src/httplib_ssl_locking_callback.c b/src/httplib_ssl_locking_callback.c index 78b5be97..2e8028f7 100644 --- a/src/httplib_ssl_locking_callback.c +++ b/src/httplib_ssl_locking_callback.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #if !defined(NO_SSL) diff --git a/src/httplib_start.c b/src/httplib_start.c index a91daac5..e4615186 100644 --- a/src/httplib_start.c +++ b/src/httplib_start.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + /* diff --git a/src/httplib_timer.c b/src/httplib_timer.c index a9484282..f77cad15 100644 --- a/src/httplib_timer.c +++ b/src/httplib_timer.c @@ -24,6 +24,10 @@ +#include "libhttp-private.h" + + + #if defined(USE_TIMERS) #if !defined(MAX_TIMERS) diff --git a/src/httplib_tls_dtor.c b/src/httplib_tls_dtor.c index f3b27ad5..09a8660e 100644 --- a/src/httplib_tls_dtor.c +++ b/src/httplib_tls_dtor.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + /* diff --git a/src/httplib_uninitialize_ssl.c b/src/httplib_uninitialize_ssl.c index 389765c7..c5b28823 100644 --- a/src/httplib_uninitialize_ssl.c +++ b/src/httplib_uninitialize_ssl.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + /* diff --git a/src/httplib_worker_thread.c b/src/httplib_worker_thread.c index a3f2e9dc..66f6aeaf 100644 --- a/src/httplib_worker_thread.c +++ b/src/httplib_worker_thread.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + static void * worker_thread_run( struct worker_thread_args *thread_args ); diff --git a/src/libhttp-private.h b/src/libhttp-private.h index f21a9015..3ade8d75 100644 --- a/src/libhttp-private.h +++ b/src/libhttp-private.h @@ -24,45 +24,6 @@ -/* - * The library provides their own memory allocation functions with a debugging - * version which counts the number of blocks and bytes allocated. The normal - * allocation functions are therefore disabled here, unless a macro has been - * set because a library function needs explicit access to the OS version of - * the memory allocation functions. - */ - -#if !defined(NO_HTTPLIB_MALLOC_OVERRIDE) -#ifdef malloc -#undef malloc -#endif -#ifdef calloc -#undef calloc -#endif -#ifdef realloc -#undef realloc -#endif -#ifdef free -#undef free -#endif -#ifdef snprintf -#undef snprintf -#endif -#ifdef vsnprintf -#undef vsnprintf -#endif -#define malloc DO_NOT_USE_THIS_FUNCTION__USE_httplib_malloc -#define calloc DO_NOT_USE_THIS_FUNCTION__USE_httplib_calloc -#define realloc DO_NOT_USE_THIS_FUNCTION__USE_httplib_realloc -#define free DO_NOT_USE_THIS_FUNCTION__USE_httplib_free -#define snprintf DO_NOT_USE_THIS_FUNCTION__USE_httplib_snprintf -#ifdef _WIN32 /* vsnprintf must not be used in any system, * \ \ \ \ - * but this define only works well for Windows. */ -#define vsnprintf DO_NOT_USE_THIS_FUNCTION__USE_httplib_vsnprintf -#endif -#endif /* ! NO_HTTPLIB_MALLOC_OVERRIDE */ - - #if defined(_WIN32) #if !defined(_CRT_SECURE_NO_WARNINGS) #define _CRT_SECURE_NO_WARNINGS /* Disable deprecation warning in VS2005 */ @@ -100,6 +61,7 @@ #pragma warning(disable : 4306) /* conditional expression is constant: introduced by FD_SET(..) */ #pragma warning(disable : 4127) +#pragma warning(disable : 4548) /* non-constant aggregate initializer: issued due to missing C99 support */ #pragma warning(disable : 4204) /* padding added after data member */ @@ -304,12 +266,12 @@ typedef long off_t; #define fileno(x) (_fileno(x)) #endif /* !fileno MINGW #defines fileno */ -typedef HANDLE pthread_mutex_t; -typedef DWORD pthread_key_t; -typedef HANDLE pthread_t; +typedef HANDLE pthread_mutex_t; +typedef DWORD pthread_key_t; +typedef HANDLE pthread_t; typedef struct { - CRITICAL_SECTION threadIdSec; - struct mg_workerTLS *waiting_thread; /* The chain of threads */ + CRITICAL_SECTION threadIdSec; + struct mg_workerTLS * waiting_thread; /* The chain of threads */ } pthread_cond_t; #ifndef __clockid_t_defined @@ -334,12 +296,6 @@ struct timespec { #define pid_t HANDLE /* MINGW typedefs pid_t to int. Using #define here. */ -static int pthread_mutex_lock(pthread_mutex_t *); -static int pthread_mutex_unlock(pthread_mutex_t *); -static void path_to_unicode(const struct mg_connection *conn, const char *path, wchar_t *wbuf, size_t wbuf_len); -static const char *mg_fgets(char *buf, size_t size, struct file *filep, char **p); - - /* POSIX dirent interface */ struct dirent { char d_name[PATH_MAX]; @@ -412,7 +368,6 @@ typedef unsigned short int in_port_t; #endif /* O_BINARY */ #define closesocket(a) (close(a)) #define mg_mkdir(conn, path, mode) (mkdir(path, mode)) -#define mg_remove(conn, x) (remove(x)) #define mg_sleep(x) (usleep((x)*1000)) #define mg_opendir(conn, x) (opendir(x)) #define mg_closedir(x) (closedir(x)) @@ -697,6 +652,9 @@ struct mg_workerTLS { #endif }; +#if defined(_WIN32) +extern CRITICAL_SECTION global_log_file_lock; +#endif #define PASSWORDS_FILE_NAME ".htpasswd" #define CGI_ENVIRONMENT_SIZE (4096) @@ -953,7 +911,6 @@ mg_static_assert(sizeof(size_t) == 4 || sizeof(size_t) == 8, "size_t data type s #if defined(_WIN32_WCE) #define _beginthreadex(psec, stack, func, prm, flags, ptid) (uintptr_t) CreateThread(psec, stack, func, prm, flags, ptid) -#define remove(f) mg_remove(NULL, f) #define access(x, a) 1 /* not required anyway */ /* WinCE-TODO: define stat, remove, rename, _rmdir, _lseeki64 */ #define EEXIST 1 /* TODO: See Windows error codes */ @@ -968,6 +925,11 @@ typedef int socklen_t; #endif /* NO_SOCKLEN_T */ #define _DARWIN_UNLIMITED_SELECT +#if defined(_WIN32) +#define SIGKILL (0) +int clock_gettime( clockid_t clk_id, struct timespec *tp ); +int poll( struct pollfd *pfd, unsigned int n, int milliseconds ); +#endif void SHA1Final( unsigned char digest[20], SHA1_CTX *context ); @@ -985,6 +947,7 @@ int XX_httplib_check_authorization( struct mg_connection *conn, const char *pa int XX_httplib_check_password( const char *method, const char *ha1, const char *uri, const char *nonce, const char *nc, const char *cnonce, const char *qop, const char *response ); void XX_httplib_close_all_listening_sockets( struct mg_context *ctx ); void XX_httplib_close_connection( struct mg_connection *conn ); +int XX_httplib_closedir( DIR *dir ); void XX_httplib_close_socket_gracefully( struct mg_connection *conn ); int WINCDECL XX_httplib_compare_dir_entries( const void *p1, const void *p2 ); int XX_httplib_connect_socket( struct mg_context *ctx, const char *host, int port, int use_ssl, char *ebuf, size_t ebuf_len, SOCKET *sock, union usa *sa ); @@ -1037,14 +1000,17 @@ int XX_httplib_is_valid_http_method( const char *method ); int XX_httplib_is_valid_port( unsigned long port ); int XX_httplib_is_websocket_protocol( const struct mg_connection *conn ); int XX_httplib_join_thread( pthread_t threadid ); +int XX_httplib_kill(pid_t pid, int sig_num); void * XX_httplib_load_dll( struct mg_context *ctx, const char *dll_name, struct ssl_func *sw ); void XX_httplib_log_access( const struct mg_connection *conn ); int XX_httplib_lowercase( const char *s ); int XX_httplib_match_prefix(const char *pattern, size_t pattern_len, const char *str); void XX_httplib_mkcol( struct mg_connection *conn, const char *path ); +int XX_httplib_mkdir( const struct mg_connection *conn, const char *path, int mode ); int XX_httplib_must_hide_file( struct mg_connection *conn, const char *path ); const char * XX_httplib_next_option( const char *list, struct vec *val, struct vec *eq_val ); void XX_httplib_open_auth_file( struct mg_connection *conn, const char *path, struct file *filep ); +DIR * XX_httplib_opendir( const struct mg_connection *conn, const char *name ); int XX_httplib_parse_auth_header( struct mg_connection *conn, char *buf, size_t buf_size, struct ah *ah ); time_t XX_httplib_parse_date_string( const char *datetime ); int XX_httplib_parse_http_headers( char **buf, struct mg_request_info *ri ); @@ -1064,9 +1030,11 @@ void XX_httplib_put_file( struct mg_connection *conn, const char *path ); int XX_httplib_read_auth_file( struct file *filep, struct read_auth_file_struct *workdata ); int XX_httplib_read_request( FILE *fp, struct mg_connection *conn, char *buf, int bufsiz, int *nread ); void XX_httplib_read_websocket( struct mg_connection *conn, mg_websocket_data_handler ws_data_handler, void *callback_data ); +struct dirent * XX_httplib_readdir( DIR *dir ); void * XX_httplib_realloc2( void *ptr, size_t size ); void XX_httplib_redirect_to_https_port( struct mg_connection *conn, int ssl_index ); int XX_httplib_refresh_trust( struct mg_connection *conn ); +int XX_httplib_remove( const struct mg_connection *conn, const char *path ); void XX_httplib_remove_bad_file( const struct mg_connection *conn, const char *path ); int XX_httplib_remove_directory( struct mg_connection *conn, const char *dir ); void XX_httplib_remove_double_dots_and_double_slashes( char *s ); @@ -1171,8 +1139,5 @@ extern const struct uriprot_tp XX_httplib_abs_uri_protocols[]; extern struct mg_option XX_httplib_config_options[]; extern int XX_httplib_cryptolib_users; extern struct ssl_func XX_httplib_crypto_sw[]; -extern pthread_mutex_t * XX_httplib_ssl_mutexes; extern struct ssl_func XX_httplib_ssl_sw[]; extern int XX_httplib_sTlsInit; -extern pthread_key_t XX_httplib_sTlsKey; -extern int XX_httplib_thread_idx_max; diff --git a/src/win32_pthread_cond_broadcast.c b/src/win32_pthread_cond_broadcast.c index cceb4949..1d8225ca 100644 --- a/src/win32_pthread_cond_broadcast.c +++ b/src/win32_pthread_cond_broadcast.c @@ -26,6 +26,9 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + + #if defined(_WIN32) diff --git a/src/win32_pthread_cond_destroy.c b/src/win32_pthread_cond_destroy.c index 69387882..b8fc7290 100644 --- a/src/win32_pthread_cond_destroy.c +++ b/src/win32_pthread_cond_destroy.c @@ -26,51 +26,12 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #if defined(_WIN32) -#ifndef WIN_PTHREADS_TIME_H -int clock_gettime( clockid_t clk_id, struct timespec *tp ) { - - FILETIME ft; - ULARGE_INTEGER li; - BOOL ok = FALSE; - double d; - static double perfcnt_per_sec = 0.0; - - if (tp) { - memset(tp, 0, sizeof(*tp)); - if (clk_id == CLOCK_REALTIME) { - GetSystemTimeAsFileTime(&ft); - li.LowPart = ft.dwLowDateTime; - li.HighPart = ft.dwHighDateTime; - li.QuadPart -= 116444736000000000; /* 1.1.1970 in filedate */ - tp->tv_sec = (time_t)(li.QuadPart / 10000000); - tp->tv_nsec = (long)(li.QuadPart % 10000000) * 100; - ok = TRUE; - } else if (clk_id == CLOCK_MONOTONIC) { - if (perfcnt_per_sec == 0.0) { - QueryPerformanceFrequency((LARGE_INTEGER *)&li); - perfcnt_per_sec = 1.0 / li.QuadPart; - } - if (perfcnt_per_sec != 0.0) { - QueryPerformanceCounter((LARGE_INTEGER *)&li); - d = li.QuadPart * perfcnt_per_sec; - tp->tv_sec = (time_t)d; - d -= tp->tv_sec; - tp->tv_nsec = (long)(d * 1.0E9); - ok = TRUE; - } - } - } - - return ok ? 0 : -1; - -} /* clock_gettime */ -#endif - - int pthread_cond_destroy( pthread_cond_t *cv ) { EnterCriticalSection(&cv->threadIdSec); diff --git a/src/win32_pthread_cond_init.c b/src/win32_pthread_cond_init.c index 55962d69..5df1058a 100644 --- a/src/win32_pthread_cond_init.c +++ b/src/win32_pthread_cond_init.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #if defined(_WIN32) diff --git a/src/win32_pthread_cond_signal.c b/src/win32_pthread_cond_signal.c index 41966c11..5524725b 100644 --- a/src/win32_pthread_cond_signal.c +++ b/src/win32_pthread_cond_signal.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #if defined(_WIN32) diff --git a/src/win32_pthread_cond_timedwait.c b/src/win32_pthread_cond_timedwait.c index c350fc97..92c37f85 100644 --- a/src/win32_pthread_cond_timedwait.c +++ b/src/win32_pthread_cond_timedwait.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #if defined(_WIN32) diff --git a/src/win32_pthread_cond_wait.c b/src/win32_pthread_cond_wait.c index 0f699b87..98acabe8 100644 --- a/src/win32_pthread_cond_wait.c +++ b/src/win32_pthread_cond_wait.c @@ -26,6 +26,9 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + + #if defined(_WIN32) diff --git a/src/win32_pthread_getspecific.c b/src/win32_pthread_getspecific.c index 928feead..15bf4afd 100644 --- a/src/win32_pthread_getspecific.c +++ b/src/win32_pthread_getspecific.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #if defined(_WIN32) diff --git a/src/win32_pthread_key_create.c b/src/win32_pthread_key_create.c index 5094f109..15afa779 100644 --- a/src/win32_pthread_key_create.c +++ b/src/win32_pthread_key_create.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #ifdef _WIN32 diff --git a/src/win32_pthread_key_delete.c b/src/win32_pthread_key_delete.c index 1470a085..d22e1374 100644 --- a/src/win32_pthread_key_delete.c +++ b/src/win32_pthread_key_delete.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #ifdef _WIN32 diff --git a/src/win32_pthread_mutex_destroy.c b/src/win32_pthread_mutex_destroy.c index e1447367..b2642b82 100644 --- a/src/win32_pthread_mutex_destroy.c +++ b/src/win32_pthread_mutex_destroy.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #if defined(_WIN32) diff --git a/src/win32_pthread_mutex_init.c b/src/win32_pthread_mutex_init.c index b69c3c53..eb24727a 100644 --- a/src/win32_pthread_mutex_init.c +++ b/src/win32_pthread_mutex_init.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #if defined(_WIN32) diff --git a/src/win32_pthread_mutex_lock.c b/src/win32_pthread_mutex_lock.c index 99037fb4..8016c2e6 100644 --- a/src/win32_pthread_mutex_lock.c +++ b/src/win32_pthread_mutex_lock.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #if defined(_WIN32) diff --git a/src/win32_pthread_mutex_trylock.c b/src/win32_pthread_mutex_trylock.c index 99ed5e85..56322900 100644 --- a/src/win32_pthread_mutex_trylock.c +++ b/src/win32_pthread_mutex_trylock.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #if defined(_WIN32) diff --git a/src/win32_pthread_mutex_unlock.c b/src/win32_pthread_mutex_unlock.c index e3c49c34..ebec2c03 100644 --- a/src/win32_pthread_mutex_unlock.c +++ b/src/win32_pthread_mutex_unlock.c @@ -26,6 +26,8 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #if defined(_WIN32) diff --git a/src/win32_pthread_self.c b/src/win32_pthread_self.c index 539e284a..28cb90c7 100644 --- a/src/win32_pthread_self.c +++ b/src/win32_pthread_self.c @@ -26,6 +26,9 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + + #ifdef _WIN32 diff --git a/src/win32_pthread_setspecific.c b/src/win32_pthread_setspecific.c index 7a5355f3..62993b8e 100644 --- a/src/win32_pthread_setspecific.c +++ b/src/win32_pthread_setspecific.c @@ -26,11 +26,13 @@ #include "libhttp-private.h" +#include "httplib_pthread.h" + #if defined(_WIN32) -static int pthread_setspecific(pthread_key_t key, void *value) { +int pthread_setspecific( pthread_key_t key, void *value ) { return TlsSetValue(key, value) ? 0 : 1; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index 402a50aa..00000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,207 +0,0 @@ -# Determine if we should print to the output -if (CIVETWEB_ENABLE_THIRD_PARTY_OUTPUT) - set(THIRD_PARTY_LOGGING 0) -else() - set(THIRD_PARTY_LOGGING 1) -endif() - -# We use the check unit testing framework for our C unit tests -include(ExternalProject) -if(NOT WIN32) - # Apply the patch to check to fix CMake building on OS X - set(CHECK_PATCH_COMMAND patch - ${CIVETWEB_THIRD_PARTY_DIR}/src/check-unit-test-framework/CMakeLists.txt - ${CMAKE_SOURCE_DIR}/cmake/check/c82fe8888aacfe784476112edd3878256d2e30bc.patch - ) -else() - set(CHECK_PATCH_COMMAND "") -endif() -ExternalProject_Add(check-unit-test-framework - DEPENDS c-library - URL "https://codeload.github.com/libcheck/check/zip/${CIVETWEB_CHECK_VERSION}" - DOWNLOAD_NAME "${CIVETWEB_CHECK_VERSION}.zip" - URL_MD5 ${CIVETWEB_CHECK_MD5_HASH} - PREFIX "${CIVETWEB_THIRD_PARTY_DIR}" - BUILD_IN_SOURCE 1 - PATCH_COMMAND ${CHECK_PATCH_COMMAND} - CMAKE_ARGS - "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" - "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" - "-DCMAKE_INSTALL_PREFIX=" - LOG_DOWNLOAD ${THIRD_PARTY_LOGGING} - LOG_UPDATE ${THIRD_PARTY_LOGGING} - LOG_CONFIGURE ${THIRD_PARTY_LOGGING} - LOG_BUILD ${THIRD_PARTY_LOGGING} - LOG_TEST ${THIRD_PARTY_LOGGING} - LOG_INSTALL ${THIRD_PARTY_LOGGING}) - -ExternalProject_Get_Property(check-unit-test-framework INSTALL_DIR) -set(CHECK_INSTALL_DIR ${INSTALL_DIR}) -unset(INSTALL_DIR) -link_directories("${CHECK_INSTALL_DIR}/lib") -include_directories("${CHECK_INSTALL_DIR}/include") -if ((WIN32 AND MINGW) OR APPLE) - set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/libcheck.a") - set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/libcompat.a") -elseif (WIN32) - set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/check.lib") - set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/compat.lib") -else() - set(CHECK_LIBRARIES "${CHECK_INSTALL_DIR}/lib/libcheck.a") -endif() -find_package(LibM) -if (LIBM_FOUND) - set(CHECK_LIBRARIES "${CHECK_LIBRARIES};LIBM::LIBM") -endif() -find_package(LibRt) -if (LIBRT_FOUND) - set(CHECK_LIBRARIES "${CHECK_LIBRARIES};LIBRT::LIBRT") -endif() - -# Build the C unit tests -add_library(shared-c-unit-tests STATIC shared.c) -target_include_directories( - shared-c-unit-tests PUBLIC - ${PROJECT_SOURCE_DIR}/include) - -add_library(public-func-c-unit-tests STATIC public_func.c) -if (BUILD_SHARED_LIBS) - target_compile_definitions(public-func-c-unit-tests PRIVATE CIVETWEB_DLL_IMPORTS) -endif() -target_include_directories( - public-func-c-unit-tests PUBLIC - ${PROJECT_SOURCE_DIR}/include) -target_link_libraries(public-func-c-unit-tests c-library ${CHECK_LIBRARIES}) -add_dependencies(public-func-c-unit-tests check-unit-test-framework) - -add_library(public-server-c-unit-tests STATIC public_server.c) -if (BUILD_SHARED_LIBS) - target_compile_definitions(public-server-c-unit-tests PRIVATE CIVETWEB_DLL_IMPORTS) -endif() -target_include_directories( - public-server-c-unit-tests PUBLIC - ${PROJECT_SOURCE_DIR}/include) -target_link_libraries(public-server-c-unit-tests c-library ${CHECK_LIBRARIES}) -add_dependencies(public-server-c-unit-tests check-unit-test-framework) - -add_library(private-c-unit-tests STATIC private.c) -target_include_directories( - private-c-unit-tests PUBLIC - ${PROJECT_SOURCE_DIR}/include) -target_link_libraries(private-c-unit-tests ${CHECK_LIBRARIES}) -add_dependencies(private-c-unit-tests check-unit-test-framework) - -add_library(exe-c-unit-tests STATIC private_exe.c) -if (BUILD_SHARED_LIBS) - target_compile_definitions(exe-c-unit-tests PRIVATE) -endif() -target_include_directories( - exe-c-unit-tests PUBLIC - ${PROJECT_SOURCE_DIR}/include) -target_link_libraries(exe-c-unit-tests c-library ${CHECK_LIBRARIES}) -add_dependencies(exe-c-unit-tests check-unit-test-framework) - -add_executable(main-c-unit-test main.c) -target_link_libraries(main-c-unit-test - shared-c-unit-tests - public-func-c-unit-tests - public-server-c-unit-tests - private-c-unit-tests - exe-c-unit-tests - ${CHECK_LIBRARIES}) -add_dependencies(main-c-unit-test check-unit-test-framework) - -# Add a check command that builds the dependent test program -add_custom_target(check - COMMAND ${CMAKE_CTEST_COMMAND} - DEPENDS main-c-unit-test) - -# A macro for adding tests -macro(civetweb_add_test suite test_case) - set(test "test-${suite}-${test_case}") - string(TOLOWER "${test}" test) - string(REGEX REPLACE "[^-A-Za-z0-9]" "-" test "${test}") - add_test( - NAME ${test} - COMMAND main-c-unit-test "--test-dir=${CMAKE_CURRENT_SOURCE_DIR}" "--suite=${suite}" "--test-case=${test_case}") - if (WIN32) - string(REPLACE ";" "\\;" test_path "$ENV{PATH}") - set_tests_properties(${test} PROPERTIES - ENVIRONMENT "PATH=${test_path}\\;$") - endif() -endmacro(civetweb_add_test) - - -# Tests of private functions -civetweb_add_test(Private "HTTP Message") -civetweb_add_test(Private "URL Parsing") -civetweb_add_test(Private "Internal Parsing") -civetweb_add_test(Private "Encode Decode") -civetweb_add_test(Private "Mask Data") -civetweb_add_test(Private "Date Parsing") - -# Public API function tests -civetweb_add_test(PublicFunc "Version") -civetweb_add_test(PublicFunc "Options") -civetweb_add_test(PublicFunc "MIME types") -civetweb_add_test(PublicFunc "strcasecmp") -civetweb_add_test(PublicFunc "URL encoding decoding") -civetweb_add_test(PublicFunc "Cookies and variables") -civetweb_add_test(PublicFunc "MD5") -civetweb_add_test(PublicFunc "Aux functions") - -# Public API server tests -civetweb_add_test(PublicServer "Check test environment") -civetweb_add_test(PublicServer "Start threads") -civetweb_add_test(PublicServer "Start Stop HTTP Server") -civetweb_add_test(PublicServer "Start Stop HTTPS Server") -civetweb_add_test(PublicServer "TLS Server Client") -civetweb_add_test(PublicServer "Server Requests") -civetweb_add_test(PublicServer "Handle Form") -civetweb_add_test(PublicServer "HTTP Authentication") -civetweb_add_test(PublicServer "HTTP Keep Alive") - -# Tests with main.c -#civetweb_add_test(EXE "Helper funcs") - - -# Add the coverage command(s) -if (${CMAKE_BUILD_TYPE} MATCHES "[Cc]overage") - find_program(GCOV_EXECUTABLE gcov) - find_program(LCOV_EXECUTABLE lcov) - find_program(GENHTML_EXECUTABLE genhtml) - find_program(CTEST_EXECUTABLE ctest) - if (GCOV_EXECUTABLE AND LCOV_EXECUTABLE AND GENHTML_EXECUTABLE AND CTEST_EXECUTABLE AND HAVE_C_FLAG_COVERAGE) - add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/lcov/index.html - COMMAND ${LCOV_EXECUTABLE} -q -z -d . - COMMAND ${LCOV_EXECUTABLE} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o before.lcov -i - COMMAND ${CTEST_EXECUTABLE} --force-new-ctest-process - COMMAND ${LCOV_EXECUTABLE} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o after.lcov - COMMAND ${LCOV_EXECUTABLE} -q -a before.lcov -a after.lcov --output-file final.lcov - COMMAND ${LCOV_EXECUTABLE} -q -r final.lcov "'${CMAKE_SOURCE_DIR}/test/*'" -o final.lcov - COMMAND ${GENHTML_EXECUTABLE} final.lcov -o lcov --demangle-cpp --sort -p "${CMAKE_SOURCE_DIR}" -t benchmark - DEPENDS main-c-unit-test - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMENT "Running LCOV" - ) - add_custom_target(coverage - DEPENDS ${CMAKE_BINARY_DIR}/lcov/index.html - COMMENT "LCOV report at lcov/index.html" - ) - message(STATUS "Coverage command added") - else() - if (HAVE_C_FLAG_COVERAGE) - set(C_FLAG_COVERAGE_MESSAGE supported) - else() - set(C_FLAG_COVERAGE_MESSAGE unavailable) - endif() - message(WARNING - "Coverage command not available:\n" - " gcov: ${GCOV_EXECUTABLE}\n" - " lcov: ${LCOV_EXECUTABLE}\n" - " genhtml: ${GENHTML_EXECUTABLE}\n" - " ctest: ${CTEST_EXECUTABLE}\n" - " --coverage flag: ${C_FLAG_COVERAGE_MESSAGE}") - endif() -endif() diff --git a/test/page_keep_alive_chunked.lua b/test/page_keep_alive_chunked.lua deleted file mode 100644 index 28ac7d12..00000000 --- a/test/page_keep_alive_chunked.lua +++ /dev/null @@ -1,66 +0,0 @@ --- Set keep_alive. The return value specifies if this is possible at all. -canKeepAlive = mg.keep_alive(true) -now = os.date("!%a, %d %b %Y %H:%M:%S") - --- First send the http headers -mg.write("HTTP/1.1 200 OK\r\n") -mg.write("Content-Type: text/html\r\n") -mg.write("Date: " .. now .. " GMT\r\n") -mg.write("Cache-Control: no-cache\r\n") -mg.write("Last-Modified: " .. now .. " GMT\r\n") -if not canKeepAlive then - mg.write("Connection: close\r\n") - mg.write("\r\n") - mg.write("Keep alive not possible!") - return -end -if mg.request_info.http_version ~= "1.1" then - -- wget will use HTTP/1.0 and Connection: keep-alive, so chunked transfer is not possible - mg.write("Connection: close\r\n") - mg.write("\r\n") - mg.write("Chunked transfer is only possible for HTTP/1.1 requests!") - mg.keep_alive(false) - return -end - --- use chunked encoding (http://www.jmarshall.com/easy/http/#http1.1c2) -mg.write("Cache-Control: max-age=0, must-revalidate\r\n") ---mg.write("Cache-Control: no-cache\r\n") ---mg.write("Cache-Control: no-store\r\n") -mg.write("Connection: keep-alive\r\n") -mg.write("Transfer-Encoding: chunked\r\n") -mg.write("\r\n") - --- function to send a chunk -function send(str) - local len = string.len(str) - mg.write(string.format("%x\r\n", len)) - mg.write(str.."\r\n") -end - --- send the chunks -send("") -send("Civetweb Lua script chunked transfer test page") -send("\n") - -fileCnt = 0 -if lfs then - send("Files in " .. lfs.currentdir()) - send('\n\n') - send('\n') - for f in lfs.dir(".") do - local at = lfs.attributes(f); - if at then - send('\n') - end - fileCnt = fileCnt + 1 - end - send("
nametypesize
' .. f .. '' .. at.mode .. '' .. at.size .. '
\n") -end - -send(fileCnt .. " entries (" .. now .. " GMT)\n") -send("") -send("") - --- end -send("") diff --git a/test/syntax_error.ssjs b/test/syntax_error.ssjs deleted file mode 100644 index d8619edd..00000000 --- a/test/syntax_error.ssjs +++ /dev/null @@ -1,7 +0,0 @@ - -conn.write('HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n\r\n'); - -conn.write('Syntax error:'); - -asdf ghjk qwert 123456789 +-*/ -.!,;