Преглед изворни кода

Merge branch 'master' of https://github.com/civetweb/civetweb

bel2125 пре 6 година
родитељ
комит
a53c492fd0
3 измењених фајлова са 14 додато и 209 уклоњено
  1. 0 208
      Makefile.deprecated
  2. 2 0
      docs/UserManual.md
  3. 12 1
      src/civetweb.c

+ 0 - 208
Makefile.deprecated

@@ -1,208 +0,0 @@
-# This Makefile is part of Civetweb web server project,
-# https://github.com/valenok/civetweb
-#
-# Example custom build:
-# COPT="-g -O0 -DNO_SSL_DL -DUSE_LUA -llua -lcrypto -lssl" make linux
-#
-# Flags are:
-# -DHAVE_MD5              - use system md5 library (-2kb)
-# -DNDEBUG                - strip off all debug code (-5kb)
-# -DDEBUG                 - build debug version (very noisy) (+7kb)
-# -DNO_CGI                - disable CGI support (-5kb)
-# -DNO_SSL                - disable SSL functionality (-2kb)
-# -DNO_SSL_DL             - link against system libssl library (-1kb)
-# -DCONFIG_FILE=\"file\"  - use `file' as the default config file
-# -DSSL_LIB=\"libssl.so.<version>\"   - use system versioned SSL shared object
-# -DCRYPTO_LIB=\"libcrypto.so.<version>\" - use system versioned CRYPTO so
-# -DUSE_LUA               - embed Lua in Civetweb (+100kb)
-
-PROG        = civetweb
-CFLAGS      = -std=c99 -O2 -W -Wall -pedantic -pthread -pipe -Iinclude $(COPT)
-
-# To build with Lua, download and unzip Lua 5.2.3 source code into the
-# civetweb directory, and then add $(LUA_SOURCES) to CFLAGS
-LUA         = src/third_party/lua-5.2.3/src
-LUA_FLAGS   = -I$(LUA) -DLUA_COMPAT_ALL
-LUA_SOURCES = $(LUA)/lapi.c $(LUA)/lcode.c $(LUA)/lctype.c \
-              $(LUA)/ldebug.c $(LUA)/ldo.c $(LUA)/ldump.c \
-              $(LUA)/lfunc.c $(LUA)/lgc.c $(LUA)/llex.c \
-              $(LUA)/lmem.c $(LUA)/lobject.c $(LUA)/lopcodes.c \
-              $(LUA)/lparser.c $(LUA)/lstate.c $(LUA)/lstring.c \
-              $(LUA)/ltable.c $(LUA)/ltm.c $(LUA)/lundump.c \
-              $(LUA)/lvm.c $(LUA)/lzio.c $(LUA)/lauxlib.c \
-              $(LUA)/lbaselib.c $(LUA)/lbitlib.c $(LUA)/lcorolib.c \
-              $(LUA)/ldblib.c $(LUA)/liolib.c $(LUA)/lmathlib.c \
-              $(LUA)/loslib.c $(LUA)/lstrlib.c $(LUA)/ltablib.c \
-              $(LUA)/loadlib.c $(LUA)/linit.c
-LUA_WINOBJS = $(LUA_SOURCES:%.c=%.obj)
-
-ifneq ($(OS), Windows_NT)
-  LUA_FLAGS += -DLUA_USE_DLOPEN
-endif
-
-LIB_SOURCES = src/civetweb.c
-
-ALL_SOURCES = src/main.c $(LIB_SOURCES) src/third_party/sqlite3.c src/third_party/lsqlite3.c src/third_party/lfs.c \
-              $(LUA_SOURCES) $(YASSL_SOURCES)
-
-SQLITE_FLAGS = -DTHREADSAFE=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS
-CIVETWEB_FLAGS = -DUSE_LUA -DUSE_LUA_SQLITE3 -DUSE_LUA_FILE_SYSTEM $(COPT)
-FLAGS = $(CIVETWEB_FLAGS) $(SQLITE_FLAGS) $(LUA_FLAGS)
-
-
-# Stock windows binary builds with Lua. 
-# Yassl has a GPL license, so we will leave it out by default.
-
-ifeq ($(WITH_YASSL), 1)
-YASSL       = ../cyassl-2.4.6
-YASSL_FLAGS = -I $(YASSL) -I $(YASSL)/cyassl \
-              -D _LIB -D OPENSSL_EXTRA -D HAVE_ERRNO_H \
-              -D HAVE_GETHOSTBYNAME -D HAVE_INET_NTOA -D HAVE_LIMITS_H \
-              -D HAVE_MEMSET -D HAVE_SOCKET -D HAVE_STDDEF_H -D HAVE_STDLIB_H \
-              -D HAVE_STRING_H -D HAVE_SYS_STAT_H -D HAVE_SYS_TYPES_H
-YASSL_SOURCES = \
-  $(YASSL)/src/internal.c $(YASSL)/src/io.c $(YASSL)/src/keys.c \
-  $(YASSL)/src/ssl.c $(YASSL)/src/tls.c $(YASSL)/ctaocrypt/src/hmac.c \
-  $(YASSL)/ctaocrypt/src/random.c $(YASSL)/ctaocrypt/src/sha.c \
-  $(YASSL)/ctaocrypt/src/sha256.c $(YASSL)/ctaocrypt/src/logging.c \
-  $(YASSL)/ctaocrypt/src/error.c $(YASSL)/ctaocrypt/src/rsa.c \
-  $(YASSL)/ctaocrypt/src/des3.c $(YASSL)/ctaocrypt/src/asn.c \
-  $(YASSL)/ctaocrypt/src/coding.c $(YASSL)/ctaocrypt/src/arc4.c \
-  $(YASSL)/ctaocrypt/src/md4.c $(YASSL)/ctaocrypt/src/md5.c \
-  $(YASSL)/ctaocrypt/src/dh.c $(YASSL)/ctaocrypt/src/dsa.c \
-  $(YASSL)/ctaocrypt/src/pwdbased.c $(YASSL)/ctaocrypt/src/aes.c \
-  $(YASSL)/ctaocrypt/src/md2.c $(YASSL)/ctaocrypt/src/ripemd.c \
-  $(YASSL)/ctaocrypt/src/sha512.c $(YASSL)/src/sniffer.c \
-  $(YASSL)/ctaocrypt/src/rabbit.c $(YASSL)/ctaocrypt/src/misc.c \
-  $(YASSL)/ctaocrypt/src/tfm.c $(YASSL)/ctaocrypt/src/integer.c \
-  $(YASSL)/ctaocrypt/src/ecc.c $(YASSL)/src/ocsp.c $(YASSL)/src/crl.c \
-  $(YASSL)/ctaocrypt/src/hc128.c $(YASSL)/ctaocrypt/src/memory.c
-  
-  ALL_SOURCES += $(YASSL_SOURCES)
-  FLAGS += $(YASSL_FLAGS) -DNO_SSL_DL
-  CIVETWEB_FLAGS += -DNO_SSL_DL 
-
-else
-#  FLAGS += -DNO_SSL
-#  CIVETWEB_FLAGS += -DNO_SSL 
-endif
-
-ALL_OBJECTS = $(ALL_SOURCES:%.c=%.o)
-ALL_WINOBJS = $(ALL_SOURCES:%.c=%.obj)
-
-
-# Using Visual Studio 6.0. To build Civetweb:
-#  Set MSVC variable below to where VS 6.0 is installed on your system
-#  Run "PATH_TO_VC6\bin\nmake windows"
-MSVC = ../vc6
-#DBG = /Zi /Od
-DBG  = /DNDEBUG /O1
-CL   = $(MSVC)/bin/cl /MD /TC /nologo $(DBG) /W3 /GA /I$(MSVC)/include
-LINK = $(MSVC)/bin/link /incremental:no /libpath:$(MSVC)/lib /machine:IX86 \
-       user32.lib shell32.lib comdlg32.lib ws2_32.lib advapi32.lib
-
-all:
-	@echo "make (linux|bsd|solaris|mac|windows|mingw|cygwin)"
-
-%.obj: %.c
-	$(CL) /c $(FLAGS) /Fo$@ $<
-
-%.o: %.c
-	$(CC) -o $@ $< -c $(FLAGS) $(CFLAGS)
-
-# Lua library for Windows
-lua.lib: $(LUA_WINOBJS)
-	$(MSVC)/bin/lib /out:$@ $(LUA_WINOBJS)
-
-# To build with Lua, make sure you have Lua unpacked into src/third_party/lua-5.2.3 directory
-linux_lua: $(ALL_OBJECTS)
-	$(CC) $(ALL_OBJECTS) -o $(PROG) -ldl
-
-civetweb.o: src/mod_lua.inl
-
-# Make sure that the compiler flags come last in the compilation string.
-# If not so, this can break some on some Linux distros which use
-# "-Wl,--as-needed" turned on by default  in cc command.
-# Also, this is turned in many other distros in static linkage builds.
-linux:
-	$(CC) $(LIB_SOURCES) src/main.c -o $(PROG) -ldl $(CFLAGS)
-
-mac: bsd
-bsd:
-	$(CC) $(LIB_SOURCES) src/main.c -o $(PROG) $(CFLAGS)
-
-bsd_lua: $(ALL_OBJECTS)
-	$(CC) $(ALL_OBJECTS) -o $@
-
-solaris:
-	$(CC) $(LIB_SOURCES) src/main.c -lnsl -lsocket -o $(PROG) $(CFLAGS)
-
-lib$(PROG).a: $(ALL_OBJECTS)
-	ar cr $@ $(ALL_OBJECTS)
-
-$(PROG).lib: $(ALL_WINOBJS)
-	$(MSVC)/bin/lib /out:$@ $(ALL_WINOBJS)
-
-# For codesign to work in non-interactive mode, unlock login keychain:
-# security unlock ~/Library/Keychains/login.keychain
-# See e.g. http://lists.apple.com/archives/apple-cdsa/2008/Jan/msg00027.html
-Civetweb: $(LIB_SOURCES) src/main.c
-	$(CC) $(LIB_SOURCES) src/main.c src/third_party/lsqlite3.c src/third_party/sqlite3.c src/third_party/lfs.c \
-          -DUSE_COCOA $(CFLAGS) $(FLAGS) -mmacosx-version-min=10.4 \
-          $(YASSL_SOURCES) $(LUA_SOURCES) \
-          -framework Cocoa -ObjC -arch i386 -arch x86_64 -o Civetweb
-
-cocoa: Civetweb
-	V=`perl -lne '/define\s+CIVETWEB_VERSION\s+"(\S+)"/ and print $$1' include/civetweb.h`; DIR=dmg/Civetweb.app && rm -rf $$DIR && mkdir -p $$DIR/Contents/{MacOS,Resources} && install -m 644 resources/civetweb_*.png resources/civetweb.icns $$DIR/Contents/Resources/ && install -m 644 resources/Info.plist $$DIR/Contents/ && install -m 755 Civetweb $$DIR/Contents/MacOS/ && ln -fs /Applications dmg/ ; hdiutil create Civetweb_$$V.dmg -volname "Civetweb $$V" -srcfolder dmg -ov #; rm -rf dmg
-
-un:
-	$(CC) test/unit_test.c -o unit_test -I. -I$(LUA) $(LUA_SOURCES) \
-          $(CFLAGS) -g -O0
-	./unit_test
-
-wi:
-	$(CL) test/unit_test.c $(LUA_SOURCES) $(LUA_FLAGS) \
-          $(YASSL_SOURCES) $(YASSL_FLAGS) /I. /DNO_SSL_DL \
-          /link /libpath:$(MSVC)/lib advapi32.lib /out:unit_test.exe
-	./unit_test.exe
-
-windows: $(ALL_WINOBJS)
-	$(MSVC)/bin/rc resources/res.rc
-	$(LINK) /nologo $(ALL_WINOBJS) resources/res.res /out:$(PROG).exe
-
-# Build for Windows under MinGW
-#MINGWDBG= -DDEBUG -O0 -ggdb
-MINGWDBG= -DNDEBUG -Os
-MINGWOPT=  -W -Wall -mthreads -Wl,--subsystem,console $(MINGWDBG) -DHAVE_STDINT $(GCC_WARNINGS) $(COPT)
-mingw:
-	windres resources\res.rc resources\res.o
-	$(CC) $(MINGWOPT) $(LIB_SOURCES) -lws2_32 \
-		-shared -Wl,--out-implib=$(PROG).lib -o $(PROG).dll
-	$(CC) $(MINGWOPT) $(LIB_SOURCES) src/main.c resources\res.o \
-	-lws2_32 -ladvapi32 -lcomdlg32 -o $(PROG).exe
-
-# Build for Windows under Cygwin
-#CYGWINDBG= -DDEBUG -O0 -ggdb
-CYGWINDBG= -DNDEBUG -Os
-CYGWINOPT=  -W -Wall -mthreads -Wl,--subsystem,console $(CYGWINDBG) -DHAVE_STDINT $(GCC_WARNINGS) $(COPT)
-cygwin:
-	windres ./resources/res.rc ./resources/res.o
-	$(CC) $(CYGWINOPT) $(LIB_SOURCES) -lws2_32 \
-		-shared -Wl,--out-implib=$(PROG).lib -o $(PROG).dll
-	$(CC) $(CYGWINOPT) -Iinclude $(LIB_SOURCES) src/main.c ./resources/res.o \
-	-lws2_32 -ladvapi32 -o $(PROG).exe
-
-tests:
-	perl test/test.pl $(TEST)
-
-tarball: clean
-	F=civetweb-`perl -lne '/define\s+CIVETWEB_VERSION\s+"(\S+)"/ and print $$1' include/civetweb.h`.tgz ; cd .. && tar -czf x civetweb/{LICENSE.md,Makefile,examples,test,resources,*.[ch],*.md} && mv x civetweb/$$F
-
-release: tarball cocoa
-	wine make windows
-	V=`perl -lne '/define\s+CIVETWEB_VERSION\s+"(\S+)"/ and print $$1' include/civetweb.h`; upx civetweb.exe; cp civetweb.exe civetweb-$$V.exe; cp civetweb.exe civetweb_php_bundle/; zip -r civetweb_php_bundle_$$V.zip civetweb_php_bundle/
-
-clean:
-	rm -rf *.o *.core $(PROG) *.obj *.so $(PROG).txt *.dSYM *.tgz \
-	$(PROG).exe *.dll *.lib resources/res.o resources/res.RES *.dSYM *.zip *.pdb \
-	*.exe *.dmg $(ALL_OBJECTS) $(ALL_WINOBJS)

+ 2 - 0
docs/UserManual.md

@@ -531,6 +531,8 @@ If set in any other way, the result is unspecified.
 
 
 ### error\_pages
 ### error\_pages
 This option may be used to specify a directory for user defined error pages.
 This option may be used to specify a directory for user defined error pages.
+To specify a directory, make sure the name ends with a backslash (Windows) 
+or slash (Linux, MacOS, ...).
 The error pages may be specified for an individual http status code (e.g.,
 The error pages may be specified for an individual http status code (e.g.,
 404 - page requested by the client not found), a group of http status codes
 404 - page requested by the client not found), a group of http status codes
 (e.g., 4xx - all client errors) or all errors. The corresponding error pages
 (e.g., 4xx - all client errors) or all errors. The corresponding error pages

+ 12 - 1
src/civetweb.c

@@ -15059,6 +15059,7 @@ sslize(struct mg_connection *conn,
 {
 {
 	int ret, err;
 	int ret, err;
 	int short_trust;
 	int short_trust;
+	unsigned timeout=1024;
 	unsigned i;
 	unsigned i;
 
 
 	if (!conn) {
 	if (!conn) {
@@ -15098,10 +15099,17 @@ sslize(struct mg_connection *conn,
 		}
 		}
 	}
 	}
 
 
+	/* Reuse the request timeout for the SSL_Accept/SSL_connect timeout  */
+	if (conn->dom_ctx->config[REQUEST_TIMEOUT]) {
+		/* NOTE: The loop below acts as a back-off, so we can end 
+		 * up sleeping for more (or less) than the REQUEST_TIMEOUT. */
+		timeout = atoi(conn->dom_ctx->config[REQUEST_TIMEOUT]);
+	}
+
 	/* SSL functions may fail and require to be called again:
 	/* SSL functions may fail and require to be called again:
 	 * see https://www.openssl.org/docs/manmaster/ssl/SSL_get_error.html
 	 * see https://www.openssl.org/docs/manmaster/ssl/SSL_get_error.html
 	 * Here "func" could be SSL_connect or SSL_accept. */
 	 * Here "func" could be SSL_connect or SSL_accept. */
-	for (i = 16; i <= 1024; i *= 2) {
+	for (i = 16; i <= timeout; i *= 2) {
 		ret = func(conn->ssl);
 		ret = func(conn->ssl);
 		if (ret != 1) {
 		if (ret != 1) {
 			err = SSL_get_error(conn->ssl, ret);
 			err = SSL_get_error(conn->ssl, ret);
@@ -16939,6 +16947,9 @@ get_request(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *err)
 	/* Message is a valid request */
 	/* Message is a valid request */
 
 
 	/* Is there a "host" ? */
 	/* Is there a "host" ? */
+	if (conn->host!=NULL) {
+		mg_free((void *)conn->host);
+	}
 	conn->host = alloc_get_host(conn);
 	conn->host = alloc_get_host(conn);
 	if (!conn->host) {
 	if (!conn->host) {
 		mg_snprintf(conn,
 		mg_snprintf(conn,