diff --git a/Makefile b/Makefile index a02c0892..ca3aeea1 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ # For help try, "make help" # -include build/Makefile.in-os +include resources/Makefile.in-os CPROG = civetweb #CXXPROG = civetweb @@ -23,32 +23,30 @@ DATAROOTDIR = $(PREFIX)/share DOCDIR = $(DATAROOTDIR)/doc/$(CPROG) SYSCONFDIR = $(PREFIX)/etc -BUILD_DIRS += $(BUILD_DIR) +BUILD_DIRS += $(BUILD_DIR) $(BUILD_DIR)/src -LIB_SOURCES = civetweb.c -APP_SOURCES = main.c +LIB_SOURCES = src/civetweb.c +APP_SOURCES = src/main.c SOURCE_DIRS = OBJECTS = $(LIB_SOURCES:.c=.o) $(APP_SOURCES:.c=.o) # only set main compile options if none were chosen -CFLAGS += -W -Wall -O2 -D$(TARGET_OS) -I. $(COPT) +CFLAGS += -W -Wall -O2 -D$(TARGET_OS) -Iinclude $(COPT) ifdef WITH_DEBUG CFLAGS += -g -DDEBUG_ENABLED endif ifdef WITH_CPP - OBJECTS += cpp/CivetServer.o - BUILD_DIRS += $(BUILD_DIR)/cpp - CFLAGS += -Icpp + OBJECTS += src/CivetServer.o LCC = $(CXX) else LCC = $(CC) endif ifdef WITH_LUA - include build/Makefile.in-lua + include resources/Makefile.in-lua endif ifdef WITH_IPV6 @@ -142,12 +140,18 @@ slib: lib$(CPROG).so clean: rm -rf $(BUILD_DIR) +distclean: clean + @rm -rf VS2012/Debug VS2012/*/Debug VS2012/*/*/Debug + @rm -rf VS2012/Release VS2012/*/Release VS2012/*/*/Release + rm -f $(CPROG) lib$(CPROG).so lib$(CPROG).a *.dmg + lib$(CPROG).a: $(BUILD_DIRS) $(LIB_OBJECTS) @rm -f $@ ar cq $@ $(LIB_OBJECTS) +lib$(CPROG).so: CFLAGS += -fPIC lib$(CPROG).so: $(BUILD_DIRS) $(LIB_OBJECTS) - $(LCC) -fPIC -shared -o $@ $(CFLAGS) $(LDFLAGS) $(LIB_OBJECTS) + $(LCC) -shared -o $@ $(CFLAGS) $(LDFLAGS) $(LIB_OBJECTS) $(CPROG): $(BUILD_DIRS) $(BUILD_OBJECTS) $(LCC) -o $@ $(CFLAGS) $(LDFLAGS) $(BUILD_OBJECTS) $(LIBS) diff --git a/Makefile.deprecated b/Makefile.deprecated index ee3b6b3c..5824aa27 100644 --- a/Makefile.deprecated +++ b/Makefile.deprecated @@ -17,11 +17,11 @@ # -DUSE_LUA - embed Lua in Civetweb (+100kb) PROG = civetweb -CFLAGS = -std=c99 -O2 -W -Wall -pedantic -pthread -pipe $(COPT) +CFLAGS = -std=c99 -O2 -W -Wall -pedantic -pthread -pipe -Iinclude $(COPT) -# To build with Lua, download and unzip Lua 5.2.1 source code into the +# To build with Lua, download and unzip Lua 5.2.2 source code into the # civetweb directory, and then add $(LUA_SOURCES) to CFLAGS -LUA = lua-5.2.1/src +LUA = src/third_party/lua-5.2.2/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 \ @@ -40,9 +40,9 @@ ifneq ($(OS), Windows_NT) LUA_FLAGS += -DLUA_USE_DLOPEN endif -LIB_SOURCES = civetweb.c md5.c +LIB_SOURCES = src/civetweb.c -ALL_SOURCES = main.c $(LIB_SOURCES) build/sqlite3.c build/lsqlite3.c \ +ALL_SOURCES = src/main.c $(LIB_SOURCES) src/third_party/sqlite3.c src/third_party/lsqlite3.c \ $(LUA_SOURCES) $(YASSL_SOURCES) SQLITE_FLAGS = -DTHREADSAFE=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS @@ -114,28 +114,28 @@ all: lua.lib: $(LUA_WINOBJS) $(MSVC)/bin/lib /out:$@ $(LUA_WINOBJS) -# To build with lua, make sure you have Lua unpacked into lua-5.2.1 directory +# To build with lua, make sure you have Lua unpacked into src/third_party/lua-5.2.1 directory linux_lua: $(ALL_OBJECTS) $(CC) $(ALL_OBJECTS) -o $(PROG) -ldl -civetweb.o: mod_lua.inl +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) main.c -o $(PROG) -ldl $(CFLAGS) + $(CC) $(LIB_SOURCES) src/main.c -o $(PROG) -ldl $(CFLAGS) mac: bsd bsd: - $(CC) $(LIB_SOURCES) main.c -o $(PROG) $(CFLAGS) + $(CC) $(LIB_SOURCES) src/main.c -o $(PROG) $(CFLAGS) bsd_lua: $(ALL_OBJECTS) $(CC) $(ALL_OBJECTS) -o $@ solaris: - $(CC) $(LIB_SOURCES) main.c -lnsl -lsocket -o $(PROG) $(CFLAGS) + $(CC) $(LIB_SOURCES) src/main.c -lnsl -lsocket -o $(PROG) $(CFLAGS) lib$(PROG).a: $(ALL_OBJECTS) ar cr $@ $(ALL_OBJECTS) @@ -146,14 +146,14 @@ $(PROG).lib: $(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) main.c - $(CC) $(LIB_SOURCES) main.c build/lsqlite3.c build/sqlite3.c \ +Civetweb: $(LIB_SOURCES) src/main.c + $(CC) $(LIB_SOURCES) src/main.c src/third_party/lsqlite3.c src/third_party/sqlite3.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' $(LIB_SOURCES)`; DIR=dmg/Civetweb.app && rm -rf $$DIR && mkdir -p $$DIR/Contents/{MacOS,Resources} && install -m 644 build/civetweb_*.png build/civetweb.icns $$DIR/Contents/Resources/ && install -m 644 build/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 + V=`perl -lne '/define\s+CIVETWEB_VERSION\s+"(\S+)"/ and print $$1' $(LIB_SOURCES)`; 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) \ @@ -167,18 +167,18 @@ wi: ./unit_test.exe windows: $(ALL_WINOBJS) - $(MSVC)/bin/rc build/res.rc - $(LINK) /nologo $(ALL_WINOBJS) build/res.res /out:$(PROG).exe + $(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 build\res.rc build\res.o + 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) main.c build\res.o \ + $(CC) $(MINGWOPT) $(LIB_SOURCES) src/main.c resources\res.o \ -lws2_32 -ladvapi32 -lcomdlg32 -o $(PROG).exe # Build for Windows under Cygwin @@ -186,24 +186,23 @@ mingw: CYGWINDBG= -DNDEBUG -Os CYGWINOPT= -W -Wall -mthreads -Wl,--subsystem,console $(CYGWINDBG) -DHAVE_STDINT $(GCC_WARNINGS) $(COPT) cygwin: - windres ./build/res.rc ./build/res.o + windres ./resources/res.rc ./resources/res.o $(CC) $(CYGWINOPT) $(LIB_SOURCES) -lws2_32 \ -shared -Wl,--out-implib=$(PROG).lib -o $(PROG).dll - $(CC) $(CYGWINOPT) -Ibuild $(LIB_SOURCES) main.c ./build/res.o \ + $(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' $(LIB_SOURCES)`.tgz ; cd .. && tar -czf x civetweb/{LICENSE.md,Makefile,examples,test,build,*.[ch],*.md} && mv x civetweb/$$F + F=civetweb-`perl -lne '/define\s+CIVETWEB_VERSION\s+"(\S+)"/ and print $$1' $(LIB_SOURCES)`.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' $(LIB_SOURCES)`; 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: - cd examples && $(MAKE) clean rm -rf *.o *.core $(PROG) *.obj *.so $(PROG).txt *.dSYM *.tgz \ - $(PROG).exe *.dll *.lib build/res.o build/res.RES *.dSYM *.zip *.pdb \ + $(PROG).exe *.dll *.lib resources/res.o resources/res.RES *.dSYM *.zip *.pdb \ *.exe *.dmg $(ALL_OBJECTS) $(ALL_WINOBJS) diff --git a/Makefile.osx b/Makefile.osx index f3dee240..5781bff9 100644 --- a/Makefile.osx +++ b/Makefile.osx @@ -18,15 +18,15 @@ CONTENTS_DIR = $(DMG_DIR)/$(PACKAGE).app/Contents RESOURCES_DIR = $(CONTENTS_DIR)/Resources OSXBIN_DIR = $(CONTENTS_DIR)/MacOS -CIVETWEB_VERSION = $(shell perl -lne '/define\s+CIVETWEB_VERSION\s+"(\S+)"/ and print $$1' civetweb.c) +CIVETWEB_VERSION = $(shell perl -lne '/define\s+CIVETWEB_VERSION\s+"(\S+)"/ and print $$1' src/civetweb.c) include Makefile package: build @rm -rf $(DMG_DIR) install -d -m 755 $(CONTENTS_DIR) $(RESOURCES_DIR) $(OSXBIN_DIR) - install -m 644 build/Info.plist $(CONTENTS_DIR)/ - install -m 644 build/civetweb_*.png build/civetweb.icns $(RESOURCES_DIR)/ + install -m 644 resources/Info.plist $(CONTENTS_DIR)/ + install -m 644 resources/civetweb_*.png resources/civetweb.icns $(RESOURCES_DIR)/ install -m 755 $(CPROG) $(OSXBIN_DIR)/$(PACKAGE) ln -fs /Applications $(DMG_DIR)/ hdiutil create $(PACKAGE)_$(CIVETWEB_VERSION).dmg -volname "$(PACKAGE) $(CIVETWEB_VERSION)" -srcfolder $(DMG_DIR) -ov diff --git a/README.md b/README.md index cd0bced9..a3048f62 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ https://groups.google.com/d/forum/civetweb # Quick start documentation -- [ReleaseNotes.md](https://github.com/sunsetbrew/civetweb/blob/master/ReleaseNotes.md) - Release Notes +- [RELEASE_NOTES.md](https://github.com/sunsetbrew/civetweb/blob/master/RELEASE_NOTES.md) - Release Notes - [docs/UserManual.md](https://github.com/sunsetbrew/civetweb/blob/master/docs/UserManual.md) - End User Guide - [docs/Building.md](https://github.com/sunsetbrew/civetweb/blob/master/docs/Building.md) - Buildiing the Server Quick Start - [docs/Embedding.md](https://github.com/sunsetbrew/civetweb/blob/master/docs/Embedding.md) - Embedding Quick Start diff --git a/ReleaseNotes.md b/RELEASE_NOTES.md similarity index 92% rename from ReleaseNotes.md rename to RELEASE_NOTES.md index 27e1d4aa..85f62c3f 100644 --- a/ReleaseNotes.md +++ b/RELEASE_NOTES.md @@ -6,11 +6,12 @@ The objective of this release is to establish a maintable code base, ensure MIT Changes ------- +- Reorangized build directories to make them more intuitive - Added new build rules for lib and slib with option to include C++ class - Upgraded LUA from 5.2.1 to 5.2.2 - Added fallback configuration file path for Linux systems. - + Good for having a system wide default configuration /etc/civetweb/civetweb.conf -- Added new C++ abstraction class cpp/CivetServer + + Good for having a system wide default configuration /usr/local/etc/civetweb.conf +- Added new C++ abstraction class CivetServer - Added thread safety for and fixed websocket defects (Morgan McGuire) - Created PKGBUILD to use Arch distribution (Daniel Oaks) - Created new documentation on Embeddeding, Building and yaSSL (see docs/). diff --git a/VS2012/civetweb/civetweb.vcxproj b/VS2012/civetweb/civetweb.vcxproj index 230387f6..33618789 100644 --- a/VS2012/civetweb/civetweb.vcxproj +++ b/VS2012/civetweb/civetweb.vcxproj @@ -52,7 +52,7 @@ Level3 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - $(ProjectDir)..\..;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\include;%(AdditionalIncludeDirectories) Windows @@ -68,7 +68,7 @@ true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - $(ProjectDir)..\..;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\include;%(AdditionalIncludeDirectories) Windows @@ -78,20 +78,17 @@ - - + + - + - + - - - - + diff --git a/VS2012/civetweb/civetweb.vcxproj.filters b/VS2012/civetweb/civetweb.vcxproj.filters index 27ff1203..253988b3 100644 --- a/VS2012/civetweb/civetweb.vcxproj.filters +++ b/VS2012/civetweb/civetweb.vcxproj.filters @@ -15,31 +15,26 @@ - + Source Files - + Source Files - + Resource Files - + Resource Files - + Header Files - - - Header Files - - \ No newline at end of file diff --git a/VS2012/civetweb_lua/civetweb_lua.vcxproj b/VS2012/civetweb_lua/civetweb_lua.vcxproj index 4b60c92f..25f4fe3e 100644 --- a/VS2012/civetweb_lua/civetweb_lua.vcxproj +++ b/VS2012/civetweb_lua/civetweb_lua.vcxproj @@ -52,7 +52,7 @@ Level3 Disabled LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(ProjectDir)..\..;$(ProjectDir)..\..\lua-5.2.2\src;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party\lua-5.2.2\src;%(AdditionalIncludeDirectories) Windows @@ -68,7 +68,7 @@ true true LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(ProjectDir)..\..;$(ProjectDir)..\..\lua-5.2.2\src;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party\lua-5.2.2\src;%(AdditionalIncludeDirectories) Windows @@ -81,30 +81,26 @@ - - - - + + + - - + + - + - + {8f5e5d77-d269-4665-9e27-1045da6cf0d8} - - - - + \ No newline at end of file diff --git a/VS2012/civetweb_lua/civetweb_lua.vcxproj.filters b/VS2012/civetweb_lua/civetweb_lua.vcxproj.filters index fb81aa5d..dade163e 100644 --- a/VS2012/civetweb_lua/civetweb_lua.vcxproj.filters +++ b/VS2012/civetweb_lua/civetweb_lua.vcxproj.filters @@ -18,40 +18,32 @@ - + Header Files - + Header Files - - Header Files - - + Header Files - + Source Files - + Source Files - + Resource Files - + Resource Files - - - Header Files - - - + \ No newline at end of file diff --git a/VS2012/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj b/VS2012/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj index 60139c93..69039859 100644 --- a/VS2012/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj +++ b/VS2012/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj @@ -52,7 +52,7 @@ Level3 Disabled USE_YASSL;NO_SSL_DL;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(ProjectDir)..\..\..\..\cyassl-2.7.0\;$(ProjectDir)..\..\..\..\cyassl-2.7.0\cyassl\ + $(ProjectDir)..\..\..\include;$(ProjectDir)..\..\..\..\cyassl-2.7.0\;$(ProjectDir)..\..\..\..\cyassl-2.7.0\cyassl\ Windows @@ -68,7 +68,7 @@ true true USE_YASSL;NO_SSL_DL;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(ProjectDir)..\..\..\..\cyassl-2.7.0\;$(ProjectDir)..\..\..\..\cyassl-2.7.0\cyassl\ + $(ProjectDir)..\..\..\include;$(ProjectDir)..\..\..\..\cyassl-2.7.0\;$(ProjectDir)..\..\..\..\cyassl-2.7.0\cyassl\ Windows @@ -78,26 +78,23 @@ - + - - + + - + - + {8c0c878b-bbd6-4241-bca6-61753ffcc7f1} - - - diff --git a/VS2012/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj.filters b/VS2012/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj.filters index d4a80e8a..1c5ee409 100644 --- a/VS2012/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj.filters +++ b/VS2012/civetweb_yassl/civetweb_yassl/civetweb_yassl.vcxproj.filters @@ -15,31 +15,26 @@ - + Header Files - + Source Files - + Source Files - + Resource Files - + Resource Files - - - Header Files - - \ No newline at end of file diff --git a/VS2012/ex_embed_cpp/ex_embed_cpp.vcxproj b/VS2012/ex_embed_cpp/ex_embed_cpp.vcxproj index 354fd9c3..228ffab0 100644 --- a/VS2012/ex_embed_cpp/ex_embed_cpp.vcxproj +++ b/VS2012/ex_embed_cpp/ex_embed_cpp.vcxproj @@ -52,7 +52,7 @@ Level3 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - $(ProjectDir)..\..;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\include;%(AdditionalIncludeDirectories) Console @@ -68,7 +68,7 @@ true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - $(ProjectDir)..\..;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\include;%(AdditionalIncludeDirectories) Console @@ -78,18 +78,15 @@ - - + + - - - - - - + + + - \ No newline at end of file + diff --git a/VS2012/ex_embed_cpp/ex_embed_cpp.vcxproj.filters b/VS2012/ex_embed_cpp/ex_embed_cpp.vcxproj.filters index f96f555a..68671e67 100644 --- a/VS2012/ex_embed_cpp/ex_embed_cpp.vcxproj.filters +++ b/VS2012/ex_embed_cpp/ex_embed_cpp.vcxproj.filters @@ -15,27 +15,22 @@ - + Header Files - + Header Files - + Source Files - + Source Files - + Source Files - - - Header Files - - - \ No newline at end of file + diff --git a/VS2012/ex_websocket/ex_websocket.vcxproj b/VS2012/ex_websocket/ex_websocket.vcxproj index 564b5f66..5bce82a2 100644 --- a/VS2012/ex_websocket/ex_websocket.vcxproj +++ b/VS2012/ex_websocket/ex_websocket.vcxproj @@ -52,7 +52,7 @@ Level3 Disabled USE_WEBSOCKET;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - $(ProjectDir)..\..;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\include;%(AdditionalIncludeDirectories) Console @@ -68,7 +68,7 @@ true true USE_WEBSOCKET;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - $(ProjectDir)..\..;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\include;%(AdditionalIncludeDirectories) Console @@ -78,14 +78,11 @@ - + - - - - - + + diff --git a/VS2012/ex_websocket/ex_websocket.vcxproj.filters b/VS2012/ex_websocket/ex_websocket.vcxproj.filters index 9ac893db..1424bda1 100644 --- a/VS2012/ex_websocket/ex_websocket.vcxproj.filters +++ b/VS2012/ex_websocket/ex_websocket.vcxproj.filters @@ -15,21 +15,16 @@ - + Header Files - + Source Files - + Source Files - - - Header Files - - \ No newline at end of file diff --git a/VS2012/lua_lib/lua_lib.vcxproj b/VS2012/lua_lib/lua_lib.vcxproj index 6e631f34..15e0e58c 100644 --- a/VS2012/lua_lib/lua_lib.vcxproj +++ b/VS2012/lua_lib/lua_lib.vcxproj @@ -47,7 +47,7 @@ Level3 Disabled LUA_COMPAT_ALL;THREADSAFE=1;SQLITE_ENABLE_FTS3;SQLITE_ENABLE_FTS3_PARENTHESIS;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(ProjectDir)..\..\lua-5.2.2\src;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\src\third_party\lua-5.2.2\src;%(AdditionalIncludeDirectories) Windows @@ -63,7 +63,7 @@ true true LUA_COMPAT_ALL;THREADSAFE=1;SQLITE_ENABLE_FTS3;SQLITE_ENABLE_FTS3_PARENTHESIS;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - $(ProjectDir)..\..\lua-5.2.2\src;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\src\third_party\lua-5.2.2\src;%(AdditionalIncludeDirectories) Windows @@ -73,43 +73,43 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/VS2012/lua_lib/lua_lib.vcxproj.filters b/VS2012/lua_lib/lua_lib.vcxproj.filters index 53b7204b..ec0bd19a 100644 --- a/VS2012/lua_lib/lua_lib.vcxproj.filters +++ b/VS2012/lua_lib/lua_lib.vcxproj.filters @@ -15,111 +15,111 @@ - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Header Files diff --git a/cpp/CivetServer.cpp b/cpp/CivetServer.cpp deleted file mode 100644 index 6e7cedc7..00000000 --- a/cpp/CivetServer.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2013 No Face Press, LLC - * License http://opensource.org/licenses/mit-license.php MIT License - */ - -#include "CivetServer.h" - -#include -#include - -int CivetServer::begin_request_callback(struct mg_connection *conn) { - struct mg_request_info *request_info = mg_get_request_info(conn); - - if (!request_info->user_data) - return 0; - - CivetServer *me = (CivetServer*) (request_info->user_data); - - if (me->handleRequest(conn)) { - return 1; // Mark as processed - } - - return 0; -} - -bool CivetServer::handleRequest(struct mg_connection *conn) { - struct mg_request_info *request_info = mg_get_request_info(conn); - - CivetHandler *handler = getHandler(request_info->uri); - if (handler) { - if (strcmp(request_info->request_method, "GET") == 0) { - return handler->handleGet(this, conn); - } else if (strcmp(request_info->request_method, "POST") == 0) { - return handler->handlePost(this, conn); - } else if (strcmp(request_info->request_method, "PUT") == 0) { - return !handler->handlePost(this, conn); - } else if (strcmp(request_info->request_method, "DELETE") == 0) { - return !handler->handlePost(this, conn); - } - } - - return false; // No handler found -} - -CivetServer::CivetServer(const char **options, - const struct mg_callbacks *_callbacks) : - context(0) { - - struct mg_callbacks callbacks; - - if (_callbacks) { - memcpy(&callbacks, _callbacks, sizeof(callbacks)); - } else { - memset(&callbacks, 0, sizeof(callbacks)); - } - callbacks.begin_request = &begin_request_callback; - - context = mg_start(&callbacks, this, options); -} - -CivetServer::~CivetServer() { - close(); -} - -CivetHandler *CivetServer::getHandler(const char *uri, unsigned urilen) const { - - for (unsigned index = 0; index < uris.size(); index++) { - const std::string &handlerURI = uris[index]; - - // first try for an exact match - if (handlerURI == uri) { - return handlers[index]; - } - - // next try for a partial match - // we will accept uri/something - if (handlerURI.length() < urilen - && uri[handlerURI.length()] == '/' - && handlerURI.compare(0, handlerURI.length(), uri, handlerURI.length()) == 0) { - - return handlers[index]; - } - } - - return 0; // none found - -} - -void CivetServer::addHandler(const std::string &uri, CivetHandler *handler) { - int index = getIndex(uri); - if (index < 0) { - uris.push_back(uri); - handlers.push_back(handler); - } else if (handlers[index] != handler) { - delete handlers[index]; - handlers[index] = handler; - } -} - -void CivetServer::removeHandler(const std::string &uri) { - int index = getIndex(uri); - if (index >= 0) { - uris.erase(uris.begin() + index, uris.begin() + index + 1); - handlers.erase(handlers.begin() + index, handlers.begin() + index + 1); - } -} - -int CivetServer::getIndex(const std::string &uri) const { - for (unsigned index = 0; index < uris.size(); index++) { - if (uris[index].compare(uri) == 0) - return index; - } - return -1; -} - -void CivetServer::close() { - if (context) { - mg_stop (context); - context = 0; - } - for (int i = handlers.size() - 1; i >= 0; i--) { - delete handlers[i]; - } - handlers.clear(); - uris.clear(); - -} diff --git a/cpp/CivetServer.h b/cpp/CivetServer.h deleted file mode 100644 index d8192f2e..00000000 --- a/cpp/CivetServer.h +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (c) 2013 No Face Press, LLC - * License http://opensource.org/licenses/mit-license.php MIT License - */ - -#ifndef _CIVETWEB_SERVER_H_ -#define _CIVETWEB_SERVER_H_ -#ifdef __cplusplus - -#include "civetweb.h" -#include -#include - -class CivetServer; // forward declaration - -/** - * Basic interface for a URI request handler. Handlers implementations - * must be reentrant. - */ -class CivetHandler { -public: - - /** - * Destructor - */ - virtual ~CivetHandler() { - } - - /** - * Callback method for GET request. - * - * @param server - the calling server - * @param conn - the connection information - * @returns true if implemented, false otherwise - */ - virtual bool handleGet(CivetServer *server, struct mg_connection *conn) { - return false; - } - - /** - * Callback method for POST request. - * - * @param server - the calling server - * @param conn - the connection information - * @returns true if implemented, false otherwise - */ - virtual bool handlePost(CivetServer *server, struct mg_connection *conn) { - return false; - } - - /** - * Callback method for PUT request. - * - * @param server - the calling server - * @param conn - the connection information - * @returns true if implemented, false otherwise - */ - virtual bool handlePut(CivetServer *server, struct mg_connection *conn) { - return false; - } - - /** - * Callback method for DELETE request. - * - * @param server - the calling server - * @param conn - the connection information - * @returns true if implemented, false otherwise - */ - virtual bool handleDelete(CivetServer *server, struct mg_connection *conn) { - return false; - } - -}; - -/** - * CivetServer - * - * Basic class for embedded web server. This has a URL mapping built-in. - */ -class CivetServer { -public: - - /** - * Constructor - * - * This automatically starts the sever. - * It is good practice to call getContext() after this in case there - * were errors starting the server. - * - * @param options - the web server options. - * @param callbacks - optional web server callback methods. - * Note that this class overrides begin_request callback. - */ - CivetServer(const char **options, const struct mg_callbacks *callbacks = 0); - - /** - * Destructor - */ - virtual ~CivetServer(); - - /** - * close() - * - * Stops server and frees resources. - */ - void close(); - - /** - * getContext() - * - * @return the context or 0 if not running. - */ - const struct mg_context *getContext() const { - return context; - } - - /** - * addHandler(const std::string &, CivetHandler *) - * - * Adds a URI handler. If there is existing URI handler, it will - * be replaced with this one. The handler is "owned" by this server - * and will be deallocated with it. - * - * URI's are ordered and partcial URI's are supported. For example, - * consider two URIs in order: /a/b and /a; /a matches - * /a, /a/b matches /a/b, /a/c matches /a. Reversing the order to - * /a and /a/b; /a matches /a/b, /a/b matches /a. /a/c matches /a. - * - * @param uri - URI to match. - * @param handler - handler instance to use. This will be free'ed - * when the server closes and instances cannot be reused. - */ - void addHandler(const std::string &uri, CivetHandler *handler); - - /** - * removeHandler(const std::string &) - * - * Removes a handler, deleting it if found. - * - * @param - the exact URL used in addHandler(). - */ - void removeHandler(const std::string &uri); - - /** - * getHandler(const std::string &uri) - * - * @param uri - the URI - * @returns the handler that matches the requested URI or 0 if none were found. - */ - CivetHandler *getHandler(const std::string &uri) const { - return getHandler(uri.data(), uri.length()); - } - - /** - * getHandler(const char *uri, unsigned urilen) - * - * @param uri - the URI - * @param urilen - the length of the URI - * @returns the handler that matches the requested URI or 0 if none were found. - */ - CivetHandler *getHandler(const char *uri, unsigned urilen) const; - -protected: - - /** - * handleRequest(struct mg_connection *) - * - * Handles the incomming request. - * - * @param conn - the connection information - * @returns true if implemented, false otherwise - */ - virtual bool handleRequest(struct mg_connection *conn); - - /** - * Returns the index of the handler that matches the - * URI exactly. - * - * @param uri - the url to match - */ - int getIndex(const std::string &uri) const; - - std::vector uris; - std::vector handlers; - struct mg_context *context; - -private: - static int begin_request_callback(struct mg_connection *conn); - -}; - -#endif /* __cplusplus */ -#endif /* _CIVETWEB_SERVER_H_ */ diff --git a/cpp/Makefile b/cpp/Makefile deleted file mode 100644 index 8bdec4ad..00000000 --- a/cpp/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2013 No Face Press, LLC -# License http://opensource.org/licenses/mit-license.php MIT License -# - -CFLAGS= -W -Wall -Wno-unused-parameter -I.. -I. -g -LIB_SOURCES = CivetServer.cpp ../civetweb.c ../md5.c -LIBS = -lpthread - -all: - $(CXX) $(CFLAGS) example.cpp $(LIB_SOURCES) $(LIBS) -o example; - -MSVC = e:/vc6 -CL = $(MSVC)/bin/cl -CLFLAGS = /MD /TC /nologo $(DBG) /W3 /DNO_SSL \ - /I$(MSVC)/include /I.. /I. /Dsnprintf=_snprintf \ - /link /incremental:no /libpath:$(MSVC)/lib /machine:IX86 - -windows: - $(CL) example.cpp $(LIB_SOURCES) $(CLFLAGS) - -clean: - rm -rf example *.exe *.dSYM *.obj diff --git a/docs/Building.md b/docs/Building.md index 9b34fbf9..1525248a 100644 --- a/docs/Building.md +++ b/docs/Building.md @@ -38,12 +38,16 @@ Install on the system, Linux only. ``` make lib WITH_CPP=1 WITH_IPV6=1 -make slib WITH_CPP=1 WITH_LUA=1 WITH_WEBSOCKET=1 +make clean slib WITH_CPP=1 WITH_LUA=1 WITH_WEBSOCKET=1 ``` Build the static and shared libraries. The *WITH_CPP* make option is to include the CivetServer class. The additional make options configure the library just as it would the application. +The *slib* option should be done on a separate clean build as position +independent code (PIC) is required for it. Trying to run it after +building the static library or the server will result in a link error. + ``` make clean ``` @@ -90,7 +94,7 @@ make build COPT="-DNDEBUG -DNO_CGI" Take total control with *CC*, *COPTS* and *TARGET_OS* as make options. TARGET_OS is used to determine some compile details as will as code function. -TARGET_OS values should be be one found in *build/Makefile.in-os*. +TARGET_OS values should be be one found in *resources/Makefile.in-os*. ``` make CC=arm-none-linux-gnueabi-gcc COPT="-march=armv7-a -mfpu=vfp -mfloat-abi=softfp" TARGET_OS=FROG @@ -119,7 +123,7 @@ Note : You dont need root access to run civetweb on Android. - Download the source from the Downloads page. - Download the Android NDK from [http://developer.android.com/tools/sdk/ndk/index.html](http://developer.android.com/tools/sdk/ndk/index.html) -- Run `/path-to-ndk/ndk-build -C /path-to-civetweb/build` +- Run `/path-to-ndk/ndk-build -C /path-to-civetweb/resources` That should generate civetweb/lib/armeabi/civetweb - Using the adb tool (you need to have Android SDK installed for that), push the generated civetweb binary to `/data/local` folder on device. diff --git a/docs/Embedding.md b/docs/Embedding.md index 90311f00..cec462b6 100644 --- a/docs/Embedding.md +++ b/docs/Embedding.md @@ -15,20 +15,20 @@ The *INL* file extension represents code that is statically included inline in a #### Required Files 1. HTTP Server API - - civetweb.c - - civetweb.h + - src/civetweb.c + - include/civetweb.h 2. MD5 API - - md5.inl + - src/md5.inl 3. C++ Wrapper (Optional) - - cpp/CivetServer.cpp - - cpp/CivetServer.h + - src/CivetServer.cpp + - include/CivetServer.h #### Other Files 1. Reference C Server - - main.c + - src/main.c 2. Reference C++ Server - - cpp/example.cpp + - examples/embedded_cpp/embedded_cpp.cpp Quick Start ------ @@ -61,8 +61,8 @@ LUA is a server side include functionality. Files ending in .la will be process ##### Add the following sources - - mod_lua.inl - - lua-5.2.2/src + - src/mod_lua.inl + - src/third_party/lua-5.2.2/src + lapi.c + lauxlib.c + lbaselib.c @@ -95,9 +95,9 @@ LUA is a server side include functionality. Files ending in .la will be process + lundump.c + lvm.c + lzio.c - - build/sqlite3.c - - build/sqlite3.h - - build/lsqlite3.c + - src/third_party/sqlite3.c + - src/third_party/sqlite3.h + - src/third_party/lsqlite3.c Civetweb internals diff --git a/docs/UserManual.md b/docs/UserManual.md index 0c19516c..81836771 100644 --- a/docs/UserManual.md +++ b/docs/UserManual.md @@ -258,7 +258,7 @@ directory is commonly referenced as dot (`.`). Path to SSL certificate file. This option is only required when at least one of the `listening_ports` is SSL. The file must be in PEM format, and it must have both private key and certificate, see for example -[ssl_cert.pem](https://github.com/sunsetbrew/civetweb/blob/master/build/ssl_cert.pem) +[ssl_cert.pem](https://github.com/sunsetbrew/civetweb/blob/master/resources/ssl_cert.pem) ### num_threads `50` Number of worker threads. Civetweb handles each incoming connection in a @@ -332,10 +332,10 @@ are accessible from the Lua code (please check reference manual for details), and also information about the request is available in `mg.request_info` object, like request method, all headers, etcetera. Please refer to `struct mg_request_info` definition in -[civetweb.h](https://github.com/sunsetbrew/civetweb/blob/master/civetweb.h) +[civetweb.h](https://github.com/sunsetbrew/civetweb/blob/master/include/civetweb.h) to see what kind of information is present in `mg.request_info` object. Also, [page.lp](https://github.com/sunsetbrew/civetweb/blob/master/test/page.lp) and -[prime_numbers.lp](https://github.com/sunsetbrew/civetweb/blob/master/examples/lua/prime_numbers.lp) +[prime_numbers.lp](https://github.com/sunsetbrew/civetweb/blob/master/examples/docroot/prime_numbers.lp) contains some example code that uses `request_info` and other functions(form submitting for example). Civetweb exports the following to the Lua server page: diff --git a/examples/Makefile b/examples/Makefile deleted file mode 100644 index 79a53751..00000000 --- a/examples/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -CFLAGS= -W -Wall -I.. -pthread -g -LIB_SOURCE = ../civetweb.c -all: - OS=`uname`; \ - test "$$OS" = Linux && LIBS="-ldl" ; \ - $(CC) $(CFLAGS) hello.c $(LIB_SOURCE) $$LIBS $(ADD) -o hello; - $(CC) $(CFLAGS) upload.c $(LIB_SOURCE) $$LIBS $(ADD) -o upload; - $(CC) $(CFLAGS) post.c $(LIB_SOURCE) $$LIBS $(ADD) -o post; - $(CC) $(CFLAGS) -DUSE_WEBSOCKET websocket.c $(LIB_SOURCE) $$LIBS $(ADD) -o websocket; - $(CC) $(CFLAGS) chat.c $(LIB_SOURCE) $$LIBS $(ADD) -o chat - - -MSVC = e:/vc6 -CL = $(MSVC)/bin/cl -CLFLAGS = /MD /TC /nologo $(DBG) /W3 /DNO_SSL \ - /I$(MSVC)/include /I.. /Dsnprintf=_snprintf \ - /link /incremental:no /libpath:$(MSVC)/lib /machine:IX86 - -windows: - $(CL) upload.c $(LIB_SOURCE) $(CLFLAGS) - $(CL) hello.c $(LIB_SOURCE) $(CLFLAGS) - $(CL) post.c $(LIB_SOURCE) $(CLFLAGS) - $(CL) /DUSE_WEBSOCKET websocket.c $(LIB_SOURCE) $(CLFLAGS) - -clean: - rm -rf hello upload post websocket chat *.exe *.dSYM *.obj diff --git a/examples/chat/Makefile b/examples/chat/Makefile new file mode 100644 index 00000000..e8d12be6 --- /dev/null +++ b/examples/chat/Makefile @@ -0,0 +1,40 @@ +# +# Copyright (c) 2013 No Face Press, LLC +# License http://opensource.org/licenses/mit-license.php MIT License +# + +#This makefile is used to test the other Makefiles + + +PROG = chat +SRC = chat.c + +TOP = ../.. +CIVETWEB_LIB = libcivetweb.a +SSL_CERT = ssl_cert.pem + +CFLAGS = -I$(TOP)/include $(COPT) +LIBS = -lpthread + +include $(TOP)/resources/Makefile.in-os + +ifeq ($(TARGET_OS),LINUX) + LIBS += -ldl +endif + +all: $(PROG) $(SSL_CERT) + +$(PROG): $(CIVETWEB_LIB) $(SRC) + $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(SRC) $(CIVETWEB_LIB) $(LIBS) + +$(CIVETWEB_LIB): + $(MAKE) -C $(TOP) clean lib + cp $(TOP)/$(CIVETWEB_LIB) . + +$(SSL_CERT): + cp $(TOP)/resources/$(SSL_CERT) . + +clean: + rm -f $(CIVETWEB_LIB) $(PROG) $(SSL_CERT) + +.PHONY: all clean diff --git a/examples/chat.c b/examples/chat/chat.c similarity index 100% rename from examples/chat.c rename to examples/chat/chat.c diff --git a/examples/html/favicon.ico b/examples/docroot/favicon.ico similarity index 100% rename from examples/html/favicon.ico rename to examples/docroot/favicon.ico diff --git a/examples/html/index.html b/examples/docroot/index.html similarity index 100% rename from examples/html/index.html rename to examples/docroot/index.html diff --git a/examples/html/jquery.js b/examples/docroot/jquery.js similarity index 100% rename from examples/html/jquery.js rename to examples/docroot/jquery.js diff --git a/examples/html/login.html b/examples/docroot/login.html similarity index 100% rename from examples/html/login.html rename to examples/docroot/login.html diff --git a/examples/html/logo.png b/examples/docroot/logo.png similarity index 100% rename from examples/html/logo.png rename to examples/docroot/logo.png diff --git a/examples/html/main.js b/examples/docroot/main.js similarity index 100% rename from examples/html/main.js rename to examples/docroot/main.js diff --git a/examples/lua/prime_numbers.lp b/examples/docroot/prime_numbers.lp similarity index 100% rename from examples/lua/prime_numbers.lp rename to examples/docroot/prime_numbers.lp diff --git a/examples/html/style.css b/examples/docroot/style.css similarity index 100% rename from examples/html/style.css rename to examples/docroot/style.css diff --git a/examples/embedded_cpp/Makefile b/examples/embedded_cpp/Makefile new file mode 100644 index 00000000..65adf98b --- /dev/null +++ b/examples/embedded_cpp/Makefile @@ -0,0 +1,36 @@ +# +# Copyright (c) 2013 No Face Press, LLC +# License http://opensource.org/licenses/mit-license.php MIT License +# + +#This makefile is used to test the other Makefiles + + +PROG = embedded_cpp +SRC = embedded_cpp.cpp + +TOP = ../.. +CIVETWEB_LIB = libcivetweb.a + +CFLAGS = -I$(TOP)/include $(COPT) +LIBS = -lpthread + +include $(TOP)/resources/Makefile.in-os + +ifeq ($(TARGET_OS),LINUX) + LIBS += -ldl +endif + +all: $(PROG) + +$(PROG): $(CIVETWEB_LIB) $(SRC) + $(CXX) -o $@ $(CFLAGS) $(LDFLAGS) $(SRC) $(CIVETWEB_LIB) $(LIBS) + +$(CIVETWEB_LIB): + $(MAKE) -C $(TOP) clean lib WITH_CPP=1 + cp $(TOP)/$(CIVETWEB_LIB) . + +clean: + rm -f $(CIVETWEB_LIB) $(PROG) + +.PHONY: all clean diff --git a/cpp/example.cpp b/examples/embedded_cpp/embedded_cpp.cpp similarity index 100% rename from cpp/example.cpp rename to examples/embedded_cpp/embedded_cpp.cpp diff --git a/examples/hello/Makefile b/examples/hello/Makefile new file mode 100644 index 00000000..4424e3b5 --- /dev/null +++ b/examples/hello/Makefile @@ -0,0 +1,36 @@ +# +# Copyright (c) 2013 No Face Press, LLC +# License http://opensource.org/licenses/mit-license.php MIT License +# + +#This makefile is used to test the other Makefiles + + +PROG = hello +SRC = hello.c + +TOP = ../.. +CIVETWEB_LIB = libcivetweb.a + +CFLAGS = -I$(TOP)/include $(COPT) +LIBS = -lpthread + +include $(TOP)/resources/Makefile.in-os + +ifeq ($(TARGET_OS),LINUX) + LIBS += -ldl +endif + +all: $(PROG) + +$(PROG): $(CIVETWEB_LIB) $(SRC) + $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(SRC) $(CIVETWEB_LIB) $(LIBS) + +$(CIVETWEB_LIB): + $(MAKE) -C $(TOP) clean lib + cp $(TOP)/$(CIVETWEB_LIB) . + +clean: + rm -f $(CIVETWEB_LIB) $(PROG) + +.PHONY: all clean diff --git a/examples/hello.c b/examples/hello/hello.c similarity index 100% rename from examples/hello.c rename to examples/hello/hello.c diff --git a/examples/lua_dll.c b/examples/lua/lua_dll.c similarity index 100% rename from examples/lua_dll.c rename to examples/lua/lua_dll.c diff --git a/examples/post/Makefile b/examples/post/Makefile new file mode 100644 index 00000000..6e504f43 --- /dev/null +++ b/examples/post/Makefile @@ -0,0 +1,36 @@ +# +# Copyright (c) 2013 No Face Press, LLC +# License http://opensource.org/licenses/mit-license.php MIT License +# + +#This makefile is used to test the other Makefiles + + +PROG = post +SRC = post.c + +TOP = ../.. +CIVETWEB_LIB = libcivetweb.a + +CFLAGS = -I$(TOP)/include $(COPT) +LIBS = -lpthread + +include $(TOP)/resources/Makefile.in-os + +ifeq ($(TARGET_OS),LINUX) + LIBS += -ldl +endif + +all: $(PROG) + +$(PROG): $(CIVETWEB_LIB) $(SRC) + $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(SRC) $(CIVETWEB_LIB) $(LIBS) + +$(CIVETWEB_LIB): + $(MAKE) -C $(TOP) clean lib + cp $(TOP)/$(CIVETWEB_LIB) . + +clean: + rm -f $(CIVETWEB_LIB) $(PROG) + +.PHONY: all clean diff --git a/examples/post.c b/examples/post/post.c similarity index 100% rename from examples/post.c rename to examples/post/post.c diff --git a/examples/ssl_cert.pem b/examples/ssl_cert.pem deleted file mode 100644 index f7e15a0e..00000000 --- a/examples/ssl_cert.pem +++ /dev/null @@ -1,50 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEogIBAAKCAQEAwONaLOP7EdegqjRuQKSDXzvHmFMZfBufjhELhNjo5KsL4ieH -hMSGCcSV6y32hzhqR5lvTViaQez+xhc58NZRu+OUgEhodRBW/vAOjpz/xdMz5HaC -EhP3E9W1pkitVseS8B5rrgJo1BfCGai1fPav1nutPq2Kj7vMy24+g460Lonf6ln1 -di4aTIRtAqXtUU6RFpPJP35PkCXbTK65O8HJSxxt/XtfoezHCU5+UIwmZGYx46UB -Wzg3IfK6bGPSiHU3pdiTol0uMPt/GUK+x4NyZJ4/ImsNAicRwMBdja4ywHKXJehH -gXBthsVIHbL21x+4ibsg9eVM/XioTV6tW3IrdwIDAQABAoIBACFfdLutmkQFBcRN -HAJNNHmmsyr0vcUOVnXTFyYeDXV67qxrYHQlOHe6LqIpKq1Mon7O2kYMnWvooFAP -trOnsS6L+qaTYJdYg2TKjgo4ubw1hZXytyB/mdExuaMSkgMgtpia+tB5lD+V+LxN -x1DesZ+veFMO3Zluyckswt4qM5yVa04YFrt31H0E1rJfIen61lidXIKYmHHWuRxK -SadjFfbcqJ6P9ZF22BOkleg5Fm5NaxJmyQynOWaAkSZa5w1XySFfRjRfsbDr64G6 -+LSG8YtRuvfxnvUNhynVPHcpE40eiPo6v8Ho6yZKXpV5klCKciodXAORsswSoGJa -N3nnu/ECgYEA6Yb2rM3QUEPIALdL8f/OzZ1GBSdiQB2WSAxzl9pR/dLF2H+0pitS -to0830mk92ppVmRVD3JGxYDRZQ56tlFXyGaCzJBMRIcsotAhBoNbjV0i9n5bLJYf -BmjU9yvWcgsTt0tr3B0FrtYyp2tCvwHqlxvFpFdUCj2oRw2uGpkhmNkCgYEA03M6 -WxFhsix3y6eVCVvShfbLBSOqp8l0qiTEty+dgVQcWN4CO/5eyaZXKxlCG9KMmKxy -Yx+YgxZrDhfaZ0cxhHGPRKEAxM3IKwT2C8/wCaSiLWXZZpTifnSD99vtOt4wEfrG -+AghNd5kamFiM9tU0AyvhJc2vdJFuXrfeC7ntM8CgYBGDA+t4cZcbRhu7ow/OKYF -kulP3nJgHP/Y+LMrl3cEldZ2jEfZmCElVNQvfd2XwTl7injhOzvzPiKRF3jDez7D -g8w0JAxceddvttJRK9GoY4l7OoeKpjUELSnEQkf+yUfOsTbXPXVY7jMfeNL6jE6b -qN7t3qv8rmXtejMBE3G6cQKBgGR5W2BMiRSlxqKx1cKlrApV87BUe1HRCyuR3xuA -d6Item7Lx1oEi7vb242yKdSYnpApWQ06xTh83Y/Ly87JaIEbiM0+h+P8OEIg0F1a -iB+86AcUX1I8KseVy+Np0HbpfwP8GrFfA5DaRPK7pXMopEtby8cAJ1XZZaI1/ZvZ -BebHAoGAcQU9WvCkT+nIp9FpXfBybYUsvgkaizMIqp66/l3GYgYAq8p1VLGvN4v5 -ec0dW58SJrCpqsM3NP78DtEzQf9OOsk+FsjBFzDU2RkeUreyt2/nQBj/2mN/+hEy -hYN0Zii2yTb63jGxKY6gH1R/r9dL8kXaJmcZrfSa3AgywnteJWg= ------END RSA PRIVATE KEY----- ------BEGIN CERTIFICATE----- -MIIDBjCCAe4CCQCX05m0b053QzANBgkqhkiG9w0BAQQFADBFMQswCQYDVQQGEwJB -VTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0 -cyBQdHkgTHRkMB4XDTA4MTIwNzEwMjUyMloXDTE4MTIwNTEwMjUyMlowRTELMAkG -A1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0 -IFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB -AMDjWizj+xHXoKo0bkCkg187x5hTGXwbn44RC4TY6OSrC+Inh4TEhgnElest9oc4 -akeZb01YmkHs/sYXOfDWUbvjlIBIaHUQVv7wDo6c/8XTM+R2ghIT9xPVtaZIrVbH -kvAea64CaNQXwhmotXz2r9Z7rT6tio+7zMtuPoOOtC6J3+pZ9XYuGkyEbQKl7VFO -kRaTyT9+T5Al20yuuTvByUscbf17X6HsxwlOflCMJmRmMeOlAVs4NyHyumxj0oh1 -N6XYk6JdLjD7fxlCvseDcmSePyJrDQInEcDAXY2uMsBylyXoR4FwbYbFSB2y9tcf -uIm7IPXlTP14qE1erVtyK3cCAwEAATANBgkqhkiG9w0BAQQFAAOCAQEAW4yZdqpB -oIdiuXRosr86Sg9FiMg/cn+2OwQ0QIaA8ZBwKsc+wIIHEgXCS8J6316BGQeUvMD+ -plNe0r4GWzzmlDMdobeQ5arPRB89qd9skE6pAMdLg3FyyfEjz3A0VpskolW5VBMr -P5R7uJ1FLgH12RyAjZCWYcCRqEMOffqvyMCH6oAjyDmQOA5IssRKX/HsHntSH/HW -W7slTcP45ty1b44Nq22/ubYk0CJRQgqKOIQ3cLgPomN1jNFQbAbfVTaK1DpEysrQ -5V8a8gNW+3sVZmV6d1Mj3pN2Le62wUKuV2g6BNU7iiwcoY8HI68aRxz2hVMS+t5f -SEGI4JSxV56lYg== ------END CERTIFICATE----- ------BEGIN DH PARAMETERS----- -MEYCQQD+ef8hZ4XbdoyIpJyCTF2UrUEfX6mYDvxuS5O1UNYcslUqlj6JkA11e/yS -6DK8Z86W6mSj5CEk4IjbyEOECXH7AgEC ------END DH PARAMETERS----- diff --git a/examples/upload/Makefile b/examples/upload/Makefile new file mode 100644 index 00000000..9c6270fb --- /dev/null +++ b/examples/upload/Makefile @@ -0,0 +1,36 @@ +# +# Copyright (c) 2013 No Face Press, LLC +# License http://opensource.org/licenses/mit-license.php MIT License +# + +#This makefile is used to test the other Makefiles + + +PROG = upload +SRC = upload.c + +TOP = ../.. +CIVETWEB_LIB = libcivetweb.a + +CFLAGS = -I$(TOP)/include $(COPT) +LIBS = -lpthread + +include $(TOP)/resources/Makefile.in-os + +ifeq ($(TARGET_OS),LINUX) + LIBS += -ldl +endif + +all: $(PROG) + +$(PROG): $(CIVETWEB_LIB) $(SRC) + $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(SRC) $(CIVETWEB_LIB) $(LIBS) + +$(CIVETWEB_LIB): + $(MAKE) -C $(TOP) clean lib + cp $(TOP)/$(CIVETWEB_LIB) . + +clean: + rm -f $(CIVETWEB_LIB) $(PROG) + +.PHONY: all clean diff --git a/examples/upload.c b/examples/upload/upload.c similarity index 100% rename from examples/upload.c rename to examples/upload/upload.c diff --git a/examples/websocket/Makefile b/examples/websocket/Makefile new file mode 100644 index 00000000..3e0469e8 --- /dev/null +++ b/examples/websocket/Makefile @@ -0,0 +1,36 @@ +# +# Copyright (c) 2013 No Face Press, LLC +# License http://opensource.org/licenses/mit-license.php MIT License +# + +#This makefile is used to test the other Makefiles + + +PROG = websocket +SRC = websocket.c + +TOP = ../.. +CIVETWEB_LIB = libcivetweb.a + +CFLAGS = -I$(TOP)/include $(COPT) +LIBS = -lpthread + +include $(TOP)/resources/Makefile.in-os + +ifeq ($(TARGET_OS),LINUX) + LIBS += -ldl +endif + +all: $(PROG) + +$(PROG): $(CIVETWEB_LIB) $(SRC) + $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(SRC) $(CIVETWEB_LIB) $(LIBS) + +$(CIVETWEB_LIB): + $(MAKE) -C $(TOP) clean lib WITH_WEBSOCKET=1 + cp $(TOP)/$(CIVETWEB_LIB) . + +clean: + rm -f $(CIVETWEB_LIB) $(PROG) + +.PHONY: all clean diff --git a/examples/websocket_html_root/index.html b/examples/websocket/docroot/index.html similarity index 100% rename from examples/websocket_html_root/index.html rename to examples/websocket/docroot/index.html diff --git a/examples/websocket.c b/examples/websocket/websocket.c similarity index 100% rename from examples/websocket.c rename to examples/websocket/websocket.c diff --git a/include/CivetServer.h b/include/CivetServer.h new file mode 100644 index 00000000..04dd2c6a --- /dev/null +++ b/include/CivetServer.h @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2013 No Face Press, LLC + * License http://opensource.org/licenses/mit-license.php MIT License + */ + +#ifndef _CIVETWEB_SERVER_H_ +#define _CIVETWEB_SERVER_H_ +#ifdef __cplusplus + +#include "civetweb.h" +#include +#include + +class CivetServer; // forward declaration + +/** + * Basic interface for a URI request handler. Handlers implementations + * must be reentrant. + */ +class CivetHandler { +public: + + /** + * Destructor + */ + virtual ~CivetHandler() { + } + + /** + * Callback method for GET request. + * + * @param server - the calling server + * @param conn - the connection information + * @returns true if implemented, false otherwise + */ + virtual bool handleGet(CivetServer *server, struct mg_connection *conn); + + /** + * Callback method for POST request. + * + * @param server - the calling server + * @param conn - the connection information + * @returns true if implemented, false otherwise + */ + virtual bool handlePost(CivetServer *server, struct mg_connection *conn); + + /** + * Callback method for PUT request. + * + * @param server - the calling server + * @param conn - the connection information + * @returns true if implemented, false otherwise + */ + virtual bool handlePut(CivetServer *server, struct mg_connection *conn); + + /** + * Callback method for DELETE request. + * + * @param server - the calling server + * @param conn - the connection information + * @returns true if implemented, false otherwise + */ + virtual bool handleDelete(CivetServer *server, struct mg_connection *conn); + +}; + +/** + * CivetServer + * + * Basic class for embedded web server. This has a URL mapping built-in. + */ +class CivetServer { +public: + + /** + * Constructor + * + * This automatically starts the sever. + * It is good practice to call getContext() after this in case there + * were errors starting the server. + * + * @param options - the web server options. + * @param callbacks - optional web server callback methods. + * Note that this class overrides begin_request callback. + */ + CivetServer(const char **options, const struct mg_callbacks *callbacks = 0); + + /** + * Destructor + */ + virtual ~CivetServer(); + + /** + * close() + * + * Stops server and frees resources. + */ + void close(); + + /** + * getContext() + * + * @return the context or 0 if not running. + */ + const struct mg_context *getContext() const { + return context; + } + + /** + * addHandler(const std::string &, CivetHandler *) + * + * Adds a URI handler. If there is existing URI handler, it will + * be replaced with this one. The handler is "owned" by this server + * and will be deallocated with it. + * + * URI's are ordered and partcial URI's are supported. For example, + * consider two URIs in order: /a/b and /a; /a matches + * /a, /a/b matches /a/b, /a/c matches /a. Reversing the order to + * /a and /a/b; /a matches /a/b, /a/b matches /a. /a/c matches /a. + * + * @param uri - URI to match. + * @param handler - handler instance to use. This will be free'ed + * when the server closes and instances cannot be reused. + */ + void addHandler(const std::string &uri, CivetHandler *handler); + + /** + * removeHandler(const std::string &) + * + * Removes a handler, deleting it if found. + * + * @param - the exact URL used in addHandler(). + */ + void removeHandler(const std::string &uri); + + /** + * getHandler(const std::string &uri) + * + * @param uri - the URI + * @returns the handler that matches the requested URI or 0 if none were found. + */ + CivetHandler *getHandler(const std::string &uri) const { + return getHandler(uri.data(), uri.length()); + } + + /** + * getHandler(const char *uri, unsigned urilen) + * + * @param uri - the URI + * @param urilen - the length of the URI + * @returns the handler that matches the requested URI or 0 if none were found. + */ + CivetHandler *getHandler(const char *uri, unsigned urilen) const; + +protected: + + /** + * handleRequest(struct mg_connection *) + * + * Handles the incomming request. + * + * @param conn - the connection information + * @returns true if implemented, false otherwise + */ + virtual bool handleRequest(struct mg_connection *conn); + + /** + * Returns the index of the handler that matches the + * URI exactly. + * + * @param uri - the url to match + */ + int getIndex(const std::string &uri) const; + + std::vector uris; + std::vector handlers; + struct mg_context *context; + +private: + static int begin_request_callback(struct mg_connection *conn); + +}; + +#endif /* __cplusplus */ +#endif /* _CIVETWEB_SERVER_H_ */ diff --git a/civetweb.h b/include/civetweb.h similarity index 97% rename from civetweb.h rename to include/civetweb.h index 7726ae60..4bebf680 100644 --- a/civetweb.h +++ b/include/civetweb.h @@ -190,7 +190,7 @@ const char **mg_get_valid_option_names(void); // This function allows an application to manipulate .htpasswd files on the // fly by adding, deleting and changing user records. This is one of the // several ways of implementing authentication on the server side. For another, -// cookie-based way please refer to the examples/chat.c in the source tree. +// cookie-based way please refer to the examples/chat in the source tree. // // If password is not NULL, entry is added (or modified if already exists). // If password is NULL, entry is deleted. diff --git a/build/Info.plist b/resources/Info.plist similarity index 100% rename from build/Info.plist rename to resources/Info.plist diff --git a/build/Makefile.in-lua b/resources/Makefile.in-lua similarity index 94% rename from build/Makefile.in-lua rename to resources/Makefile.in-lua index 572b8ac0..7ec3e561 100644 --- a/build/Makefile.in-lua +++ b/resources/Makefile.in-lua @@ -3,7 +3,7 @@ # License http://opensource.org/licenses/mit-license.php MIT License # -LUA_DIR = lua-5.2.2/src +LUA_DIR = src/third_party/lua-5.2.2/src LUA_SOURCE_FILES = lapi.c \ lauxlib.c \ @@ -42,7 +42,7 @@ LUA_SOURCES = $(addprefix $(LUA_DIR)/, $(LUA_SOURCE_FILES)) LUA_OBJECTS = $(LUA_SOURCES:.c=.o) LUA_CFLAGS = -I$(LUA_DIR) -DLUA_COMPAT_ALL -SQLITE_DIR = build +SQLITE_DIR = src/third_party SQLITE_SOURCE_FILES = sqlite3.c lsqlite3.c SQLITE_SOURCES = $(addprefix $(SQLITE_DIR)/, $(SQLITE_SOURCE_FILES)) SQLITE_OBJECTS = $(SQLITE_SOURCES:.c=.o) diff --git a/build/Makefile.in-os b/resources/Makefile.in-os similarity index 100% rename from build/Makefile.in-os rename to resources/Makefile.in-os diff --git a/build/civetweb.icns b/resources/civetweb.icns similarity index 100% rename from build/civetweb.icns rename to resources/civetweb.icns diff --git a/build/civetweb.psd b/resources/civetweb.psd similarity index 100% rename from build/civetweb.psd rename to resources/civetweb.psd diff --git a/build/civetweb_16x16.png b/resources/civetweb_16x16.png similarity index 100% rename from build/civetweb_16x16.png rename to resources/civetweb_16x16.png diff --git a/build/civetweb_16x16@2.png b/resources/civetweb_16x16@2.png similarity index 100% rename from build/civetweb_16x16@2.png rename to resources/civetweb_16x16@2.png diff --git a/build/civetweb_22x22.png b/resources/civetweb_22x22.png similarity index 100% rename from build/civetweb_22x22.png rename to resources/civetweb_22x22.png diff --git a/build/civetweb_22x22@2.png b/resources/civetweb_22x22@2.png similarity index 100% rename from build/civetweb_22x22@2.png rename to resources/civetweb_22x22@2.png diff --git a/build/civetweb_32x32.png b/resources/civetweb_32x32.png similarity index 100% rename from build/civetweb_32x32.png rename to resources/civetweb_32x32.png diff --git a/build/civetweb_32x32@2.png b/resources/civetweb_32x32@2.png similarity index 100% rename from build/civetweb_32x32@2.png rename to resources/civetweb_32x32@2.png diff --git a/build/civetweb_64x64.png b/resources/civetweb_64x64.png similarity index 100% rename from build/civetweb_64x64.png rename to resources/civetweb_64x64.png diff --git a/build/civetweb_64x64@2.png b/resources/civetweb_64x64@2.png similarity index 100% rename from build/civetweb_64x64@2.png rename to resources/civetweb_64x64@2.png diff --git a/build/dll.def b/resources/dll.def similarity index 100% rename from build/dll.def rename to resources/dll.def diff --git a/build/jni/Android.mk b/resources/jni/Android.mk similarity index 79% rename from build/jni/Android.mk rename to resources/jni/Android.mk index 6fdf596f..f24981a6 100644 --- a/build/jni/Android.mk +++ b/resources/jni/Android.mk @@ -2,5 +2,5 @@ LOCAL_PATH := $(call my-dir)/../.. include $(CLEAR_VARS) LOCAL_CFLAGS := -std=c99 -O2 -W -Wall -pthread -pipe $(COPT) LOCAL_MODULE := civetweb -LOCAL_SRC_FILES := main.c civetweb.c +LOCAL_SRC_FILES := src\main.c src\civetweb.c include $(BUILD_EXECUTABLE) diff --git a/build/res.rc b/resources/res.rc similarity index 100% rename from build/res.rc rename to resources/res.rc diff --git a/build/ssl_cert.pem b/resources/ssl_cert.pem similarity index 100% rename from build/ssl_cert.pem rename to resources/ssl_cert.pem diff --git a/build/systray.ico b/resources/systray.ico similarity index 100% rename from build/systray.ico rename to resources/systray.ico diff --git a/src/CivetServer.cpp b/src/CivetServer.cpp new file mode 100644 index 00000000..7aba32e8 --- /dev/null +++ b/src/CivetServer.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2013 No Face Press, LLC + * License http://opensource.org/licenses/mit-license.php MIT License + */ + +#include "CivetServer.h" + +#include +#include + +#ifndef UNUSED_PARAMETER + #define UNUSED_PARAMETER(x) (void)(x) +#endif + +bool CivetHandler::handleGet(CivetServer *server, struct mg_connection *conn) { + UNUSED_PARAMETER(server); + UNUSED_PARAMETER(conn); + return false; +} + +bool CivetHandler::handlePost(CivetServer *server, struct mg_connection *conn) { + UNUSED_PARAMETER(server); + UNUSED_PARAMETER(conn); + return false; +} + +bool CivetHandler::handlePut(CivetServer *server, struct mg_connection *conn) { + UNUSED_PARAMETER(server); + UNUSED_PARAMETER(conn); + return false; +} + +bool CivetHandler::handleDelete(CivetServer *server, struct mg_connection *conn) { + UNUSED_PARAMETER(server); + UNUSED_PARAMETER(conn); + return false; +} + +int CivetServer::begin_request_callback(struct mg_connection *conn) { + struct mg_request_info *request_info = mg_get_request_info(conn); + + if (!request_info->user_data) + return 0; + + CivetServer *me = (CivetServer*) (request_info->user_data); + + if (me->handleRequest(conn)) { + return 1; // Mark as processed + } + + return 0; +} + +bool CivetServer::handleRequest(struct mg_connection *conn) { + struct mg_request_info *request_info = mg_get_request_info(conn); + + CivetHandler *handler = getHandler(request_info->uri); + if (handler) { + if (strcmp(request_info->request_method, "GET") == 0) { + return handler->handleGet(this, conn); + } else if (strcmp(request_info->request_method, "POST") == 0) { + return handler->handlePost(this, conn); + } else if (strcmp(request_info->request_method, "PUT") == 0) { + return !handler->handlePost(this, conn); + } else if (strcmp(request_info->request_method, "DELETE") == 0) { + return !handler->handlePost(this, conn); + } + } + + return false; // No handler found +} + +CivetServer::CivetServer(const char **options, + const struct mg_callbacks *_callbacks) : + context(0) { + + struct mg_callbacks callbacks; + + if (_callbacks) { + memcpy(&callbacks, _callbacks, sizeof(callbacks)); + } else { + memset(&callbacks, 0, sizeof(callbacks)); + } + callbacks.begin_request = &begin_request_callback; + + context = mg_start(&callbacks, this, options); +} + +CivetServer::~CivetServer() { + close(); +} + +CivetHandler *CivetServer::getHandler(const char *uri, unsigned urilen) const { + + for (unsigned index = 0; index < uris.size(); index++) { + const std::string &handlerURI = uris[index]; + + // first try for an exact match + if (handlerURI == uri) { + return handlers[index]; + } + + // next try for a partial match + // we will accept uri/something + if (handlerURI.length() < urilen + && uri[handlerURI.length()] == '/' + && handlerURI.compare(0, handlerURI.length(), uri, handlerURI.length()) == 0) { + + return handlers[index]; + } + } + + return 0; // none found + +} + +void CivetServer::addHandler(const std::string &uri, CivetHandler *handler) { + int index = getIndex(uri); + if (index < 0) { + uris.push_back(uri); + handlers.push_back(handler); + } else if (handlers[index] != handler) { + delete handlers[index]; + handlers[index] = handler; + } +} + +void CivetServer::removeHandler(const std::string &uri) { + int index = getIndex(uri); + if (index >= 0) { + uris.erase(uris.begin() + index, uris.begin() + index + 1); + handlers.erase(handlers.begin() + index, handlers.begin() + index + 1); + } +} + +int CivetServer::getIndex(const std::string &uri) const { + for (unsigned index = 0; index < uris.size(); index++) { + if (uris[index].compare(uri) == 0) + return index; + } + return -1; +} + +void CivetServer::close() { + if (context) { + mg_stop (context); + context = 0; + } + for (int i = handlers.size() - 1; i >= 0; i--) { + delete handlers[i]; + } + handlers.clear(); + uris.clear(); + +} diff --git a/civetweb.c b/src/civetweb.c similarity index 100% rename from civetweb.c rename to src/civetweb.c diff --git a/main.c b/src/main.c similarity index 100% rename from main.c rename to src/main.c diff --git a/md5.inl b/src/md5.inl similarity index 100% rename from md5.inl rename to src/md5.inl diff --git a/mod_lua.inl b/src/mod_lua.inl similarity index 100% rename from mod_lua.inl rename to src/mod_lua.inl diff --git a/build/lsqlite3.c b/src/third_party/lsqlite3.c similarity index 100% rename from build/lsqlite3.c rename to src/third_party/lsqlite3.c diff --git a/lua-5.2.2/Makefile b/src/third_party/lua-5.2.2/Makefile similarity index 100% rename from lua-5.2.2/Makefile rename to src/third_party/lua-5.2.2/Makefile diff --git a/lua-5.2.2/README b/src/third_party/lua-5.2.2/README similarity index 100% rename from lua-5.2.2/README rename to src/third_party/lua-5.2.2/README diff --git a/lua-5.2.2/doc/contents.html b/src/third_party/lua-5.2.2/doc/contents.html similarity index 100% rename from lua-5.2.2/doc/contents.html rename to src/third_party/lua-5.2.2/doc/contents.html diff --git a/lua-5.2.2/doc/logo.gif b/src/third_party/lua-5.2.2/doc/logo.gif similarity index 100% rename from lua-5.2.2/doc/logo.gif rename to src/third_party/lua-5.2.2/doc/logo.gif diff --git a/lua-5.2.2/doc/lua.1 b/src/third_party/lua-5.2.2/doc/lua.1 similarity index 100% rename from lua-5.2.2/doc/lua.1 rename to src/third_party/lua-5.2.2/doc/lua.1 diff --git a/lua-5.2.2/doc/lua.css b/src/third_party/lua-5.2.2/doc/lua.css similarity index 100% rename from lua-5.2.2/doc/lua.css rename to src/third_party/lua-5.2.2/doc/lua.css diff --git a/lua-5.2.2/doc/luac.1 b/src/third_party/lua-5.2.2/doc/luac.1 similarity index 100% rename from lua-5.2.2/doc/luac.1 rename to src/third_party/lua-5.2.2/doc/luac.1 diff --git a/lua-5.2.2/doc/manual.css b/src/third_party/lua-5.2.2/doc/manual.css similarity index 100% rename from lua-5.2.2/doc/manual.css rename to src/third_party/lua-5.2.2/doc/manual.css diff --git a/lua-5.2.2/doc/manual.html b/src/third_party/lua-5.2.2/doc/manual.html similarity index 100% rename from lua-5.2.2/doc/manual.html rename to src/third_party/lua-5.2.2/doc/manual.html diff --git a/lua-5.2.2/doc/osi-certified-72x60.png b/src/third_party/lua-5.2.2/doc/osi-certified-72x60.png similarity index 100% rename from lua-5.2.2/doc/osi-certified-72x60.png rename to src/third_party/lua-5.2.2/doc/osi-certified-72x60.png diff --git a/lua-5.2.2/doc/readme.html b/src/third_party/lua-5.2.2/doc/readme.html similarity index 100% rename from lua-5.2.2/doc/readme.html rename to src/third_party/lua-5.2.2/doc/readme.html diff --git a/lua-5.2.2/src/Makefile b/src/third_party/lua-5.2.2/src/Makefile similarity index 100% rename from lua-5.2.2/src/Makefile rename to src/third_party/lua-5.2.2/src/Makefile diff --git a/lua-5.2.2/src/lapi.c b/src/third_party/lua-5.2.2/src/lapi.c similarity index 100% rename from lua-5.2.2/src/lapi.c rename to src/third_party/lua-5.2.2/src/lapi.c diff --git a/lua-5.2.2/src/lapi.h b/src/third_party/lua-5.2.2/src/lapi.h similarity index 100% rename from lua-5.2.2/src/lapi.h rename to src/third_party/lua-5.2.2/src/lapi.h diff --git a/lua-5.2.2/src/lauxlib.c b/src/third_party/lua-5.2.2/src/lauxlib.c similarity index 100% rename from lua-5.2.2/src/lauxlib.c rename to src/third_party/lua-5.2.2/src/lauxlib.c diff --git a/lua-5.2.2/src/lauxlib.h b/src/third_party/lua-5.2.2/src/lauxlib.h similarity index 100% rename from lua-5.2.2/src/lauxlib.h rename to src/third_party/lua-5.2.2/src/lauxlib.h diff --git a/lua-5.2.2/src/lbaselib.c b/src/third_party/lua-5.2.2/src/lbaselib.c similarity index 100% rename from lua-5.2.2/src/lbaselib.c rename to src/third_party/lua-5.2.2/src/lbaselib.c diff --git a/lua-5.2.2/src/lbitlib.c b/src/third_party/lua-5.2.2/src/lbitlib.c similarity index 100% rename from lua-5.2.2/src/lbitlib.c rename to src/third_party/lua-5.2.2/src/lbitlib.c diff --git a/lua-5.2.2/src/lcode.c b/src/third_party/lua-5.2.2/src/lcode.c similarity index 100% rename from lua-5.2.2/src/lcode.c rename to src/third_party/lua-5.2.2/src/lcode.c diff --git a/lua-5.2.2/src/lcode.h b/src/third_party/lua-5.2.2/src/lcode.h similarity index 100% rename from lua-5.2.2/src/lcode.h rename to src/third_party/lua-5.2.2/src/lcode.h diff --git a/lua-5.2.2/src/lcorolib.c b/src/third_party/lua-5.2.2/src/lcorolib.c similarity index 100% rename from lua-5.2.2/src/lcorolib.c rename to src/third_party/lua-5.2.2/src/lcorolib.c diff --git a/lua-5.2.2/src/lctype.c b/src/third_party/lua-5.2.2/src/lctype.c similarity index 100% rename from lua-5.2.2/src/lctype.c rename to src/third_party/lua-5.2.2/src/lctype.c diff --git a/lua-5.2.2/src/lctype.h b/src/third_party/lua-5.2.2/src/lctype.h similarity index 100% rename from lua-5.2.2/src/lctype.h rename to src/third_party/lua-5.2.2/src/lctype.h diff --git a/lua-5.2.2/src/ldblib.c b/src/third_party/lua-5.2.2/src/ldblib.c similarity index 100% rename from lua-5.2.2/src/ldblib.c rename to src/third_party/lua-5.2.2/src/ldblib.c diff --git a/lua-5.2.2/src/ldebug.c b/src/third_party/lua-5.2.2/src/ldebug.c similarity index 100% rename from lua-5.2.2/src/ldebug.c rename to src/third_party/lua-5.2.2/src/ldebug.c diff --git a/lua-5.2.2/src/ldebug.h b/src/third_party/lua-5.2.2/src/ldebug.h similarity index 100% rename from lua-5.2.2/src/ldebug.h rename to src/third_party/lua-5.2.2/src/ldebug.h diff --git a/lua-5.2.2/src/ldo.c b/src/third_party/lua-5.2.2/src/ldo.c similarity index 100% rename from lua-5.2.2/src/ldo.c rename to src/third_party/lua-5.2.2/src/ldo.c diff --git a/lua-5.2.2/src/ldo.h b/src/third_party/lua-5.2.2/src/ldo.h similarity index 100% rename from lua-5.2.2/src/ldo.h rename to src/third_party/lua-5.2.2/src/ldo.h diff --git a/lua-5.2.2/src/ldump.c b/src/third_party/lua-5.2.2/src/ldump.c similarity index 100% rename from lua-5.2.2/src/ldump.c rename to src/third_party/lua-5.2.2/src/ldump.c diff --git a/lua-5.2.2/src/lfunc.c b/src/third_party/lua-5.2.2/src/lfunc.c similarity index 100% rename from lua-5.2.2/src/lfunc.c rename to src/third_party/lua-5.2.2/src/lfunc.c diff --git a/lua-5.2.2/src/lfunc.h b/src/third_party/lua-5.2.2/src/lfunc.h similarity index 100% rename from lua-5.2.2/src/lfunc.h rename to src/third_party/lua-5.2.2/src/lfunc.h diff --git a/lua-5.2.2/src/lgc.c b/src/third_party/lua-5.2.2/src/lgc.c similarity index 100% rename from lua-5.2.2/src/lgc.c rename to src/third_party/lua-5.2.2/src/lgc.c diff --git a/lua-5.2.2/src/lgc.h b/src/third_party/lua-5.2.2/src/lgc.h similarity index 100% rename from lua-5.2.2/src/lgc.h rename to src/third_party/lua-5.2.2/src/lgc.h diff --git a/lua-5.2.2/src/linit.c b/src/third_party/lua-5.2.2/src/linit.c similarity index 100% rename from lua-5.2.2/src/linit.c rename to src/third_party/lua-5.2.2/src/linit.c diff --git a/lua-5.2.2/src/liolib.c b/src/third_party/lua-5.2.2/src/liolib.c similarity index 100% rename from lua-5.2.2/src/liolib.c rename to src/third_party/lua-5.2.2/src/liolib.c diff --git a/lua-5.2.2/src/llex.c b/src/third_party/lua-5.2.2/src/llex.c similarity index 100% rename from lua-5.2.2/src/llex.c rename to src/third_party/lua-5.2.2/src/llex.c diff --git a/lua-5.2.2/src/llex.h b/src/third_party/lua-5.2.2/src/llex.h similarity index 100% rename from lua-5.2.2/src/llex.h rename to src/third_party/lua-5.2.2/src/llex.h diff --git a/lua-5.2.2/src/llimits.h b/src/third_party/lua-5.2.2/src/llimits.h similarity index 100% rename from lua-5.2.2/src/llimits.h rename to src/third_party/lua-5.2.2/src/llimits.h diff --git a/lua-5.2.2/src/lmathlib.c b/src/third_party/lua-5.2.2/src/lmathlib.c similarity index 100% rename from lua-5.2.2/src/lmathlib.c rename to src/third_party/lua-5.2.2/src/lmathlib.c diff --git a/lua-5.2.2/src/lmem.c b/src/third_party/lua-5.2.2/src/lmem.c similarity index 100% rename from lua-5.2.2/src/lmem.c rename to src/third_party/lua-5.2.2/src/lmem.c diff --git a/lua-5.2.2/src/lmem.h b/src/third_party/lua-5.2.2/src/lmem.h similarity index 100% rename from lua-5.2.2/src/lmem.h rename to src/third_party/lua-5.2.2/src/lmem.h diff --git a/lua-5.2.2/src/loadlib.c b/src/third_party/lua-5.2.2/src/loadlib.c similarity index 100% rename from lua-5.2.2/src/loadlib.c rename to src/third_party/lua-5.2.2/src/loadlib.c diff --git a/lua-5.2.2/src/lobject.c b/src/third_party/lua-5.2.2/src/lobject.c similarity index 100% rename from lua-5.2.2/src/lobject.c rename to src/third_party/lua-5.2.2/src/lobject.c diff --git a/lua-5.2.2/src/lobject.h b/src/third_party/lua-5.2.2/src/lobject.h similarity index 100% rename from lua-5.2.2/src/lobject.h rename to src/third_party/lua-5.2.2/src/lobject.h diff --git a/lua-5.2.2/src/lopcodes.c b/src/third_party/lua-5.2.2/src/lopcodes.c similarity index 100% rename from lua-5.2.2/src/lopcodes.c rename to src/third_party/lua-5.2.2/src/lopcodes.c diff --git a/lua-5.2.2/src/lopcodes.h b/src/third_party/lua-5.2.2/src/lopcodes.h similarity index 100% rename from lua-5.2.2/src/lopcodes.h rename to src/third_party/lua-5.2.2/src/lopcodes.h diff --git a/lua-5.2.2/src/loslib.c b/src/third_party/lua-5.2.2/src/loslib.c similarity index 100% rename from lua-5.2.2/src/loslib.c rename to src/third_party/lua-5.2.2/src/loslib.c diff --git a/lua-5.2.2/src/lparser.c b/src/third_party/lua-5.2.2/src/lparser.c similarity index 100% rename from lua-5.2.2/src/lparser.c rename to src/third_party/lua-5.2.2/src/lparser.c diff --git a/lua-5.2.2/src/lparser.h b/src/third_party/lua-5.2.2/src/lparser.h similarity index 100% rename from lua-5.2.2/src/lparser.h rename to src/third_party/lua-5.2.2/src/lparser.h diff --git a/lua-5.2.2/src/lstate.c b/src/third_party/lua-5.2.2/src/lstate.c similarity index 100% rename from lua-5.2.2/src/lstate.c rename to src/third_party/lua-5.2.2/src/lstate.c diff --git a/lua-5.2.2/src/lstate.h b/src/third_party/lua-5.2.2/src/lstate.h similarity index 100% rename from lua-5.2.2/src/lstate.h rename to src/third_party/lua-5.2.2/src/lstate.h diff --git a/lua-5.2.2/src/lstring.c b/src/third_party/lua-5.2.2/src/lstring.c similarity index 100% rename from lua-5.2.2/src/lstring.c rename to src/third_party/lua-5.2.2/src/lstring.c diff --git a/lua-5.2.2/src/lstring.h b/src/third_party/lua-5.2.2/src/lstring.h similarity index 100% rename from lua-5.2.2/src/lstring.h rename to src/third_party/lua-5.2.2/src/lstring.h diff --git a/lua-5.2.2/src/lstrlib.c b/src/third_party/lua-5.2.2/src/lstrlib.c similarity index 100% rename from lua-5.2.2/src/lstrlib.c rename to src/third_party/lua-5.2.2/src/lstrlib.c diff --git a/lua-5.2.2/src/ltable.c b/src/third_party/lua-5.2.2/src/ltable.c similarity index 100% rename from lua-5.2.2/src/ltable.c rename to src/third_party/lua-5.2.2/src/ltable.c diff --git a/lua-5.2.2/src/ltable.h b/src/third_party/lua-5.2.2/src/ltable.h similarity index 100% rename from lua-5.2.2/src/ltable.h rename to src/third_party/lua-5.2.2/src/ltable.h diff --git a/lua-5.2.2/src/ltablib.c b/src/third_party/lua-5.2.2/src/ltablib.c similarity index 100% rename from lua-5.2.2/src/ltablib.c rename to src/third_party/lua-5.2.2/src/ltablib.c diff --git a/lua-5.2.2/src/ltm.c b/src/third_party/lua-5.2.2/src/ltm.c similarity index 100% rename from lua-5.2.2/src/ltm.c rename to src/third_party/lua-5.2.2/src/ltm.c diff --git a/lua-5.2.2/src/ltm.h b/src/third_party/lua-5.2.2/src/ltm.h similarity index 100% rename from lua-5.2.2/src/ltm.h rename to src/third_party/lua-5.2.2/src/ltm.h diff --git a/lua-5.2.2/src/lua.c b/src/third_party/lua-5.2.2/src/lua.c similarity index 100% rename from lua-5.2.2/src/lua.c rename to src/third_party/lua-5.2.2/src/lua.c diff --git a/lua-5.2.2/src/lua.h b/src/third_party/lua-5.2.2/src/lua.h similarity index 100% rename from lua-5.2.2/src/lua.h rename to src/third_party/lua-5.2.2/src/lua.h diff --git a/lua-5.2.2/src/lua.hpp b/src/third_party/lua-5.2.2/src/lua.hpp similarity index 100% rename from lua-5.2.2/src/lua.hpp rename to src/third_party/lua-5.2.2/src/lua.hpp diff --git a/lua-5.2.2/src/luac.c b/src/third_party/lua-5.2.2/src/luac.c similarity index 100% rename from lua-5.2.2/src/luac.c rename to src/third_party/lua-5.2.2/src/luac.c diff --git a/lua-5.2.2/src/luaconf.h b/src/third_party/lua-5.2.2/src/luaconf.h similarity index 100% rename from lua-5.2.2/src/luaconf.h rename to src/third_party/lua-5.2.2/src/luaconf.h diff --git a/lua-5.2.2/src/lualib.h b/src/third_party/lua-5.2.2/src/lualib.h similarity index 100% rename from lua-5.2.2/src/lualib.h rename to src/third_party/lua-5.2.2/src/lualib.h diff --git a/lua-5.2.2/src/lundump.c b/src/third_party/lua-5.2.2/src/lundump.c similarity index 100% rename from lua-5.2.2/src/lundump.c rename to src/third_party/lua-5.2.2/src/lundump.c diff --git a/lua-5.2.2/src/lundump.h b/src/third_party/lua-5.2.2/src/lundump.h similarity index 100% rename from lua-5.2.2/src/lundump.h rename to src/third_party/lua-5.2.2/src/lundump.h diff --git a/lua-5.2.2/src/lvm.c b/src/third_party/lua-5.2.2/src/lvm.c similarity index 100% rename from lua-5.2.2/src/lvm.c rename to src/third_party/lua-5.2.2/src/lvm.c diff --git a/lua-5.2.2/src/lvm.h b/src/third_party/lua-5.2.2/src/lvm.h similarity index 100% rename from lua-5.2.2/src/lvm.h rename to src/third_party/lua-5.2.2/src/lvm.h diff --git a/lua-5.2.2/src/lzio.c b/src/third_party/lua-5.2.2/src/lzio.c similarity index 100% rename from lua-5.2.2/src/lzio.c rename to src/third_party/lua-5.2.2/src/lzio.c diff --git a/lua-5.2.2/src/lzio.h b/src/third_party/lua-5.2.2/src/lzio.h similarity index 100% rename from lua-5.2.2/src/lzio.h rename to src/third_party/lua-5.2.2/src/lzio.h diff --git a/build/sqlite3.c b/src/third_party/sqlite3.c similarity index 100% rename from build/sqlite3.c rename to src/third_party/sqlite3.c diff --git a/build/sqlite3.h b/src/third_party/sqlite3.h similarity index 100% rename from build/sqlite3.h rename to src/third_party/sqlite3.h diff --git a/test/MakefileTest.mk b/test/MakefileTest.mk new file mode 100644 index 00000000..644193b9 --- /dev/null +++ b/test/MakefileTest.mk @@ -0,0 +1,62 @@ +# +# Copyright (c) 2013 No Face Press, LLC +# License http://opensource.org/licenses/mit-license.php MIT License +# + +#This makefile is used to test the other Makefiles + +TOP = .. +TEST_OUT = test_install + +include $(TOP)/resources/Makefile.in-os + +all: test + +test: buildoptions buildlibs buildinstall +test: buildexamples + +ifeq ($(TARGET_OS),OSX) +test: dmg +endif + +test: clean + @echo PASSED + +dmg: + $(MAKE) -C $(TOP) -f Makefile.osx clean package + +buildexamples: + $(MAKE) -C $(TOP)/examples/chat clean all + $(MAKE) -C $(TOP)/examples/chat clean + $(MAKE) -C $(TOP)/examples/hello clean all + $(MAKE) -C $(TOP)/examples/hello clean + $(MAKE) -C $(TOP)/examples/post clean all + $(MAKE) -C $(TOP)/examples/post clean + $(MAKE) -C $(TOP)/examples/upload clean all + $(MAKE) -C $(TOP)/examples/upload clean + $(MAKE) -C $(TOP)/examples/websocket clean all + $(MAKE) -C $(TOP)/examples/websocket clean + $(MAKE) -C $(TOP)/examples/embedded_cpp clean all + $(MAKE) -C $(TOP)/examples/embedded_cpp clean + +buildoptions: + $(MAKE) -C $(TOP) clean build + $(MAKE) -C $(TOP) clean build WITH_IPV6=1 + $(MAKE) -C $(TOP) clean build WITH_WEBSOCKET=1 + $(MAKE) -C $(TOP) clean build WITH_LUA=1 + $(MAKE) -C $(TOP) clean build WITH_LUA=1 WITH_IPV6=1 WITH_WEBSOCKET=1 + +buildinstall: + $(MAKE) -C $(TOP) clean install PREFIX=$(TEST_OUT) + +buildlibs: + $(MAKE) -C $(TOP) clean lib + $(MAKE) -C $(TOP) clean slib + $(MAKE) -C $(TOP) clean lib WITH_CPP=1 + $(MAKE) -C $(TOP) clean slib WITH_CPP=1 + +clean: + $(MAKE) -C $(TOP) clean + rm -rf $(TOP)/$(TEST_OUT) + +.PHONY: all buildoptions buildinstall clean os linux diff --git a/test/test.pl b/test/test.pl index 9974b977..e5034890 100644 --- a/test/test.pl +++ b/test/test.pl @@ -140,7 +140,7 @@ $SIG{ALRM} = sub { die "timeout\n" }; # Make sure we export only symbols that start with "mg_", and keep local # symbols static. if ($^O =~ /darwin|bsd|linux/) { - my $out = `(cc -c civetweb.c && nm civetweb.o) | grep ' T '`; + my $out = `(cc -c src/civetweb.c && nm src/civetweb.o) | grep ' T '`; foreach (split /\n/, $out) { /T\s+_?mg_.+/ or fail("Exported symbol $_") } diff --git a/test/unit_test.c b/test/unit_test.c index 95d8347d..07fe9d30 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -28,9 +28,9 @@ #define USE_IPV6 #endif -// USE_* definitions must be made before #include "civetweb.c" ! +// USE_* definitions must be made before #include "src/civetweb.c" ! -#include "civetweb.c" +#include "src/civetweb.c" static int s_total_tests = 0; static int s_failed_tests = 0; @@ -223,7 +223,7 @@ static void upload_cb(struct mg_connection *conn, const char *path) { if (atoi(ri->query_string) == 1) { ASSERT(!strcmp(path, "./upload_test.txt")); - ASSERT((p1 = read_file("civetweb.c", &len1)) != NULL); + ASSERT((p1 = read_file("src/civetweb.c", &len1)) != NULL); ASSERT((p2 = read_file(path, &len2)) != NULL); ASSERT(len1 == len2); ASSERT(memcmp(p1, p2, len1) == 0); @@ -231,7 +231,7 @@ static void upload_cb(struct mg_connection *conn, const char *path) { remove(upload_filename); } else if (atoi(ri->query_string) == 2) { if (!strcmp(path, "./upload_test.txt")) { - ASSERT((p1 = read_file("civetweb.h", &len1)) != NULL); + ASSERT((p1 = read_file("include/civetweb.h", &len1)) != NULL); ASSERT((p2 = read_file(path, &len2)) != NULL); ASSERT(len1 == len2); ASSERT(memcmp(p1, p2, len1) == 0); @@ -289,7 +289,7 @@ static const char *OPTIONS[] = { "document_root", ".", "listening_ports", LISTENING_ADDR, "enable_keep_alive", "yes", - "ssl_certificate", "build/ssl_cert.pem", + "ssl_certificate", "resources/ssl_cert.pem", NULL, }; @@ -330,10 +330,10 @@ static void test_mg_download(void) { // Fetch civetweb.c, should succeed ASSERT((conn = mg_download("localhost", port, 1, ebuf, sizeof(ebuf), "%s", - "GET /civetweb.c HTTP/1.0\r\n\r\n")) != NULL); + "GET /src/civetweb.c HTTP/1.0\r\n\r\n")) != NULL); ASSERT(!strcmp(conn->request_info.uri, "200")); ASSERT((p1 = read_conn(conn, &len1)) != NULL); - ASSERT((p2 = read_file("civetweb.c", &len2)) != NULL); + ASSERT((p2 = read_file("src/civetweb.c", &len2)) != NULL); ASSERT(len1 == len2); ASSERT(memcmp(p1, p2, len1) == 0); free(p1), free(p2); @@ -395,7 +395,7 @@ static void test_mg_upload(void) { ASSERT((ctx = mg_start(&CALLBACKS, NULL, OPTIONS)) != NULL); // Upload one file - ASSERT((file_data = read_file("civetweb.c", &file_len)) != NULL); + ASSERT((file_data = read_file("src/civetweb.c", &file_len)) != NULL); post_data = NULL; post_data_len = alloc_printf(&post_data, 0, "--%s\r\n" @@ -421,7 +421,7 @@ static void test_mg_upload(void) { mg_close_connection(conn); // Upload two files - ASSERT((file_data = read_file("civetweb.h", &file_len)) != NULL); + ASSERT((file_data = read_file("include/civetweb.h", &file_len)) != NULL); ASSERT((file2_data = read_file("README.md", &file2_len)) != NULL); post_data = NULL; post_data_len = alloc_printf(&post_data, 0,