1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-08-09 03:22:45 +03:00

Updated references to LibHTTP

This commit is contained in:
Lammert Bies
2016-11-15 20:04:22 +01:00
parent 69063333c0
commit 6566341735
78 changed files with 386 additions and 1637 deletions

View File

@@ -1,4 +1,9 @@
# Libhttp Contributors
* Lammert Bies
# Civetweb Contributors # Civetweb Contributors
Libhttp is based on Civetweb which is based on the MIT licensed version of Mongoose. The contributors list mentioned here is the list as it was present in the CREDITS.md file of the Civetweb project when it was forked to Libhttp.
* Alex Kozlov * Alex Kozlov
* bel2125 * bel2125

View File

@@ -6,12 +6,14 @@ aspects of the software. Not all licenses may apply depending
on the features chosen. on the features chosen.
Civetweb License Libhttp License
----- -----
### Included with all features. ### Included with all features.
> Copyright (c) 2013-2015 The CivetWeb developers ([CREDITS.md](https://github.com/civetweb/civetweb/blob/master/CREDITS.md)) > Copyright (c) 2016 Lammert Bies
>
> Copyright (c) 2013-2016 The CivetWeb developers ([CREDITS.md](https://github.com/civetweb/civetweb/blob/master/CREDITS.md))
> >
> Copyright (c) 2004-2013 Sergey Lyubka > Copyright (c) 2004-2013 Sergey Lyubka
> >

View File

@@ -12,41 +12,37 @@ Libhttp can be used by developers as a library, to add web server functionality
It can also be used by end users as a stand-alone web server. It is available as single executable, no installation is required. It can also be used by end users as a stand-alone web server. It is available as single executable, no installation is required.
Libhttp is a fork of the Mongoose (MIT)/Civetweb family of http server libraries with the focus on event Libhttp is a fork of the Mongoose (MIT)/Civetweb family of http server libraries with the focus on event
driven efficient communication and good documentation. driven efficient communication, clean code and good documentation.
Where to find the official version? Where to find the official version?
----------------------------------- -----------------------------------
End users can download Libhttp at Github Documentation of the library can be found on [www.libhttp.org](http://www.libhttp.org)
<!-- [https://sourceforge.net/projects/civetweb/](https://sourceforge.net/projects/civetweb/) -->
Developers can contribute to Libhttp via GitHub Developers can download and contribute to Libhttp via GitHub
[https://github.com/lammertb/libhttp](https://github.com/lammertb/libhttp) [https://github.com/lammertb/libhttp](https://github.com/lammertb/libhttp)
Trouble tickets should be filed on GitHub Trouble tickets should be filed on GitHub
[https://github.com/lammertb/libhttp/issues](https://github.com/lammertb/libhttp/issues) [https://github.com/lammertb/libhttp/issues](https://github.com/lammertb/libhttp/issues)
<!-- Discussion/support group and announcements are at Google Groups
[https://groups.google.com/d/forum/civetweb](https://groups.google.com/d/forum/civetweb) -->
Quick start documentation Quick start documentation
-------------------------- --------------------------
- [docs/Installing.md](https://github.com/civetweb/civetweb/blob/master/docs/Installing.md) - Install Guide (for end users using pre-built binaries) - [docs/APIReference.md](docs/APIReference.md) - Reference of the C programming API
- [docs/UserManual.md](https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md) - End User Guide - [docs/Installing.md](docs/Installing.md) - Install Guide (for end users using pre-built binaries)
- [docs/Building.md](https://github.com/civetweb/civetweb/blob/master/docs/Building.md) - Building the Server (quick start guide) - [docs/UserManual.md](docs/UserManual.md) - End User Guide
- [docs/Embedding.md](https://github.com/civetweb/civetweb/blob/master/docs/Embedding.md) - Embedding (how to add HTTP support to an existing application) - [docs/Building.md](docs/Building.md) - Building the Server (quick start guide)
- [docs/OpenSSL.md](https://github.com/civetweb/civetweb/blob/master/docs/OpenSSL.md) - Adding HTTPS (SSL/TLS) support using OpenSSL. - [docs/Embedding.md](docs/Embedding.md) - Embedding (how to add HTTP support to an existing application)
- [RELEASE_NOTES.md](https://github.com/civetweb/civetweb/blob/master/RELEASE_NOTES.md) - Release Notes - [docs/OpenSSL.md](docs/OpenSSL.md) - Adding HTTPS (SSL/TLS) support using OpenSSL.
- [LICENSE.md](https://github.com/civetweb/civetweb/blob/master/LICENSE.md) - Copyright License - [RELEASE_NOTES.md](RELEASE_NOTES.md) - Release Notes
- [LICENSE.md](LICENSE.md) - Copyright License
Overview Overview
-------- --------
CivetWeb keeps the balance between functionality and LibHTTP keeps the balance between functionality and
simplicity by a carefully selected list of features: simplicity by a carefully selected list of features:
- Liberal, commercial-friendly, permissive, - Liberal, commercial-friendly, permissive,
@@ -56,7 +52,7 @@ simplicity by a carefully selected list of features:
- Forked from [Mongoose](https://code.google.com/p/mongoose/) in 2013, before - Forked from [Mongoose](https://code.google.com/p/mongoose/) in 2013, before
it changed the licence from MIT to commercial + GPL. A lot of enchancements it changed the licence from MIT to commercial + GPL. A lot of enchancements
have been added since that time, see have been added since that time, see
[RELEASE_NOTES.md](https://github.com/civetweb/civetweb/blob/master/RELEASE_NOTES.md). [RELEASE_NOTES.md](RELEASE_NOTES.md).
- Works on Windows, Mac, Linux, UNIX, iPhone, Android, Buildroot, and many - Works on Windows, Mac, Linux, UNIX, iPhone, Android, Buildroot, and many
other platforms. other platforms.
- Scripting and database support (Lua scipts, Lua Server Pages, CGI + SQLite - Scripting and database support (Lua scipts, Lua Server Pages, CGI + SQLite
@@ -78,31 +74,30 @@ simplicity by a carefully selected list of features:
### Optionally included software ### Optionally included software
<a href="http://lua.org"> <a href="http://lua.org">
![Lua](https://raw.github.com/civetweb/civetweb/master/resources/lua-logo.jpg "Lua Logo") ![Lua](https://raw.github.com/lammertb/libhttp/master/resources/lua-logo.jpg "Lua Logo")
</a> </a>
<a href="http://sqlite.org"> <a href="http://sqlite.org">
![Sqlite3](https://raw.github.com/civetweb/civetweb/master/resources/sqlite3-logo.jpg "Sqlite3 Logo") ![Sqlite3](https://raw.github.com/lammertb/libhttp/master/resources/sqlite3-logo.jpg "Sqlite3 Logo")
</a> </a>
<a href="http://keplerproject.github.io/luafilesystem/"> <a href="http://keplerproject.github.io/luafilesystem/">
![LuaFileSystem](https://raw.github.com/civetweb/civetweb/master/resources/luafilesystem-logo.jpg "LuaFileSystem Logo") ![LuaFileSystem](https://raw.github.com/lammertb/libhttp/master/resources/luafilesystem-logo.jpg "LuaFileSystem Logo")
</a> </a>
<a href="http://lua.sqlite.org/index.cgi/index"> <a href="http://lua.sqlite.org/index.cgi/index">
![LuaSQLite3](https://raw.github.com/civetweb/civetweb/master/resources/luasqlite-logo.jpg "LuaSQLite3 Logo") ![LuaSQLite3](https://raw.github.com/lammertb/libhttp/master/resources/luasqlite-logo.jpg "LuaSQLite3 Logo")
</a> </a>
<a href="http://viremo.eludi.net/LuaXML/index.html"> <a href="http://viremo.eludi.net/LuaXML/index.html">
![LuaXML](https://raw.github.com/civetweb/civetweb/master/resources/luaxml-logo.jpg "LuaXML Logo") ![LuaXML](https://raw.github.com/lammertb/libhttp/master/resources/luaxml-logo.jpg "LuaXML Logo")
</a> </a>
<a href="http://duktape.org"> <a href="http://duktape.org">
![Duktape](https://raw.github.com/civetweb/civetweb/master/resources/duktape-logo.png "Duktape Logo") ![Duktape](https://raw.github.com/lammertb/libhttp/master/resources/duktape-logo.png "Duktape Logo")
</a> </a>
Support Support
------- -------
This project is very easy to install and use. Please read the [documentation](https://github.com/civetweb/civetweb/blob/master/docs/) This project is very easy to install and use. Please read the [documentation](docs/)
and have a look at the [examples] (https://github.com/civetweb/civetweb/blob/master/examples/). and have a look at the [examples] (examples/).
More information may be found on the [mailing list](https://groups.google.com/d/forum/civetweb).
Contributions Contributions
@@ -113,24 +108,27 @@ Contributions are welcome provided all contributions carry the MIT license.
DO NOT APPLY fixes copied from Mongoose to this project to prevent GPL tainting. DO NOT APPLY fixes copied from Mongoose to this project to prevent GPL tainting.
Since 2013 CivetWeb and Mongoose are developed independently. By now the code base differs, so patches cannot be safely transfered in either direction. Since 2013 CivetWeb and Mongoose are developed independently. By now the code base differs, so patches cannot be safely transfered in either direction.
Some guidelines can be found in [docs/Contribution.md](https://github.com/civetweb/civetweb/blob/master/docs/Contribution.md). Some guidelines can be found in [docs/Contribution.md](docs/Contribution.md).
### Authors ### Authors
CivetWeb is based on the Mongoose project. The original author of Mongoose was LibHTTP is based on CivetWeb which in turn is based on the Mongoose project. The original author of Mongoose was
Sergey Lyubka (Copyright (c) 2004-2013 Sergey Lyubka, MIT license). Sergey Lyubka (Copyright (c) 2004-2013 Sergey Lyubka, MIT license).
However, in August 16, 2013, the [license of Mongoose has been changed](https://groups.google.com/forum/#!topic/mongoose-users/aafbOnHonkI) However, in August 16, 2013, the [license of Mongoose has been changed](https://groups.google.com/forum/#!topic/mongoose-users/aafbOnHonkI)
after writing and distributing the original code this project is based on. after writing and distributing the original code this project is based on.
The license change used to be described on the Mongoose Wikipedia page as well, but it's getting deleted there regularly.
CivetWeb has been forked from the last MIT version of Mongoose. CivetWeb has been forked from the last MIT version of Mongoose.
Since 2013, CivetWeb has seen many improvements from various authors Since 2013, CivetWeb has seen many improvements from various authors
(Copyright (c) 2013-2016 the CivetWeb developers, MIT license). (Copyright (c) 2013-2016 the CivetWeb developers, MIT license).
A list of authors can be found in [CREDITS.md](https://github.com/civetweb/civetweb/blob/master/CREDITS.md). A list of authors can be found in [CREDITS.md](CREDITS.md).
Using the CivetWeb project ensures the MIT licenses terms are applied and LibHTTP has been forked from a 2016 version of CivetWeb. It contains all updates in CivetWeb
upto the moment of forking and updates of later dates in CivetWeb may be used in LibHTTP
because they both use the same license. It is expected though that both projects will
go in different directions though so future compatibility is not guaranteed.
Using the LibHTTP project ensures the MIT licenses terms are applied and
GPL cannot be imposed on any of this code as long as it is sourced from GPL cannot be imposed on any of this code as long as it is sourced from
here. This code will remain free with the MIT license protection. here. This code will remain free with the MIT license protection.

View File

@@ -1,4 +1,16 @@
Release Notes v1.9 (work in progress) Release Notes v2.0 (work in progress)
===
### Objectives: *Clean up source code, proper documentation, focus on embedding*
Changes
-------
- Changed references from CivetWeb to LibHTTP in documentation
- Removed deprecated function `mg_upload();`
- Removed deprecated function `mg_get_valid_option_names();`
- Removed all build scripts except the script for `make`
Release Notes v1.9 (will never be released as LibHTTP)
=== ===
### Objectives: *Read client certificate information, bug fixes* ### Objectives: *Read client certificate information, bug fixes*

866
build.cmd
View File

@@ -1,866 +0,0 @@
:: Make sure the extensions are enabled
@verify other 2>nul
@setlocal EnableDelayedExpansion
@if errorlevel 1 (
call :print_usage "Failed to enable extensions"
exit /b 1
)
::Change the code page to unicode
@chcp 65001 1>nul 2>nul
@if errorlevel 1 (
call :print_usage "Failed to change the code page to unicode"
exit /b 1
)
:: Set up some global variables
@set project=civetweb
@set "script_name=%~nx0"
@set "script_folder=%~dp0"
@set "script_folder=%script_folder:~0,-1%"
@set "output_path=%script_folder%\output"
@set "build_path=%output_path%\build"
@set "install_path=%output_path%\install"
@set build_shared=OFF
@set build_type=Release
@set dependency_path=%TEMP%\%project%-build-dependencies
:: Check the command line parameters
@set logging_level=1
@set "options=%* "
@if not "!options!"=="!options:/? =!" set usage="Convenience script to build %project% with CMake"
@for %%a in (%options%) do @(
@set arg=%%~a
@set arg=!arg: =!
@set one=!arg:~0,1!
@set two=!arg:~0,2!
@if /i [!arg!] == [/q] set quiet=true
@if /i [!two!] == [/v] call :verbosity "!arg!"
@if /i [!arg!] == [/s] set build_shared=ON
@if /i [!arg!] == [/d] set build_type=Debug
@if /i not [!one!] == [/] (
if not defined generator (
set generator=!arg!
) else (
set usage="Too many generators: !method! !arg!" ^
"There should only be one generator parameter"
)
)
)
@if defined quiet (
set logging_level=0
)
@if not defined generator (
set generator=MSVC
)
@if /i not [%generator%] == [MinGW] (
if /i not [%generator%] == [MSVC] (
call :print_usage "Invalid argument: %generator%"
exit /b 1
)
)
:: Set up the logging
@set log_folder=%output_path%\logs
@call :iso8601 timestamp
@set log_path=%log_folder%\%timestamp%.log
@set log_keep=10
:: Only keep a certain amount of logs
@set /a "log_keep=log_keep-1"
@if not exist %log_folder% @mkdir %log_folder%
@for /f "skip=%log_keep%" %%f in ('dir /b /o-D /tc %log_folder%') do @(
call :log 4 "Removing old log file %log_folder%\%%f"
del %log_folder%\%%f
)
:: Set up some more global variables
@call :architecture arch
@call :windows_version win_ver win_ver_major win_ver_minor win_ver_rev
@call :script_source script_source
@if [%script_source%] == [explorer] (
set /a "logging_level=logging_level+1"
)
:: Print the usage or start the script
@set exit_code=0
@if defined usage (
call :print_usage %usage%
) else (
call :main
@if errorlevel 1 (
@call :log 0 "Failed to build the %project% project"
@set exit_code=1
)
)
:: Tell the user where the built files are
@call :log 5
@call :log 0 "The built files are available in %install_path%"
:: Stop the script if the user double clicked
@if [%script_source%] == [explorer] (
pause
)
@exit /b %exit_code%
@endlocal
@goto :eof
:: -------------------------- Functions start here ----------------------------
:main - Main function that performs the build
@setlocal
@call :log 6
@call :log 2 "Welcome to the %project% build script"
@call :log 6 "------------------------------------"
@call :log 6
@call :log 2 "This script builds the project using CMake"
@call :log 6
@call :log 2 "Generating %generator%..."
@call :log 6
@set methods=dependencies ^
generate ^
build ^
install
@for %%m in (%methods%) do @(
call :log 3 "Excuting the '%%m' method"
call :log 8
call :%%~m
if errorlevel 1 (
call :log 0 "Failed to complete the '%%~m' dependency routine"
call :log 0 "View the log at %log_path%"
exit /b 1
)
)
@call :log 6 "------------------------------------"
@call :log 2 "Build complete"
@call :log 6
@endlocal
@goto :eof
:print_usage - Prints the usage of the script
:: %* - message to print, each argument on it's own line
@setlocal
@for %%a in (%*) do @echo.%%~a
@echo.
@echo.build [/?][/v[v...]^|/q][MinGW^|MSVC]
@echo.
@echo. [MinGW^|(MSVC)]
@echo. Builds the library with one of the compilers
@echo. /s Builds shared libraries
@echo. /d Builds a debug variant of the project
@echo. /v Sets the output to be more verbose
@echo. /v[v...] Extra verbosity, /vv, /vvv, etc
@echo. /q Quiets the output
@echo. /? Shows this usage message
@echo.
@endlocal
@goto :eof
:dependencies - Installs any prerequisites for the build
@setlocal EnableDelayedExpansion
@if errorlevel 1 (
call :log 0 "Failed to enable extensions"
exit /b 1
)
@call :log 5
@call :log 0 "Installing dependencies for %generator%"
@if /i [%generator%] == [MinGW] (
call :mingw compiler_path
@if errorlevel 1 (
@call :log 5
@call :log 0 "Failed to find MinGW"
@exit /b 1
)
set "PATH=!compiler_path!;%PATH%"
@call :find_in_path gcc_executable gcc.exe
@if errorlevel 1 (
@call :log 5
@call :log 0 "Failed to find gcc.exe"
@exit /b 1
)
)
@if [%reboot_required%] equ [1] call :reboot
@endlocal & set "PATH=%PATH%"
@goto :eof
:generate - Uses CMake to generate the build files
@setlocal EnableDelayedExpansion
@if errorlevel 1 (
call :log 0 "Failed to enable extensions"
exit /b 1
)
@call :log 5
@call :log 0 "Generating CMake files for %generator%"
@call :cmake cmake_executable
@if errorlevel 1 (
@call :log 5
@call :log 0 "Need CMake to create the build files"
@exit /b 1
)
@if /i [%generator%] == [MinGW] @(
@set "generator_var=-G "MinGW Makefiles^""
)
@if /i [%generator%] == [MSVC] @(
rem We could figure out the correct MSVS generator here
)
@call :iso8601 iso8601
@set output=%temp%\cmake-%iso8601%.log
@if not exist %build_path% mkdir %build_path%
@cd %build_path%
@"%cmake_executable%" ^
!generator_var! ^
-DCMAKE_BUILD_TYPE=!build_type! ^
-DBUILD_SHARED_LIBS=!build_shared! ^
"%script_folder%" > "%output%"
@if errorlevel 1 (
@call :log 5
@call :log 0 "Failed to generate build files with CMake"
@call :log_append "%output%"
@cd %script_folder%
@exit /b 1
)
@cd %script_folder%
@endlocal
@goto :eof
:build - Builds the library
@setlocal EnableDelayedExpansion
@if errorlevel 1 (
call :log 0 "Failed to enable extensions"
exit /b 1
)
@call :log 5
@call :log 0 "Building %project% with %generator%"
@if /i [%generator%] == [MinGW] @(
@call :find_in_path mingw32_make_executable mingw32-make.exe
@if errorlevel 1 (
@call :log 5
@call :log 0 "Failed to find mingw32-make"
@exit /b 1
)
@set "build_command=^"!mingw32_make_executable!^" all test"
)
@if /i [%generator%] == [MSVC] @(
@call :msbuild msbuild_executable
@if errorlevel 1 (
@call :log 5
@call :log 0 "Failed to find MSBuild"
@exit /b 1
)
@set "build_command=^"!msbuild_executable!^" /m:4 /p:Configuration=%build_type% %project%.sln"
)
@if not defined build_command (
@call :log 5
@call :log 0 "No build command for %generator%"
@exit /b 1
)
@cd %build_path%
@call :iso8601 iso8601
@set output=%temp%\build-%iso8601%.log
@call :log 7
@call :log 2 "Build command: %build_command:"=%"
@%build_command% > "%output%"
@if errorlevel 1 (
@call :log_append "%output%"
@call :log 5
@call :log 0 "Failed to complete the build"
@exit /b 1
)
@call :log_append "%output%"
@cd %script_folder%
@endlocal
@goto :eof
:install - Installs the built files
@setlocal
@call :log 5
@call :log 0 "Installing built files"
@call :cmake cmake_executable
@if errorlevel 1 (
@call :log 5
@call :log 0 "Need CMake to install the built files"
@exit /b 1
)
@call :iso8601 iso8601
@set output=%temp%\install-%iso8601%.log
@"%cmake_executable%" ^
"-DCMAKE_INSTALL_PREFIX=%install_path%" ^
-P "%build_path%/cmake_install.cmake" ^
> "%output%"
@if errorlevel 1 (
@call :log_append "%output%"
@call :log 5
@call :log 0 "Failed to install the files"
@exit /b 1
)
@call :log_append "%output%"
@endlocal
@goto :eof
:script_source - Determines if the script was ran from the cli or explorer
:: %1 - The return variable [cli|explorer]
@verify other 2>nul
@setlocal EnableDelayedExpansion
@if errorlevel 1 (
call :log 0 "Failed to enable extensions"
exit /b 1
)
@call :log 3 "Attempting to detect the script source"
@echo "The invocation command was: '%cmdcmdline%'" >> %log_path%
@for /f "tokens=1-3,*" %%a in ("%cmdcmdline%") do @(
set cmd=%%~a
set arg1=%%~b
set arg2=%%~c
set rest=%%~d
)
@set quote="
@if "!arg2:~0,1!" equ "!quote!" (
if "!arg2:~-1!" neq "!quote!" (
set "arg2=!arg2:~1!"
)
)
@call :log 4 "cmd = %cmd%"
@call :log 4 "arg1 = %arg1%"
@call :log 4 "arg2 = %arg2%"
@call :log 4 "rest = %rest%"
@call :log 4 "src = %~f0"
@if /i "%arg2%" == "call" (
set script_source=cli
) else (
@if /i "%arg1%" == "/c" (
set script_source=explorer
) else (
set script_source=cli
)
)
@call :log 3 "The script was invoked from %script_source%"
@endlocal & set "%~1=%script_source%"
@goto :eof
:architecture - Finds the system architecture
:: %1 - The return variable [x86|x86_64]
@setlocal
@call :log 3 "Determining the processor architecture"
@set "key=HKLM\System\CurrentControlSet\Control\Session Manager\Environment"
@set "var=PROCESSOR_ARCHITECTURE"
@for /f "skip=2 tokens=2,*" %%a in ('reg query "%key%" /v "%var%"') do @set "arch=%%b"
@if "%arch%" == "AMD64" set arch=x86_64
@call :log 4 "arch = %arch%"
@endlocal & set "%~1=%arch%"
@goto :eof
:md5 - Gets the MD5 checksum for a file
:: %1 - The hash
:: %2 - The file path
@setlocal
@set var=%~1
@set file_path=%~2
@if [%var%] == [] exit /b 1
@if "%file_path%" == "" exit /b 1
@if not exist "%file_path%" exit /b 1
@for /f "skip=3 tokens=1,*" %%a in ('powershell Get-FileHash -Algorithm MD5 "'%file_path%'"') do @set hash=%%b
@if not defined hash (
call :log 6
call :log 0 "Failed to get MD5 hash for %file_path%"
exit /b 1
)
@endlocal & set "%var%=%hash: =%"
@goto :eof
:windows_version - Checks the windows version
:: %1 - The windows version
:: %2 - The major version number return variable
:: %3 - The minor version number return variable
:: %4 - The revision version number return variable
@setlocal
@call :log 3 "Retrieving the Windows version"
@for /f "tokens=2 delims=[]" %%x in ('ver') do @set win_ver=%%x
@set win_ver=%win_ver:Version =%
@set win_ver_major=%win_ver:~0,1%
@set win_ver_minor=%win_ver:~2,1%
@set win_ver_rev=%win_ver:~4%
@call :log 4 "win_ver = %win_ver%"
@endlocal & set "%~1=%win_ver%" ^
& set "%~2=%win_ver_major%" ^
& set "%~3=%win_ver_minor%" ^
& set "%~4=%win_ver_rev%"
@goto :eof
:find_in_path - Finds a program of file in the PATH
@setlocal
@set var=%~1
@set file=%~2
@if [%var%] == [] exit /b 1
@if [%file%] == [] exit /b 1
@call :log 3 "Searching PATH for %file%"
@for %%x in ("%file%") do @set "file_path=%%~f$PATH:x"
@if not defined file_path exit /b 1
@endlocal & set "%var%=%file_path%"
@goto :eof
:administrator_check - Checks for administrator priviledges
@setlocal
@call :log 2 "Checking for administrator priviledges"
@set "key=HKLM\Software\VCA\Tool Chain\Admin Check"
@reg add "%key%" /v Elevated /t REG_DWORD /d 1 /f > nul 2>&1
@if errorlevel 1 exit /b 1
@reg delete "%key%" /va /f > nul 2>&1
@endlocal
@goto :eof
:log_append - Appends another file into the current logging file
:: %1 - the file_path to the file to concatenate
@setlocal
@set "file_path=%~1"
@if [%file_path%] == [] exit /b 1
@call :log 3 "Appending to log: %file_path%"
@call :iso8601 iso8601
@set "temp_log=%temp%\append-%iso8601%.log"
@call :log 4 "Using temp file %temp_log%"
@type "%log_path%" "%file_path%" > "%temp_log%" 2>nul
@move /y "%temp_log%" "%log_path%" 1>nul
@del "%file_path%" 2>nul
@del "%temp_log%" 2>nul
@endlocal
@goto :eof
:iso8601 - Returns the current time in ISO8601 format
:: %1 - the return variable
:: %2 - format [extended|basic*]
:: iso8601 - contains the resulting timestamp
@setlocal
@wmic Alias /? >NUL 2>&1 || @exit /b 1
@set "var=%~1"
@if "%var%" == "" @exit /b 1
@set "format=%~2"
@if "%format%" == "" set format=basic
@for /F "skip=1 tokens=1-6" %%g IN ('wmic Path Win32_UTCTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') do @(
@if "%%~l"=="" goto :iso8601_done
@set "yyyy=%%l"
@set "mm=00%%j"
@set "dd=00%%g"
@set "hour=00%%h"
@set "minute=00%%i"
@set "seconds=00%%k"
)
:iso8601_done
@set mm=%mm:~-2%
@set dd=%dd:~-2%
@set hour=%hour:~-2%
@set minute=%minute:~-2%
@set seconds=%seconds:~-2%
@if /i [%format%] == [extended] (
set iso8601=%yyyy%-%mm%-%dd%T%hour%:%minute%:%seconds%Z
) else (
if /i [%format%] == [basic] (
set iso8601=%yyyy%%mm%%dd%T%hour%%minute%%seconds%Z
) else (
@exit /b 1
)
)
@set iso8601=%iso8601: =0%
@endlocal & set %var%=%iso8601%
@goto :eof
:verbosity - Processes the verbosity parameter '/v[v...]
:: %1 - verbosity given on the command line
:: logging_level - set to the number of v's
@setlocal
@set logging_level=0
@set verbosity=%~1
:verbosity_loop
@set verbosity=%verbosity:~1%
@if not [%verbosity%] == [] @(
set /a "logging_level=logging_level+1"
goto verbosity_loop
)
@endlocal & set logging_level=%logging_level%
@goto :eof
:log - Logs a message, depending on verbosity
:: %1 - level
:: [0-4] for CLI logging
:: [5-9] for GUI logging
:: %2 - message to print
@setlocal
@set "level=%~1"
@set "msg=%~2"
@if "%log_folder%" == "" (
echo Logging was used to early in the script, log_folder isn't set yet
goto :eof
)
@if "%log_path%" == "" (
echo Logging was used to early in the script, log_path isn't set yet
goto :eof
)
@if not exist "%log_folder%" mkdir "%log_folder%"
@if not exist "%log_path%" echo. 1>nul 2>"%log_path%"
@echo.%msg% >> "%log_path%"
@if %level% geq 5 (
@if [%script_source%] == [explorer] (
set /a "level=level-5"
) else (
@goto :eof
)
)
@if "%logging_level%" == "" (
echo Logging was used to early in the script, logging_level isn't set yet
goto :eof
)
@if %logging_level% geq %level% echo.%msg% 1>&2
@endlocal
@goto :eof
:start_browser - Opens the default browser to a URL
:: %1 - the url to open
@setlocal
@set url=%~1
@call :log 4 "Opening default browser: %url%"
@start %url%
@endlocal
@goto :eof
:find_cmake - Finds cmake on the command line or in the registry
:: %1 - the cmake file path
@setlocal
@set var=%~1
@if [%var%] == [] exit /b 1
@call :log 6
@call :log 6 "Finding CMake"
@call :log 6 "--------------"
@call :find_in_path cmake_executable cmake.exe
@if not errorlevel 1 goto found_cmake
@for /l %%i in (5,-1,0) do @(
@for /l %%j in (9,-1,0) do @(
@for /l %%k in (9,-1,0) do @(
@for %%l in (HKCU HKLM) do @(
@for %%m in (SOFTWARE SOFTWARE\Wow6432Node) do @(
@reg query "%%l\%%m\Kitware\CMake %%i.%%j.%%k" /ve > nul 2>nul
@if not errorlevel 1 (
@for /f "skip=2 tokens=2,*" %%a in ('reg query "%%l\%%m\Kitware\CMake %%i.%%j.%%k" /ve') do @(
@if exist "%%b\bin\cmake.exe" (
@set "cmake_executable=%%b\bin\cmake.exe"
goto found_cmake
)
)
)
)))))
@call :log 5
@call :log 0 "Failed to find cmake"
@exit /b 1
:found_cmake
@endlocal & set "%var%=%cmake_executable%"
@goto :eof
:cmake - Finds cmake and installs it if necessary
:: %1 - the cmake file path
@setlocal
@set var=%~1
@if [%var%] == [] exit /b 1
@call :log 6
@call :log 6 "Checking for CMake"
@call :log 6 "------------------"
@call :find_cmake cmake_executable cmake.exe
@if not errorlevel 1 goto got_cmake
@set checksum=C00267A3D3D9619A7A2E8FA4F46D7698
@set version=3.2.2
@call :install_nsis cmake http://www.cmake.org/files/v%version:~0,3%/cmake-%version%-win32-x86.exe %checksum%
@if errorlevel 1 (
call :log 5
call :log 0 "Failed to install cmake"
@exit /b 1
)
@call :find_cmake cmake_executable cmake.exe
@if not errorlevel 1 goto got_cmake
@call :log 5
@call :log 0 "Failed to check for cmake"
@exit /b 1
:got_cmake
@endlocal & set "%var%=%cmake_executable%"
@goto :eof
:mingw - Finds MinGW, installing it if needed
:: %1 - the compiler path that should be added to PATH
@setlocal EnableDelayedExpansion
@if errorlevel 1 (
@call :log 5
@call :log 0 "Failed to enable extensions"
@exit /b 1
)
@set var=%~1
@if [%var%] == [] exit /b 1
@call :log 6
@call :log 6 "Checking for MinGW"
@call :log 6 "------------------"
@call :find_in_path gcc_executable gcc.exe
@if not errorlevel 1 (
@for %%a in ("%gcc_executable%") do @set "compiler_path=%%~dpa"
goto got_mingw
)
@call :log 7
@call :log 2 "Downloading MinGW"
@if %logging_level% leq 1 set "logging=/q"
@if %logging_level% gtr 1 set "logging=/v"
@set output_path=
@for /f %%a in ('call
"%script_folder%\mingw.cmd"
%logging%
/arch "%arch%"
"%dependency_path%"'
) do @set "compiler_path=%%a\"
@if not defined compiler_path (
@call :log_append "%output%"
@call :log 5
@call :log 0 "Failed to download MinGW"
@exit /b 1
)
:got_mingw
@call :log 5
@call :log 0 "Found MinGW: %compiler_path%gcc.exe"
@endlocal & set "%var%=%compiler_path%"
@goto :eof
:msbuild - Finds MSBuild
:: %1 - the path to MSBuild executable
@setlocal
@set var=%~1
@if [%var%] == [] exit /b 1
@call :find_in_path msbuild_executable msbuild.exe
@if not errorlevel 1 goto got_msbuild
@for /l %%i in (20,-1,4) do @(
@for /l %%j in (9,-1,0) do @(
@for %%k in (HKCU HKLM) do @(
@for %%l in (SOFTWARE SOFTWARE\Wow6432Node) do @(
@reg query "%%k\%%l\Microsoft\MSBuild\%%i.%%j" /v MSBuildOverrideTasksPath > nul 2>nul
@if not errorlevel 1 (
@for /f "skip=2 tokens=2,*" %%a in ('reg query "%%k\%%l\Microsoft\MSBuild\%%i.%%j" /v MSBuildOverrideTasksPath') do @(
@if exist "%%bmsbuild.exe" (
@set "msbuild_executable=%%bmsbuild.exe"
goto got_msbuild
)
)
)
))))
@call :log 5
@call :log 0 "Failed to check for MSBuild"
@exit /b 1
:got_msbuild
@endlocal & set "%var%=%msbuild_executable%"
@goto :eof
:download - Downloads a file from the internet
:: %1 - the url of the file to download
:: %2 - the file to download to
:: %3 - the MD5 checksum of the file (optional)
@setlocal EnableDelayedExpansion
@if errorlevel 1 (
call :print_usage "Failed to enable extensions"
exit /b 1
)
@set url=%~1
@set file_path=%~2
@set checksum=%~3
@for %%a in (%file_path%) do @set dir_path=%%~dpa
@for %%a in (%file_path%) do @set file_name=%%~nxa
@if [%url%] == [] exit /b 1
@if [%file_path%] == [] exit /b 1
@if [%dir_path%] == [] exit /b 1
@if [%file_name%] == [] exit /b 1
@if not exist "%dir_path%" mkdir "%dir_path%"
@call :log 1 "Downloading %url%"
@call :iso8601 iso8601
@set temp_path=%temp%\download-%iso8601%-%file_name%
@call :log 3 "Using temp file %temp_path%"
@powershell Invoke-WebRequest "%url%" -OutFile %temp_path%
@if errorlevel 1 (
call :log 0 "Failed to download %url%"
exit /b 1
)
@if [%checksum%] neq [] (
@call :log 4 "Checking %checksum% against %temp_path%"
@call :md5 hash "%temp_path%"
if "!hash!" neq "%checksum%" (
call :log 0 "Failed to match checksum: %temp_path%"
call :log 0 "Hash : !hash!"
call :log 0 "Checksum: %checksum%"
exit /b 1
) else (
call :log 3 "Checksum matched: %temp_path%"
call :log 3 "Hash : !hash!"
call :log 3 "Checksum: %checksum%"
)
)
@call :log 4 "Renaming %temp_path% to %file_path%"
@move /y "%temp_path%" "%file_path%" 1>nul
@endlocal
@goto :eof
:install_msi - Installs a dependency from an Microsoft Installer package (.msi)
:: %1 - [string] name of the project to install
:: %2 - The location of the .msi, a url must start with 'http://' or file_path
:: %3 - The checksum of the msi (optional)
@setlocal
@set name=%~1
@set file_path=%~2
@set checksum=%~3
@set msi=%~nx2
@set msi_path=%dependency_path%\%msi%
@if [%name%] == [] exit /b 1
@if [%file_path%] == [] exit /b 1
@if [%msi%] == [] exit /b 1
@if [%msi_path%] == [] exit /b 1
@for %%x in (msiexec.exe) do @set "msiexec_path=%%~f$PATH:x"
@if "msiexec_path" == "" (
call :log 0 "Failed to find the Microsoft package installer (msiexec.exe)"
call :log 6
call :log 0 "Please install it from the Microsoft Download center"
call :log 6
choice /C YN /T 60 /D N /M "Would you like to go there now?"
if !errorlevel! equ 1 call :start_browser ^
"http://search.microsoft.com/DownloadResults.aspx?q=Windows+Installer"
exit /b 1
)
@call :log 6
@call :log 1 "Installing the '%name%' dependency"
@call :log 6 "-------------------------------------"
@call :administrator_check
@if errorlevel 1 (
call :log 0 "You must run %~nx0 in elevated mode to install '%name%'"
call :log 5 "Right-Click and select 'Run as Administrator'
call :log 0 "Install the dependency manually by running %file_path%"
@exit /b 740
)
@if [%file_path:~0,4%] == [http] (
if not exist "%msi_path%" (
call :download "%file_path%" "%msi_path%" %checksum%
if errorlevel 1 (
call :log 0 "Failed to download the %name% dependency"
exit /b 1
)
)
) else (
call :log 2 "Copying MSI %file_path% to %msi_path%"
call :log 7
if not exist "%msi_path%" (
xcopy /q /y /z "%file_path%" "%msi_path%" 1>nul
if errorlevel 1 (
call :log 0 "Failed to copy the Microsoft Installer"
exit /b 1
)
)
)
@call :log 1 "Running the %msi%"
@call :log 6
@set msi_log=%temp%\msiexec-%timestamp%.log
@call :log 3 "Logging to: %msi_log%"
@msiexec /i "%msi_path%" /passive /log "%msi_log%" ALLUSERS=1
@set msi_errorlevel=%errorlevel%
@call :log_append "%msi_log%"
@if %msi_errorlevel% equ 0 goto install_msi_success
@if %msi_errorlevel% equ 3010 goto install_msi_success_reboot
@if %msi_errorlevel% equ 1641 goto install_msi_success_reboot
@if %msi_errorlevel% equ 3015 goto install_msi_in_progress_reboot
@if %msi_errorlevel% equ 1615 goto install_msi_in_progress_reboot
@call :log 0 "Microsoft Installer failed: %msi_errorlevel%"
@call :log 0 "Install the dependency manually by running %msi_path%"
@exit /b 1
:install_msi_in_progress_reboot
@call :log 0 "The installation requires a reboot to continue"
@call :log 5
@call :reboot
@exit /b 1
:install_msi_success_reboot
@call :log 3 "The installation requires a reboot to be fully functional"
@set reboot_required=1
:install_msi_success
@call :log 2 "Successfully installed %name%"
@call :log 7
@endlocal & set reboot_required=%reboot_required%
@goto :eof
:install_nsis - Installs a dependency from an Nullsoft Installer package (.exe)
:: %1 - [string] name of the project to install
:: %2 - The location of the .exe, a url must start with 'http://' or file_path
:: %3 - The checksum of the exe (optional)
@setlocal
@set name=%~1
@set file_path=%~2
@set checksum=%~3
@set exe=%~nx2
@set exe_path=%dependency_path%\%exe%
@if [%name%] == [] exit /b 1
@if [%file_path%] == [] exit /b 1
@if [%exe%] == [] exit /b 1
@if [%exe_path%] == [] exit /b 1
@call :log 6
@call :log 1 "Installing the '%name%' dependency"
@call :log 6 "-------------------------------------"
@call :administrator_check
@if errorlevel 1 (
call :log 0 "You must run %~nx0 in elevated mode to install '%name%'"
call :log 5 "Right-Click and select 'Run as Administrator'
call :log 0 "Install the dependency manually by running %file_path%"
@exit /b 740
)
@if [%file_path:~0,4%] == [http] (
if not exist "%exe_path%" (
call :download "%file_path%" "%exe_path%" %checksum%
if errorlevel 1 (
call :log 0 "Failed to download the %name% dependency"
exit /b 1
)
)
) else (
call :log 2 "Copying installer %file_path% to %exe_path%"
call :log 7
if not exist "%exe_path%" (
xcopy /q /y /z "%file_path%" "%exe_path%" 1>nul
if errorlevel 1 (
call :log 0 "Failed to copy the Nullsoft Installer"
exit /b 1
)
)
)
@call :log 1 "Running the %exe%"
@call :log 6
@"%exe_path%" /S
@set nsis_errorlevel=%errorlevel%
@if %nsis_errorlevel% equ 0 goto install_nsis_success
@if %nsis_errorlevel% equ 3010 goto install_nsis_success_reboot
@if %nsis_errorlevel% equ 1641 goto install_nsis_success_reboot
@if %nsis_errorlevel% equ 3015 goto install_nsis_in_progress_reboot
@if %nsis_errorlevel% equ 1615 goto install_nsis_in_progress_reboot
@call :log 0 "Nullsoft Installer failed: %nsis_errorlevel%"
@call :log 0 "Install the dependency manually by running %exe_path%"
@exit /b 1
:install_nsis_in_progress_reboot
@call :log 0 "The installation requires a reboot to continue"
@call :log 5
@call :reboot
@exit /b 1
:install_nsis_success_reboot
@call :log 3 "The installation requires a reboot to be fully functional"
@set reboot_required=1
:install_nsis_success
@call :log 2 "Successfully installed %name%"
@call :log 7
@endlocal & set reboot_required=%reboot_required%
@goto :eof
:reboot - Asks the user if they would like to reboot then stops the script
@setlocal
@call :log 6 "-------------------------------------------"
@choice /C YN /T 60 /D N /M "The %method% requires a reboot, reboot now?"
@set ret=%errorlevel%
@call :log 6
@if %ret% equ 1 (
@shutdown /r
) else (
@call :log 0 "You will need to reboot to complete the %method%"
@call :log 5
)
@endlocal
@goto :eof

View File

@@ -1,7 +1,7 @@
# CivetWeb API Reference # Libhttp API Reference
CivetWeb is often used as HTTP and HTTPS library inside a larger application. Libhttp is often used as HTTP and HTTPS library inside a larger application.
A C API is available to integrate the CivetWeb functionality in a larger A C API is available to integrate the Libhttp functionality in a larger
codebase. A C++ wrapper is also available, although it is not guaranteed codebase. A C++ wrapper is also available, although it is not guaranteed
that all functionality available through the C API can also be accessed that all functionality available through the C API can also be accessed
from C++. This document describes the public C API. Basic usage examples of from C++. This document describes the public C API. Basic usage examples of
@@ -43,7 +43,6 @@ the API can be found in [Embedding.md](Embedding.md).
* [`mg_get_server_ports( ctx, size, ports );`](api/mg_get_server_ports.md) * [`mg_get_server_ports( ctx, size, ports );`](api/mg_get_server_ports.md)
* [`mg_get_user_connection_data( conn );`](api/mg_get_user_connection_data.md) * [`mg_get_user_connection_data( conn );`](api/mg_get_user_connection_data.md)
* [`mg_get_user_data( ctx );`](api/mg_get_user_data.md) * [`mg_get_user_data( ctx );`](api/mg_get_user_data.md)
* [~~`mg_get_valid_option_names();`~~](api/mg_get_valid_option_names.md)
* [`mg_get_valid_options();`](api/mg_get_valid_options.md) * [`mg_get_valid_options();`](api/mg_get_valid_options.md)
* [`mg_get_var( data, data_len, var_name, dst, dst_len );`](api/mg_get_var.md) * [`mg_get_var( data, data_len, var_name, dst, dst_len );`](api/mg_get_var.md)
* [`mg_get_var2( data, data_len, var_name, dst, dst_len, occurrence );`](api/mg_get_var2.md) * [`mg_get_var2( data, data_len, var_name, dst, dst_len, occurrence );`](api/mg_get_var2.md)
@@ -69,7 +68,6 @@ the API can be found in [Embedding.md](Embedding.md).
* [`mg_strncasecmp( s1, s2, len );`](api/mg_strncasecmp.md) * [`mg_strncasecmp( s1, s2, len );`](api/mg_strncasecmp.md)
* [`mg_unlock_connection( conn );`](api/mg_unlock_connection.md) * [`mg_unlock_connection( conn );`](api/mg_unlock_connection.md)
* [`mg_unlock_context( ctx );`](api/mg_unlock_context.md) * [`mg_unlock_context( ctx );`](api/mg_unlock_context.md)
* [~~`mg_upload( conn, destination_dir );`~~](api/mg_upload.md)
* [`mg_url_decode( src, src_len, dst, dst_len, is_form_url_encoded );`](api/mg_url_decode.md) * [`mg_url_decode( src, src_len, dst, dst_len, is_form_url_encoded );`](api/mg_url_decode.md)
* [`mg_url_encode( src, dst, dst_len );`](api/mg_url_encode.md) * [`mg_url_encode( src, dst, dst_len );`](api/mg_url_encode.md)
* [`mg_version();`](api/mg_version.md) * [`mg_version();`](api/mg_version.md)

View File

@@ -1,44 +1,21 @@
Building CivetWeb Building LibHTTP
========= =========
This guide covers the build instructions for the stand-alone web server. This guide covers the build instructions for the stand-alone web server.
See [Embedding.md](https://github.com/civetweb/civetweb/blob/master/docs/Embedding.md) for information on extending an existing C or C++ application. A brief overview of the source code files can be found in [Embedding.md](https://github.com/civetweb/civetweb/blob/master/docs/Embedding.md) as well. See [Embedding.md](Embedding.md) for information on extending an existing C or C++ application. A brief overview of the source code files can be found in [Embedding.md](Embedding.md) as well.
#### Where to get the source code? #### Where to get the source code?
The latest version can be found at The latest version can be found at
https://github.com/civetweb/civetweb https://github.com/lammertb/libhttp
Released versions can be found at Released versions can be found at
https://github.com/civetweb/civetweb/releases https://github.com/lammertb/libhttp/releases
Building for Windows Building for Windows, Linux, BSD, OSX
---------
#### Using Visual Studio
Open the *VS/civetweb.sln* in Visual Studio.
To include SSL support, you may have to add an extra library for the cryptography support. You might wish to use yaSSL. However, it is GPL licensed or uses a commercial license. See [yaSSL.md](https://github.com/civetweb/civetweb/blob/master/docs/yaSSL.md) for more information.
Alternatively, you might wish to use OpenSSL. See [OpenSSL.md](https://github.com/civetweb/civetweb/blob/master/docs/OpenSSL.md) for more information.
#### Using MinGW-w64 or TDM-GCC
In the start menu locate and run the "Run terminal" batch file. For TDM-GCC this is named "MinGW Command Prompt".
Navigate to the civetweb sources directory and run:
```
mingw32-make CC=gcc
```
#### Using Qt Creator
Open the Qt Designer project in the Qt folder
#### Using CMake
Except for the components in the `third_party` folder (e.g., Lua and Duktape), CivetWeb can also be built with CMake.
CMake can be used for all supported operating systems.
Building for Linux, BSD, and OSX
--------- ---------
Builds for all operating systems are created with GNU Make.
## Using Make ## Using Make
@@ -62,7 +39,7 @@ make lib WITH_CPP=1 WITH_IPV6=1
make clean 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. Build the static and shared libraries.
The *WITH_CPP* make option is to include the CivetServer class. The *WITH_CPP* make option is to include the LibHTTPServer class.
The additional make options configure the library just as it would the application. 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 The *slib* option should be done on a separate clean build as position
@@ -143,37 +120,21 @@ one additional *package* rule.
make -f Makefile.osx package make -f Makefile.osx package
``` ```
Building with Buildroot
---------
[Buildroot](http://buildroot.uclibc.org/) is a tool for creating cross compiled file systems. Including Civetweb in buildroot is fairly easy. There is even support for various build options.
1. First, check if it already there.
- In buildroot, make menuconfig
- Package Selection for the target --->
- Networking applications --->
- civetweb
2. If not there, just add it
- copy *Config.in* and *civetweb.mk* from Civetweb's *contrib/buildroot/* to Buildroot's *package/civetweb/* directory.
- In Buildroot's *package/Config.in, insert the following line in were you will know how to find it in the menu.
> ``` source "package/civetweb/Config.in" ```
Building on Android Building on Android
--------- ---------
This is a small guide to help you run civetweb on Android. Currently it is This is a small guide to help you run LibHTTP on Android. Currently it is
tested on the HTC Wildfire. If you have managed to run it on other devices tested on the HTC Wildfire. If you have managed to run it on other devices
as well, please comment or drop an email in the mailing list. as well, please comment or drop an email in the mailing list.
Note: You do not need root access to run civetweb on Android. Note: You do not need root access to run LibHTTP on Android.
- Download the source from the Downloads page. - 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) - 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/resources` - Run `/path-to-ndk/ndk-build -C /path-to-libhttp/resources`
That should generate civetweb/lib/armeabi/civetweb That should generate libhttp/lib/armeabi/libhttp
- Using the adb tool (you need to have Android SDK installed for that), - Using the adb tool (you need to have Android SDK installed for that),
push the generated civetweb binary to `/data/local` folder on device. push the generated libhttp binary to `/data/local` folder on device.
- From adb shell, navigate to `/data/local` and execute `./civetweb`. - From adb shell, navigate to `/data/local` and execute `./libhttp`.
- To test if the server is running fine, visit your web-browser and - To test if the server is running fine, visit your web-browser and
navigate to `http://127.0.0.1:8080` You should see the `Index of /` page. navigate to `http://127.0.0.1:8080` You should see the `Index of /` page.
@@ -183,7 +144,7 @@ Note: You do not need root access to run civetweb on Android.
Notes: Notes:
- `jni` stands for Java Native Interface. Read up on Android NDK if you want - `jni` stands for Java Native Interface. Read up on Android NDK if you want
to know how to interact with the native C functions of civetweb in Android to know how to interact with the native C functions of libhttp in Android
Java applications. Java applications.
- TODO: A Java application that interacts with the native binary or a - TODO: A Java application that interacts with the native binary or a
shared library. shared library.

View File

@@ -1,9 +1,9 @@
Contributing to CivetWeb Contributing to LibHTTP
==== ====
Contributions to CivetWeb are welcome, provided all contributions carry the MIT license. Contributions to LibHTTP are welcome, provided all contributions carry the MIT license.
- Please first create an issue on GitHub or create a thread on the CivetWeb discussion group. - Please first create an issue on GitHub.
- If possible, create a pull request on GitHub. Please take care your modifications pass the continuous integration checks. These checks are performed automatically when you create a pull request, but it may take some hours until all tests are completed. - If possible, create a pull request on GitHub. Please take care your modifications pass the continuous integration checks. These checks are performed automatically when you create a pull request, but it may take some hours until all tests are completed.
- Alternatively, you can post a patch. However, pull requests are preferred. - Alternatively, you can post a patch. However, pull requests are preferred.
- Contributor names are listed in CREDITS.md, unless you explicitly state you don't want your name to be listed there. - Contributor names are listed in CREDITS.md, unless you explicitly state you don't want your name to be listed there.

View File

@@ -1,38 +1,38 @@
Embedding CivetWeb Embedding LibHTTP
========= =========
CivetWeb is primarily designed so applications can easily add HTTP and HTTPS server as well as WebSocket functionality. For example, an application server could use CivetWeb to enable a web service interface for automation or remote control. LibHTTP is primarily designed so applications can easily add HTTP and HTTPS server as well as WebSocket functionality. For example, an application server could use LibHTTP to enable a web service interface for automation or remote control.
However, it can also be used as a stand-alone executable. It can deliver static files and offers built-in server side Lua, JavaScript and CGI support. Some instructions how to build the stand-alone server can be found in [Building.md](https://github.com/civetweb/civetweb/blob/master/docs/Building.md). However, it can also be used as a stand-alone executable. It can deliver static files and offers built-in server side Lua, JavaScript and CGI support. Some instructions how to build the stand-alone server can be found in [Building.md](Building.md).
Files Files
------ ------
There is just a small set of files to compile in to the application, There is just a small set of files to compile in to the application,
but if a library is desired, see [Building.md](https://github.com/CivetWeb/CivetWeb/blob/master/docs/Building.md) but if a library is desired, see [Building.md](Building.md)
#### Regarding the INL file extension #### Regarding the INL file extension
The *INL* file extension represents code that is statically included inline in a source file. Slightly different from C++ where it means "inline" code which is technically not the same as static code. CivetWeb overloads this extension for the sake of clarity as opposed to having .c extensions on files that should not be directly compiled. The *INL* file extension represents code that is statically included inline in a source file. Slightly different from C++ where it means "inline" code which is technically not the same as static code. LibHTTP overloads this extension for the sake of clarity as opposed to having .c extensions on files that should not be directly compiled.
#### HTTP Server Source Files #### HTTP Server Source Files
These files constitute the CivetWeb library. They do not contain a `main` function, These files constitute the LibHTTP library. They do not contain a `main` function,
but all functions required to run a HTTP server. but all functions required to run a HTTP server.
- HTTP server API - HTTP server API
- include/civetweb.h - include/libhttp.h
- C implementation - C implementation
- src/civetweb.c - src/libhttp.c
- src/md5.inl (MD5 calculation) - src/md5.inl (MD5 calculation)
- src/handle_form.inl (HTML form handling functions) - src/handle_form.inl (HTML form handling functions)
- Optional: C++ wrapper - Optional: C++ wrapper
- include/CivetServer.h (C++ interface) - include/LibHTTPServer.h (C++ interface)
- src/CivetServer.cpp (C++ wrapper implementation) - src/LibHTTPServer.cpp (C++ wrapper implementation)
- Optional: Third party components - Optional: Third party components
- src/third_party/* (third party components, mainly used for the standalone server) - src/third_party/* (third party components, mainly used for the standalone server)
- src/mod_*.inl (modules to access third party components from civetweb) - src/mod_*.inl (modules to access third party components from LibHTTP)
Note: The C++ wrapper uses the official C interface (civetweb.h) and does not add new features to the server. Some features available in the C interface might be missing in the C++ interface. Note: The C++ wrapper uses the official C interface (libhttp.h) and does not add new features to the server. Some features available in the C interface might be missing in the C++ interface.
#### Additional Source Files for Executables #### Additional Source Files for Executables
@@ -54,7 +54,7 @@ Quick Start
By default, the server will automatically serve up files like a normal HTTP server. An embedded server is most likely going to overload this functionality. By default, the server will automatically serve up files like a normal HTTP server. An embedded server is most likely going to overload this functionality.
### C ### C
- Include the C interface ```civetweb.h```. - Include the C interface ```libhttp.h```.
- Use `mg_start()` to start the server. - Use `mg_start()` to start the server.
- Use *options* to select the port and document root among other things. - Use *options* to select the port and document root among other things.
- Use *callbacks* to add your own hooks. - Use *callbacks* to add your own hooks.
@@ -62,11 +62,11 @@ By default, the server will automatically serve up files like a normal HTTP serv
- Use `mg_stop()` to stop the server. - Use `mg_stop()` to stop the server.
### C++ ### C++
- Note that CivetWeb is Clean C, and C++ interface ```CivetServer.h``` is only a wrapper layer around the C interface. - Note that LibHTTP is Clean C, and C++ interface ```LibHTTPServer.h``` is only a wrapper layer around the C interface.
Not all CivetWeb features available in C are also available in C++. Not all LibHTTP features available in C are also available in C++.
- Create CivetHandlers for each URI. - Create LibHTTPHandlers for each URI.
- Register the handlers with `CivetServer::addHandler()` - Register the handlers with `LibHTTPServer::addHandler()`
- `CivetServer` starts on contruction and stops on destruction. - `LibHTTPServer` starts on contruction and stops on destruction.
- Use contructor *options* to select the port and document root among other things. - Use contructor *options* to select the port and document root among other things.
- Use constructor *callbacks* to add your own hooks. - Use constructor *callbacks* to add your own hooks.
@@ -130,17 +130,17 @@ This build is valid for Lua version Lua 5.2. It is also possible to build with L
JavaScript Support JavaScript Support
------ ------
CivetWeb can be built with server side JavaScript support by including the Duktape library. LibHTTP can be built with server side JavaScript support by including the Duktape library.
CivetWeb internals LibHTTP internals
------ ------
CivetWeb is multithreaded web server. `mg_start()` function allocates LibHTTP is multithreaded web server. `mg_start()` function allocates
web server context (`struct mg_context`), which holds all information web server context (`struct mg_context`), which holds all information
about web server instance: about web server instance:
- configuration options. Note that CivetWeb makes internal copies of - configuration options. Note that LibHTTP makes internal copies of
passed options. passed options.
- SSL context, if any - SSL context, if any
- user-defined callbacks - user-defined callbacks
@@ -153,11 +153,11 @@ When `mg_start()` returns, all initialization is guaranteed to be complete
some threads: a master thread, that accepts new connections, and several some threads: a master thread, that accepts new connections, and several
worker threads, that process accepted connections. The number of worker threads worker threads, that process accepted connections. The number of worker threads
is configurable via `num_threads` configuration option. That number puts a is configurable via `num_threads` configuration option. That number puts a
limit on number of simultaneous requests that can be handled by CivetWeb. limit on number of simultaneous requests that can be handled by LibHTTP.
If you embed CivetWeb into a program that uses SSL outside CivetWeb as well, If you embed LibHTTP into a program that uses SSL outside LibHTTP as well,
you may need to initialize SSL before calling `mg_start()`, and set the pre- you may need to initialize SSL before calling `mg_start()`, and set the pre-
processor define SSL_ALREADY_INITIALIZED. This is not required if SSL is used processor define SSL_ALREADY_INITIALIZED. This is not required if SSL is used
only within CivetWeb. only within LibHTTP.
When master thread accepts new a connection, a new accepted socket (described When master thread accepts new a connection, a new accepted socket (described
by `struct socket`) it placed into the accepted sockets queue, by `struct socket`) it placed into the accepted sockets queue,
@@ -180,7 +180,7 @@ looks something like this:
} }
} }
Function `consume_socket()` gets a new accepted socket from the CivetWeb socket Function `consume_socket()` gets a new accepted socket from the LibHTTP socket
queue, atomically removing it from the queue. If the queue is empty, queue, atomically removing it from the queue. If the queue is empty,
`consume_socket()` blocks and waits until a new socket is placed in the queue `consume_socket()` blocks and waits until a new socket is placed in the queue
by the master thread. by the master thread.
@@ -195,6 +195,6 @@ listening sockets. `poll()` is used to avoid `FD_SETSIZE` limitation of
to use hi-performance alternatives like `epoll()` or `kqueue()`. Worker to use hi-performance alternatives like `epoll()` or `kqueue()`. Worker
threads use blocking IO on accepted sockets for reading and writing data. threads use blocking IO on accepted sockets for reading and writing data.
All accepted sockets have `SO_RCVTIMEO` and `SO_SNDTIMEO` socket options set All accepted sockets have `SO_RCVTIMEO` and `SO_SNDTIMEO` socket options set
(controlled by the `request_timeout_ms` CivetWeb option, 30 seconds default) (controlled by the `request_timeout_ms` LibHTTP option, 30 seconds default)
which specifies a read/write timeout on client connections. which specifies a read/write timeout on client connections.

View File

@@ -1,36 +1,6 @@
Civetweb Install Guide LibHTTP Install Guide
==== ====
This guide covers the distributions for CivetWeb. The latest source code is available at [https://github.com/civetweb/civetweb](https://github.com/civetweb/civetweb). This guide covers the distributions for LibHTTP. The latest source code is available at [https://github.com/lammertb/libhttp](https://github.com/lammertb/libhttp).
Windows Installing is as simple as downloading the sources and typing `make` on the command line in the root of the project directory.
---
This pre-built version comes pre-built wit Lua support. Libraries for SSL support are not included due to licensing restrictions;
however, users may add an SSL library themselves.
Instructions for adding SSL support can be found in [https://github.com/civetweb/civetweb/tree/master/docs](https://github.com/civetweb/civetweb/tree/master/docs)
1a. 32 Bit: Install the [Visual C++ Redistributable for Visual Studio 2010](http://www.microsoft.com/en-us/download/details.aspx?id=8328)
1b. 64 Bit: Install the [Visual C++ Redistributable for Visual Studio 2013](http://www.microsoft.com/en-us/download/details.aspx?id=40784)
2. Download latest *civetweb-win.zip* from [SourceForge](https://sourceforge.net/projects/civetweb/files/)
3. When started, Civetweb puts itself into the tray.
OS X
---
This pre-built version comes with Lua, IPV6 and SSL support.
1. Download the latest *Civetweb.dmg* from [SourceForge](https://sourceforge.net/projects/civetweb/files/)
2. Click on the it and look for the attachment in the finder.
4. Drag Civetweb to the Applications folder.
5. When started, Civetweb puts itself into top menu.
Linux
---
1. Download the latest *civetweb.tar.gz* from [SourceForge](https://sourceforge.net/projects/civetweb/files/)
2. Open archive and change to the new directory.
3. make help
4. make
5. make install
6. Run the program ```/usr/local/bin/civetweb```, it will use the configuration file */usr/local/etc/civetweb.conf*.

View File

@@ -1,7 +1,7 @@
Adding OpenSSL Support Adding OpenSSL Support
===== =====
Civetweb supports *HTTPS* connections using the OpenSSL transport layer LibHTTP supports *HTTPS* connections using the OpenSSL transport layer
security (TLS) library. OpenSSL is a free, open source library (see security (TLS) library. OpenSSL is a free, open source library (see
http://www.openssl.org/). http://www.openssl.org/).
@@ -11,17 +11,17 @@ Getting Started
- Install OpenSSL on your system. There are OpenSSL install packages for all - Install OpenSSL on your system. There are OpenSSL install packages for all
major Linux distributions as well as a setup for Windows. major Linux distributions as well as a setup for Windows.
- The default build configuration of the civetweb web server will load the - The default build configuration of the LibHTTP web server will load the
required OpenSSL libraries, if a HTTPS certificate has been configured. required OpenSSL libraries, if a HTTPS certificate has been configured.
Civetweb Configuration LibHTTP Configuration
---- ----
The configuration file must contain an https port, identified by a letter 's' The configuration file must contain an https port, identified by a letter 's'
attached to the port number. attached to the port number.
To serve http and https from their standard ports use the following line in To serve http and https from their standard ports use the following line in
the configuration file 'civetweb.conf': the configuration file 'libhttp.conf':
<pre> <pre>
listening_ports 80, 443s listening_ports 80, 443s
</pre> </pre>
@@ -32,7 +32,7 @@ To serve only https use:
Furthermore the SSL certificate file must be set: Furthermore the SSL certificate file must be set:
<pre> <pre>
ssl_certificate d:\civetweb\certificate\server.pem ssl_certificate d:\libhttp\certificate\server.pem
</pre> </pre>
@@ -40,7 +40,7 @@ Creating a self signed certificate
---- ----
OpenSSL provides a command line interface, that can be used to create the OpenSSL provides a command line interface, that can be used to create the
certificate file required by civetweb (server.pem). certificate file required by LibHTTP (server.pem).
One can use the following steps in Windows (in Linux replace "copy" by "cp" One can use the following steps in Windows (in Linux replace "copy" by "cp"
and "type" by "cat"): and "type" by "cat"):
@@ -102,7 +102,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Including a certificate from a certificate authority Including a certificate from a certificate authority
---- ----
CivetWeb requires one certificate file in PEM format. LibHTTP requires one certificate file in PEM format.
If you got multiple files from your certificate authority, If you got multiple files from your certificate authority,
you need to copy their content together into one file. you need to copy their content together into one file.
Make sure the file has one section BEGIN RSA PRIVATE KEY / Make sure the file has one section BEGIN RSA PRIVATE KEY /
@@ -124,7 +124,7 @@ Common Problems
---- ----
In case the OpenSSL configuration is not set up correctly, the server will not In case the OpenSSL configuration is not set up correctly, the server will not
start. Configure an error log file in 'civetweb.conf' to get more information: start. Configure an error log file in 'libhttp.conf' to get more information:
<pre> <pre>
error_log_file error.log error_log_file error.log
</pre> </pre>

View File

@@ -2,9 +2,9 @@
Overview Overview
===== =====
Civetweb is small and easy to use web server. LibHTTP is small and easy to use web server.
It may be embedded into C/C++ host applications or used as a stand-alone It may be embedded into C/C++ host applications or used as a stand-alone
server. See `Embedding.md` for information on embedding civetweb into server. See `Embedding.md` for information on embedding LibHTTP into
host applications. host applications.
The stand-alone server is self-contained, and does not require any external The stand-alone server is self-contained, and does not require any external
@@ -14,71 +14,71 @@ software to run. Some Windows users may need to install the
Installation Installation
---- ----
On Windows, UNIX and Mac, the civetweb stand-alone executable may be started On Windows, UNIX and Mac, the LibHTTP stand-alone executable may be started
from the command line. from the command line.
Running `civetweb` in a terminal, optionally followed by configuration parameters Running `libhttp` in a terminal, optionally followed by configuration parameters
(`civetweb [OPTIONS]`) or a configuration file name (`civetweb [config_file_name]`), (`libhttp [OPTIONS]`) or a configuration file name (`libhttp [config_file_name]`),
starts the web server. starts the web server.
For UNIX and Mac, civetweb does not detach from the terminal. For UNIX and Mac, libhttp does not detach from the terminal.
Pressing `Ctrl-C` keys will stop the server. Pressing `Ctrl-C` keys will stop the server.
On Windows, civetweb iconifies itself to the system tray icon when started. On Windows, LibHTTP iconifies itself to the system tray icon when started.
Right-click on the icon pops up a menu, where it is possible to stop Right-click on the icon pops up a menu, where it is possible to stop
civetweb, or configure it, or install it as Windows service. LibHTTP, or configure it, or install it as Windows service.
When started without options, the server exposes the local directory at When started without options, the server exposes the local directory at
[http](http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) port 8080. [http](http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) port 8080.
Thus, the easiest way to share a folder on Windows is to copy `civetweb.exe` Thus, the easiest way to share a folder on Windows is to copy `libhttp.exe`
to this folder, double-click the exe, and launch a browser at to this folder, double-click the exe, and launch a browser at
[http://localhost:8080](http://localhost:8080). Note that 'localhost' should [http://localhost:8080](http://localhost:8080). Note that 'localhost' should
be changed to a machine's name if a folder is accessed from other computer. be changed to a machine's name if a folder is accessed from other computer.
When started, civetweb first searches for the configuration file. When started, LibHTTP first searches for the configuration file.
If configuration file is specified explicitly in the command line, i.e. If configuration file is specified explicitly in the command line, i.e.
`civetweb path_to_config_file`, then specified configuration file is used. `libhttp path_to_config_file`, then specified configuration file is used.
Otherwise, civetweb would search for file `civetweb.conf` in the same directory Otherwise, LibHTTP would search for file `libhttp.conf` in the same directory
the executable is located, and use it. This configuration file is optional. the executable is located, and use it. This configuration file is optional.
The configuration file is a sequence of lines, each line containing one The configuration file is a sequence of lines, each line containing one
command line argument name and the corresponding value. command line argument name and the corresponding value.
Empty lines, and lines beginning with `#`, are ignored. Empty lines, and lines beginning with `#`, are ignored.
Here is the example of `civetweb.conf` file: Here is the example of `libhttp.conf` file:
document_root c:\www document_root c:\www
listening_ports 80,443s listening_ports 80,443s
ssl_certificate c:\civetweb\ssl_cert.pem ssl_certificate c:\libhttp\ssl_cert.pem
When a configuration file is used, additional command line arguments may When a configuration file is used, additional command line arguments may
override the configuration file settings. override the configuration file settings.
All command line arguments must start with `-`. All command line arguments must start with `-`.
For example: The above `civetweb.conf` file is used, and civetweb started as For example: The above `libhttp.conf` file is used, and LibHTTP started as
`civetweb -document_root D:\web`. Then the `D:\web` directory will be served `libhttp -document_root D:\web`. Then the `D:\web` directory will be served
as document root, because command line options take priority over the as document root, because command line options take priority over the
configuration file. The configuration options section below provides a good configuration file. The configuration options section below provides a good
overview of the Civetweb features. overview of the LibHTTP features.
Note that configuration options on the command line must start with `-`, Note that configuration options on the command line must start with `-`,
but their names are the same as in the config file. All option names are but their names are the same as in the config file. All option names are
listed in the next section. Thus, the following two setups are equivalent: listed in the next section. Thus, the following two setups are equivalent:
# Using command line arguments # Using command line arguments
$ civetweb -listening_ports 1234 -document_root /var/www $ libhttp -listening_ports 1234 -document_root /var/www
# Using config file # Using config file
$ cat civetweb.conf $ cat libhttp.conf
listening_ports 1234 listening_ports 1234
document_root /var/www document_root /var/www
$ civetweb $libhttp
Civetweb can also be used to modify `.htpasswd` passwords files: LibHTTP can also be used to modify `.htpasswd` passwords files:
civetweb -A <htpasswd_file> <realm> <user> <passwd> libhttp -A <htpasswd_file> <realm> <user> <passwd>
Unlike other web servers, civetweb does not require CGI scripts to be located Unlike other web servers, LibHTTP does not require CGI scripts to be located
in a special directory. CGI scripts can be anywhere. CGI (and SSI) files are in a special directory. CGI scripts can be anywhere. CGI (and SSI) files are
recognized by the file name pattern. Civetweb uses shell-like glob recognized by the file name pattern. LibHTTP uses shell-like glob
patterns. Pattern match starts at the beginning of the string, so essentially patterns. Pattern match starts at the beginning of the string, so essentially
patterns are prefix patterns. Syntax is as follows: patterns are prefix patterns. Syntax is as follows:
@@ -96,7 +96,7 @@ All other characters in the pattern match themselves. Examples:
# Configuration Options # Configuration Options
Below is a list of configuration options understood by Civetweb. Below is a list of configuration options understood by LibHTTP.
Every option is followed by it's default value. If a default value is not Every option is followed by it's default value. If a default value is not
present, then the default is empty. present, then the default is empty.
@@ -119,16 +119,16 @@ DELETE requests might still be handled by Lua scripts and CGI paged.
### cgi\_interpreter ### cgi\_interpreter
Path to an executable to use as CGI interpreter for __all__ CGI scripts Path to an executable to use as CGI interpreter for __all__ CGI scripts
regardless of the script file extension. If this option is not set (which is regardless of the script file extension. If this option is not set (which is
the default), Civetweb looks at first line of a CGI script, the default), LibHTTP looks at first line of a CGI script,
[shebang line](http://en.wikipedia.org/wiki/Shebang_(Unix\)), for an [shebang line](http://en.wikipedia.org/wiki/Shebang_(Unix\)), for an
interpreter (not only on Linux and Mac but also for Windows). interpreter (not only on Linux and Mac but also for Windows).
For example, if both PHP and Perl CGIs are used, then For example, if both PHP and Perl CGIs are used, then
`#!/path/to/php-cgi.exe` and `#!/path/to/perl.exe` must be first lines of the `#!/path/to/php-cgi.exe` and `#!/path/to/perl.exe` must be first lines of the
respective CGI scripts. Note that paths should be either full file paths, respective CGI scripts. Note that paths should be either full file paths,
or file paths relative to the current working directory of the civetweb or file paths relative to the current working directory of the LibHTTP
server. If civetweb is started by mouse double-click on Windows, the current server. If LibHTTP is started by mouse double-click on Windows, the current
working directory is the directory where the civetweb executable is located. working directory is the directory where the LibHTTP executable is located.
If all CGIs use the same interpreter, for example they are all PHP, it is If all CGIs use the same interpreter, for example they are all PHP, it is
more efficient to set `cgi_interpreter` to the path to `php-cgi.exe`. more efficient to set `cgi_interpreter` to the path to `php-cgi.exe`.
@@ -158,7 +158,7 @@ should end with a special extension, by default the extension should be
either `.shtml` or `.shtm`. These extentions may be changed using the either `.shtml` or `.shtm`. These extentions may be changed using the
`ssi_pattern` option. `ssi_pattern` option.
Unknown SSI directives are silently ignored by civetweb. Currently, two SSI Unknown SSI directives are silently ignored by LibHTTP. Currently, two SSI
directives are supported, `<!--#include ...>` and directives are supported, `<!--#include ...>` and
`<!--#exec "command">`. Note that the `<!--#include ...>` directive supports `<!--#exec "command">`. Note that the `<!--#include ...>` directive supports
three path specifications: three path specifications:
@@ -221,7 +221,7 @@ password in digest format:
user:realm:digest user:realm:digest
test:test.com:ce0220efc2dd2fad6185e1f1af5a4327 test:test.com:ce0220efc2dd2fad6185e1f1af5a4327
Password files may be generated using `civetweb -A` as explained above, or Password files may be generated using `libhttp -A` as explained above, or
online tools e.g. [this generator](http://www.askapache.com/online-tools/htpasswd-generator). online tools e.g. [this generator](http://www.askapache.com/online-tools/htpasswd-generator).
### index\_files `index.xhtml,index.html,index.htm,index.cgi,index.shtml,index.php` ### index\_files `index.xhtml,index.html,index.htm,index.cgi,index.shtml,index.php`
@@ -243,7 +243,7 @@ client will time out.
### access\_control\_list ### access\_control\_list
An Access Control List (ACL) allows restrictions to be put on the list of IP An Access Control List (ACL) allows restrictions to be put on the list of IP
addresses which have access to the web server. In the case of the Civetweb addresses which have access to the web server. In the case of the LibHTTP
web server, the ACL is a comma separated list of IP subnets, where each web server, the ACL is a comma separated list of IP subnets, where each
subnet is pre-pended by either a `-` or a `+` sign. A plus sign means allow, subnet is pre-pended by either a `-` or a `+` sign. A plus sign means allow,
where a minus sign means deny. If a subnet mask is omitted, such as `-1.2.3.4`, where a minus sign means deny. If a subnet mask is omitted, such as `-1.2.3.4`,
@@ -307,49 +307,49 @@ avoid accidentally serving the wrong directory.
Path to the SSL certificate file. This option is only required when at least Path to the 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, 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 and it must have both, private key and certificate, see for example
[ssl_cert.pem](https://github.com/civetweb/civetweb/blob/master/resources/ssl_cert.pem) [ssl_cert.pem](https://github.com/lammertb/libhttp/blob/master/resources/ssl_cert.pem)
A description how to create a certificate can be found in doc/OpenSSL.md A description how to create a certificate can be found in doc/OpenSSL.md
### num\_threads `50` ### num\_threads `50`
Number of worker threads. Civetweb handles each incoming connection in a Number of worker threads. LibHTTP handles each incoming connection in a
separate thread. Therefore, the value of this option is effectively the number separate thread. Therefore, the value of this option is effectively the number
of concurrent HTTP connections Civetweb can handle. of concurrent HTTP connections LibHTTP can handle.
### run\_as\_user ### run\_as\_user
Switch to given user credentials after startup. Usually, this option is Switch to given user credentials after startup. Usually, this option is
required when civetweb needs to bind on privileged ports on UNIX. To do required when LibHTTP needs to bind on privileged ports on UNIX. To do
that, civetweb needs to be started as root. From a security point of view, that, LibHTTP needs to be started as root. From a security point of view,
running as root is not advisable, therefore this option can be used to drop running as root is not advisable, therefore this option can be used to drop
privileges. Example: privileges. Example:
civetweb -listening_ports 80 -run_as_user webserver libhttp -listening_ports 80 -run_as_user webserver
### url\_rewrite\_patterns ### url\_rewrite\_patterns
Comma-separated list of URL rewrites in the form of Comma-separated list of URL rewrites in the form of
`uri_pattern=file_or_directory_path`. When Civetweb receives any request, `uri_pattern=file_or_directory_path`. When LibHTTP receives any request,
it constructs the file name to show by combining `document_root` and the URI. it constructs the file name to show by combining `document_root` and the URI.
However, if the rewrite option is used and `uri_pattern` matches the However, if the rewrite option is used and `uri_pattern` matches the
requested URI, then `document_root` is ignored. Instead, requested URI, then `document_root` is ignored. Instead,
`file_or_directory_path` is used, which should be a full path name or `file_or_directory_path` is used, which should be a full path name or
a path relative to the web server's current working directory. Note that a path relative to the web server's current working directory. Note that
`uri_pattern`, as all civetweb patterns, is a prefix pattern. `uri_pattern`, as all LibHTTP patterns, is a prefix pattern.
This makes it possible to serve many directories outside from `document_root`, This makes it possible to serve many directories outside from `document_root`,
redirect all requests to scripts, and do other tricky things. For example, redirect all requests to scripts, and do other tricky things. For example,
to redirect all accesses to `.doc` files to a special script, do: to redirect all accesses to `.doc` files to a special script, do:
civetweb -url_rewrite_patterns **.doc$=/path/to/cgi-bin/handle_doc.cgi libhttp -url_rewrite_patterns **.doc$=/path/to/cgi-bin/handle_doc.cgi
Or, to imitate support for user home directories, do: Or, to imitate support for user home directories, do:
civetweb -url_rewrite_patterns /~joe/=/home/joe/,/~bill=/home/bill/ libhttp -url_rewrite_patterns /~joe/=/home/joe/,/~bill=/home/bill/
### hide\_files\_patterns ### hide\_files\_patterns
A pattern for the files to hide. Files that match the pattern will not A pattern for the files to hide. Files that match the pattern will not
show up in directory listing and return `404 Not Found` if requested. Pattern show up in directory listing and return `404 Not Found` if requested. Pattern
must be for a file name only, not including directory names. Example: must be for a file name only, not including directory names. Example:
civetweb -hide_files_patterns secret.txt|*.hide libhttp -hide_files_patterns secret.txt|*.hide
### request\_timeout\_ms `30000` ### request\_timeout\_ms `30000`
Timeout for network read and network write operations, in milliseconds. Timeout for network read and network write operations, in milliseconds.
@@ -378,7 +378,7 @@ content by including them between <? and ?> tags.
An example can be found in the test directory. An example can be found in the test directory.
### websocket\_root ### websocket\_root
In case civetweb is built with Lua and websocket support, Lua scripts may In case LibHTTP is built with Lua and websocket support, Lua scripts may
be used for websockets as well. Since websockets use a different URL scheme be used for websockets as well. Since websockets use a different URL scheme
(ws, wss) than other http pages (http, https), the Lua scripts used for (ws, wss) than other http pages (http, https), the Lua scripts used for
websockets may also be served from a different directory. By default, websockets may also be served from a different directory. By default,
@@ -484,7 +484,7 @@ This option can be used to enable or disable the use of the Linux `sendfile` sys
# Lua Scripts and Lua Server Pages # Lua Scripts and Lua Server Pages
Pre-built Windows and Mac civetweb binaries have built-in Lua scripting Pre-built Windows and Mac LibHTTP binaries have built-in Lua scripting
support as well as support for Lua Server Pages. support as well as support for Lua Server Pages.
Lua scripts (default extension: *.lua) use plain Lua syntax. Lua scripts (default extension: *.lua) use plain Lua syntax.
@@ -509,7 +509,7 @@ page, one can write:
URI is <?=mg.request_info.uri?> URI is <?=mg.request_info.uri?>
</p> </p>
Lua is known for it's speed and small size. Civetweb currently uses Lua Lua is known for it's speed and small size. LibHTTP currently uses Lua
version 5.2.4. The documentation for it can be found in the version 5.2.4. The documentation for it can be found in the
[Lua 5.2 reference manual](http://www.lua.org/manual/5.2/). [Lua 5.2 reference manual](http://www.lua.org/manual/5.2/).
@@ -519,30 +519,30 @@ web client. Using `mg.write()` is the way to generate web content from inside
Lua code. In addition to `mg.write()`, all standard Lua library functions Lua code. In addition to `mg.write()`, all standard Lua library functions
are accessible from the Lua code (please check the reference manual for are accessible from the Lua code (please check the reference manual for
details). Lua functions working on files (e.g., `io.open`) use a path details). Lua functions working on files (e.g., `io.open`) use a path
relative to the working path of the civetweb process. The web server content relative to the working path of the LibHTTP process. The web server content
is located in the path `mg.document_root`. is located in the path `mg.document_root`.
Information on the request is available in the `mg.request_info` Information on the request is available in the `mg.request_info`
object, like the request method, all HTTP headers, etcetera. object, like the request method, all HTTP headers, etcetera.
[page2.lua](https://github.com/civetweb/civetweb/blob/master/test/page2.lua) [page2.lua](https://github.com/lammertb/libhttp/blob/master/test/page2.lua)
is an example for a plain Lua script. is an example for a plain Lua script.
[page2.lp](https://github.com/civetweb/civetweb/blob/master/test/page2.lp) [page2.lp](https://github.com/lammertb/libhttp/blob/master/test/page2.lp)
is an example for a Lua Server Page. is an example for a Lua Server Page.
Both examples show the content of the `mg.request_info` object as the page Both examples show the content of the `mg.request_info` object as the page
content. Please refer to `struct mg_request_info` definition in content. Please refer to `struct mg_request_info` definition in
[civetweb.h](https://github.com/civetweb/civetweb/blob/master/include/civetweb.h) [libhttp.h](https://github.com/lammertb/libhttp/blob/master/include/libhttp.h)
to see additional information on the elements of the `mg.request_info` object. to see additional information on the elements of the `mg.request_info` object.
Civetweb also provides access to the [SQlite3 database](http://www.sqlite.org/) LibHTTP also provides access to the [SQlite3 database](http://www.sqlite.org/)
through the [LuaSQLite3 interface](http://lua.sqlite.org/index.cgi/doc/tip/doc/lsqlite3.wiki) through the [LuaSQLite3 interface](http://lua.sqlite.org/index.cgi/doc/tip/doc/lsqlite3.wiki)
in Lua. Examples are given in in Lua. Examples are given in
[page.lua](https://github.com/civetweb/civetweb/blob/master/test/page.lua) and [page.lua](https://github.com/lammertb/libhttp/blob/master/test/page.lua) and
[page.lp](https://github.com/civetweb/civetweb/blob/master/test/page.lp). [page.lp](https://github.com/lammertb/libhttp/blob/master/test/page.lp).
Civetweb exports the following functions to Lua: LibHTTP exports the following functions to Lua:
mg (table): mg (table):
@@ -551,7 +551,7 @@ mg (table):
mg.include(path) -- sources another Lua file mg.include(path) -- sources another Lua file
mg.redirect(uri) -- internal redirect to a given URI mg.redirect(uri) -- internal redirect to a given URI
mg.onerror(msg) -- error handler, can be overridden mg.onerror(msg) -- error handler, can be overridden
mg.version -- a string that holds Civetweb version mg.version -- a string that holds LibHTTP version
mg.document_root -- a string that holds the document root directory mg.document_root -- a string that holds the document root directory
mg.auth_domain -- a string that holds the HTTP authentication domain mg.auth_domain -- a string that holds the HTTP authentication domain
mg.get_var(str, varname) -- extract variable from (query) string mg.get_var(str, varname) -- extract variable from (query) string
@@ -588,28 +588,28 @@ connect (function):
local host = 'code.google.com' -- IP address or domain name local host = 'code.google.com' -- IP address or domain name
local ok, sock = pcall(connect, host, 80, 1) local ok, sock = pcall(connect, host, 80, 1)
if ok then if ok then
sock:send('GET /p/civetweb/ HTTP/1.0\r\n' .. sock:send('GET /p/libhttp/ HTTP/1.0\r\n' ..
'Host: ' .. host .. '\r\n\r\n') 'Host: ' .. host .. '\r\n\r\n')
local reply = sock:recv() local reply = sock:recv()
sock:close() sock:close()
-- reply now contains the web page https://code.google.com/p/civetweb -- reply now contains the web page https://code.google.com/p/libhttp
end end
**IMPORTANT: Civetweb does not send HTTP headers for Lua pages. Therefore, **IMPORTANT: LibHTTP does not send HTTP headers for Lua pages. Therefore,
every Lua Page must begin with a HTTP reply line and headers**, like this: every Lua Page must begin with a HTTP reply line and headers**, like this:
<? print('HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n') ?> <? print('HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n') ?>
<html><body> <html><body>
... the rest of the web page ... ... the rest of the web page ...
To serve a Lua Page, civetweb creates a Lua context. That context is used for To serve a Lua Page, LibHTTP creates a Lua context. That context is used for
all Lua blocks within the page. That means, all Lua blocks on the same page all Lua blocks within the page. That means, all Lua blocks on the same page
share the same context. If one block defines a variable, for example, that share the same context. If one block defines a variable, for example, that
variable is visible in all block that follow. variable is visible in all block that follow.
## Websockets for Lua ## Websockets for Lua
Civetweb offers support for websockets in Lua as well. In contrast to plain LibHTTP offers support for websockets in Lua as well. In contrast to plain
Lua scripts and Lua server pages, Lua websocket scripts are shared by all clients. Lua scripts and Lua server pages, Lua websocket scripts are shared by all clients.
Lua websocket scripts must define a few functions: Lua websocket scripts must define a few functions:
@@ -626,7 +626,7 @@ must return true in order to keep the connetion open.
Lua websocket pages do support single shot (timeout) and interval timers. Lua websocket pages do support single shot (timeout) and interval timers.
An example is shown in An example is shown in
[websocket.lua](https://github.com/civetweb/civetweb/blob/master/test/websocket.lua). [websocket.lua](https://github.com/lammertb/libhttp/blob/master/test/websocket.lua).
# Common Problems # Common Problems
@@ -634,7 +634,7 @@ An example is shown in
reason for that is wrong paths to the interpreter. Remember that with PHP, reason for that is wrong paths to the interpreter. Remember that with PHP,
the correct interpreter is `php-cgi.exe` (`php-cgi` on UNIX). the correct interpreter is `php-cgi.exe` (`php-cgi` on UNIX).
Solution: specify the full path to the PHP interpreter, e.g.: Solution: specify the full path to the PHP interpreter, e.g.:
`civetweb -cgi_interpreter /full/path/to/php-cgi` `libhttp -cgi_interpreter /full/path/to/php-cgi`
- `php-cgi` is unavailable, for example on Mac OS X. As long as the `php` binary is installed, you can run CGI programs in command line mode (see the example below). Note that in this mode, `$_GET` and friends will be unavailable, and you'll have to parse the query string manually using [parse_str](http://php.net/manual/en/function.parse-str.php) and the `QUERY_STRING` environmental variable. - `php-cgi` is unavailable, for example on Mac OS X. As long as the `php` binary is installed, you can run CGI programs in command line mode (see the example below). Note that in this mode, `$_GET` and friends will be unavailable, and you'll have to parse the query string manually using [parse_str](http://php.net/manual/en/function.parse-str.php) and the `QUERY_STRING` environmental variable.
@@ -644,13 +644,13 @@ An example is shown in
echo "Hello World!\n"; echo "Hello World!\n";
?> ?>
- Civetweb fails to start. If Civetweb exits immediately when started, this - LibHTTP fails to start. If LibHTTP exits immediately when started, this
usually indicates a syntax error in the configuration file usually indicates a syntax error in the configuration file
(named `civetweb.conf` by default) or the command-line arguments. (named `libhttp.conf` by default) or the command-line arguments.
Syntax checking is omitted from Civetweb to keep its size low. However, Syntax checking is omitted from LibHTTP to keep its size low. However,
the Manual should be of help. Note: the syntax changes from time to time, the Manual should be of help. Note: the syntax changes from time to time,
so updating the config file might be necessary after executable update. so updating the config file might be necessary after executable update.
- Embedding with OpenSSL on Windows might fail because of calling convention. - Embedding with OpenSSL on Windows might fail because of calling convention.
To force Civetweb to use `__stdcall` convention, add `/Gz` compilation To force LibHTTP to use `__stdcall` convention, add `/Gz` compilation
flag in Visual Studio compiler. flag in Visual Studio compiler.

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `struct client_cert;` ### `struct client_cert;`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `struct mg_callbacks;` ### `struct mg_callbacks;`
@@ -7,52 +7,52 @@
| Field | Description | | Field | Description |
| :--- | :--- | | :--- | :--- |
|**`begin_request`**|**`int (*begin_request)( struct mg_connection * conn );`**| |**`begin_request`**|**`int (*begin_request)( struct mg_connection * conn );`**|
| |The `begin_request()` callback function is called when CivetWeb has received a new HTTP request. If the callback function does not process the request, it should return 0. In that case CivetWeb will handle the request with the default callback routine. If the callback function returns a value between 1 and 999, CivetWeb does nothing and the callback function should do all the processing, including sending the proper HTTP headers etc. Starting at CivetWeb version 1.7, the function `begin_request()` is called before any authorization is done. If an authorization check is required, `request_handler()` should be used instead. The return value of the callback function is not only used to signal CivetWeb to not further process the request. The returned value is also stored as HTTP status code in the access log. | | |The `begin_request()` callback function is called when LibHTTP has received a new HTTP request. If the callback function does not process the request, it should return 0. In that case LibHTTP will handle the request with the default callback routine. If the callback function returns a value between 1 and 999, LibHTTP does nothing and the callback function should do all the processing, including sending the proper HTTP headers etc. Starting at LibHTTP version 1.7, the function `begin_request()` is called before any authorization is done. If an authorization check is required, `request_handler()` should be used instead. The return value of the callback function is not only used to signal LibHTTP to not further process the request. The returned value is also stored as HTTP status code in the access log. |
|**`connection_close`**|**`void (*connection_close)( const struct mg_connection *conn );`**| |**`connection_close`**|**`void (*connection_close)( const struct mg_connection *conn );`**|
| |The callback function `connection_close()` is called when CivetWeb is closing a connection. The per-context mutex is locked when the callback function is invoked. The function is primarly useful for noting when a websocket is closing and removing it from any application-maintained list of clients. *Using this callback for websocket connections is deprecated. Use* `mg_set_websocket_handler()` *instead.*| | |The callback function `connection_close()` is called when LibHTTP is closing a connection. The per-context mutex is locked when the callback function is invoked. The function is primarly useful for noting when a websocket is closing and removing it from any application-maintained list of clients. *Using this callback for websocket connections is deprecated. Use* `mg_set_websocket_handler()` *instead.*|
|**`end_request`**|**`void (*end_request)( const struct mg_connection * conn );`**| |**`end_request`**|**`void (*end_request)( const struct mg_connection * conn );`**|
| |The callback function `end_request()` is called by CivetWeb when a request has been completely processed. It sends the reply status code which was sent to the client to the application.| | |The callback function `end_request()` is called by LibHTTP when a request has been completely processed. It sends the reply status code which was sent to the client to the application.|
|**`exit_context`**|**`void (*exit_context)( const struct mg_context *ctx );`**| |**`exit_context`**|**`void (*exit_context)( const struct mg_context *ctx );`**|
| |The callback function `exit_context()` is called by CivetWeb when the server is stopped. It allows the application to do some cleanup on the application side.| | |The callback function `exit_context()` is called by LibHTTP when the server is stopped. It allows the application to do some cleanup on the application side.|
|**`http_error`**|**`int (*http_error)( struct mg_connection *conn, int status );`**| |**`http_error`**|**`int (*http_error)( struct mg_connection *conn, int status );`**|
| |The callback function `http_error()` is called by CivetWeb just before an HTTP error is to be sent to the client. The function allows the application to send a custom error page. The status code of the error is provided as a parameter. If the application sends their own error page, it must return 1 to signal CivetWeb that no further processing is needed. If the returned value is 0, CivetWeb will send a built-in error page to the client.| | |The callback function `http_error()` is called by LibHTTP just before an HTTP error is to be sent to the client. The function allows the application to send a custom error page. The status code of the error is provided as a parameter. If the application sends their own error page, it must return 1 to signal LibHTTP that no further processing is needed. If the returned value is 0, LibHTTP will send a built-in error page to the client.|
|**`init_context`**|**`void (*init_context)( const struct mg_context *ctx );`**| |**`init_context`**|**`void (*init_context)( const struct mg_context *ctx );`**|
| |The callback function `init_context()` is called after the CivetWeb server has been started and initialized, but before any requests are served. This allowes the application to perform some initialization activities before the first requests are handled.| | |The callback function `init_context()` is called after the LibHTTP server has been started and initialized, but before any requests are served. This allowes the application to perform some initialization activities before the first requests are handled.|
|**`init_lua`**|**`void (*init_lua)( const struct mg_connection *conn, void *lua_context );`**| |**`init_lua`**|**`void (*init_lua)( const struct mg_connection *conn, void *lua_context );`**|
| |The callback function `init_lua()` is called just before a Lua server page is to be served. Lua page serving must have been enabled at compile time for this callback function to be called. The parameter `lua_context` is a `lua_State *` pointer.| | |The callback function `init_lua()` is called just before a Lua server page is to be served. Lua page serving must have been enabled at compile time for this callback function to be called. The parameter `lua_context` is a `lua_State *` pointer.|
|**`init_ssl`**|**`int (*init_ssl)( void *ssl_context, void *user_data );`**| |**`init_ssl`**|**`int (*init_ssl)( void *ssl_context, void *user_data );`**|
| |The callback function `init_ssl()` is called when CivetWeb initializes the SSL library. The parameter `user_data` contains a pointer to the data which was provided to `mg_start()` when the server was started. The callback function can return 0 to signal that CivetWeb should setup the SSL certificate. With a return value of 1 the callback function signals CivetWeb that the certificate has already been setup and no further processing is necessary. The value -1 should be returned when the SSL initialization fails.| | |The callback function `init_ssl()` is called when LibHTTP initializes the SSL library. The parameter `user_data` contains a pointer to the data which was provided to `mg_start()` when the server was started. The callback function can return 0 to signal that LibHTTP should setup the SSL certificate. With a return value of 1 the callback function signals LibHTTP that the certificate has already been setup and no further processing is necessary. The value -1 should be returned when the SSL initialization fails.|
|**`init_thread`**|**`void (*init_thread)( const struct mg_context *ctx, int thread_type );`**| |**`init_thread`**|**`void (*init_thread)( const struct mg_context *ctx, int thread_type );`**|
| |The callback function `init_thread()` is called when a new thread is created by CivetWeb. The `thread_type` parameter indicates which type of thread has been created. following thread types are recognized:| | |The callback function `init_thread()` is called when a new thread is created by LibHTTP. The `thread_type` parameter indicates which type of thread has been created. following thread types are recognized:|
| |**0** - The master thread is created | | |**0** - The master thread is created |
| |**1** - A worker thread which handles client connections has been created| | |**1** - A worker thread which handles client connections has been created|
| |**2** - An internal helper thread (timer thread) has been created| | |**2** - An internal helper thread (timer thread) has been created|
|**`log_access`**|**`int (*log_access)( const struct mg_connection *conn, const char *message );`**| |**`log_access`**|**`int (*log_access)( const struct mg_connection *conn, const char *message );`**|
| |The callback function `log_access()` is called when CivetWeb is about to log a message. If the callback function returns 0, CivetWeb will use the default internal access log routines to log the access. If a non-zero value is returned, CivetWeb assumes that access logging has already been done and no further action is performed.| | |The callback function `log_access()` is called when LibHTTP is about to log a message. If the callback function returns 0, LibHTTP will use the default internal access log routines to log the access. If a non-zero value is returned, LibHTTP assumes that access logging has already been done and no further action is performed.|
|**`log_message`**|**`int (*log_message)( const struct mg_connection *conn, const char *message );`**| |**`log_message`**|**`int (*log_message)( const struct mg_connection *conn, const char *message );`**|
| |The callback function `log_message()` is called when CivetWeb is about to log a message. If the callback function returns 0, CivetWeb will use the default internal log routines to log the message. If a non-zero value is returned CivetWeb assumes that logging has already been done and no further action is performed.| | |The callback function `log_message()` is called when LibHTTP is about to log a message. If the callback function returns 0, LibHTTP will use the default internal log routines to log the message. If a non-zero value is returned LibHTTP assumes that logging has already been done and no further action is performed.|
|**`open_file`**|**`const char *(*open_file)( const struct mg_connection *conn, const char *path, size_t *data_len );`**| |**`open_file`**|**`const char *(*open_file)( const struct mg_connection *conn, const char *path, size_t *data_len );`**|
| |The callback function `open_file()` is called when a file is to be opened by CivetWeb. The callback can return a pointer to a memory location and set the memory block size in the variable pointed to by `data_len` to signal CivetWeb that the file should not be loaded from disk, but that instead a stored version in memory should be used. If the callback function returns NULL, CivetWeb will open the file from disk. This callback allows caching to be implementedi at the application side, or to serve specific files from static memory instead of from disk.| | |The callback function `open_file()` is called when a file is to be opened by LibHTTP. The callback can return a pointer to a memory location and set the memory block size in the variable pointed to by `data_len` to signal LibHTTP that the file should not be loaded from disk, but that instead a stored version in memory should be used. If the callback function returns NULL, LibHTTP will open the file from disk. This callback allows caching to be implementedi at the application side, or to serve specific files from static memory instead of from disk.|
|~~`upload`~~|**`void (*upload)( struct mg_connection * conn, const char *file_name );`**| |~~`upload`~~|**`void (*upload)( struct mg_connection * conn, const char *file_name );`**|
| |*Deprecated. Use* `mg_handle_form_request()` *instead.* The callback function `upload()` is called when CivetWeb has uploaded a file to a temporary directory as result of a call to `mg_upload()`. The parameter `file_name` contains the full file name including path to the uploaded file.| | |*Deprecated. Use* `mg_handle_form_request()` *instead.* The callback function `upload()` is called when LibHTTP has uploaded a file to a temporary directory as result of a call to `mg_upload()`. The parameter `file_name` contains the full file name including path to the uploaded file.|
|~~`websocket_connect`~~|**`int (*websocket_connect)( const struct mg_connection *conn );`**| |~~`websocket_connect`~~|**`int (*websocket_connect)( const struct mg_connection *conn );`**|
| |*Deprecated. Use* `mg_set_websocket_handler()` *instead.* The callback function `websocket_connect()` is called when a websocket request is received, before the actual websocket handshake has taken place. The callback function can signal to CivetWeb if it should accept or deny the incoming request with one of the following return values: | | |*Deprecated. Use* `mg_set_websocket_handler()` *instead.* The callback function `websocket_connect()` is called when a websocket request is received, before the actual websocket handshake has taken place. The callback function can signal to LibHTTP if it should accept or deny the incoming request with one of the following return values: |
| |**0** - CivetWeb can proceed with the handshake to accept the connection | | |**0** - LibHTTP can proceed with the handshake to accept the connection |
| |**1** - CivetWeb must close the connection immediately without performing a handshake | | |**1** - LibHTTP must close the connection immediately without performing a handshake |
|~~`websocket_data`~~|**`int (*websocket_data)( struct mg_connection *conn, int bits, char *data, size_t data_len );`**| |~~`websocket_data`~~|**`int (*websocket_data)( struct mg_connection *conn, int bits, char *data, size_t data_len );`**|
| |*Deprecated. Use* `mg_set_websocket_handler()` *instead.* The callback function `websocket_data()` is called when a data frame has been received from the client. The parameters contain the following information: | | |*Deprecated. Use* `mg_set_websocket_handler()` *instead.* The callback function `websocket_data()` is called when a data frame has been received from the client. The parameters contain the following information: |
| | **`bits`** - The first byte of the websocket frame. See [RFC-6455](http://tools.ietf.org/html/rfc6455) at section 5.2 for more information. | | | **`bits`** - The first byte of the websocket frame. See [RFC-6455](http://tools.ietf.org/html/rfc6455) at section 5.2 for more information. |
| | **`data`** - The pointer to the received data block. Masks--if any--have already been applied. | | | **`data`** - The pointer to the received data block. Masks--if any--have already been applied. |
| | **`data_len`** - The length of the received data block | | | **`data_len`** - The length of the received data block |
| | If the application wants to keep the websocket open to receive more data, the callback function should return the value **1**. If the value **0** is returned by the callback function, CivetWeb will close the websocket connection and no more frames will be received.| | | If the application wants to keep the websocket open to receive more data, the callback function should return the value **1**. If the value **0** is returned by the callback function, LibHTTP will close the websocket connection and no more frames will be received.|
|~~`websocket_ready`~~|**`int (*websocket_ready)( struct mg_connection *conn );`**| |~~`websocket_ready`~~|**`int (*websocket_ready)( struct mg_connection *conn );`**|
| |*Deprecated. Use* `mg_set_websocket_handler()` *instead.* The callback function `websocket_ready()` is called after the handshake of a websocket connection has succeeded succesfully to signal the application that the connection is ready for use. | | |*Deprecated. Use* `mg_set_websocket_handler()` *instead.* The callback function `websocket_ready()` is called after the handshake of a websocket connection has succeeded succesfully to signal the application that the connection is ready for use. |
### Description ### Description
Much of the functionality in the Civetweb library is provided through callback functions. The application registers their own processing functions with the Civetweb library and when an event happens, the appropriate callback function is called. In this way an application is able to have their processing code right at the heart of the webserver, without the need to change the code of the webserver itself. A number of callback functions are registered when the civetweb subsystem is started. Other may be added or changed at runtime with helper functions. Much of the functionality in the LibHTTP library is provided through callback functions. The application registers their own processing functions with the LibHTTP library and when an event happens, the appropriate callback function is called. In this way an application is able to have their processing code right at the heart of the webserver, without the need to change the code of the webserver itself. A number of callback functions are registered when the LibHTTP subsystem is started. Other may be added or changed at runtime with helper functions.
A pointer to a `mg_callbacks` structure is passed as parameter to the [`mg_start()`](mg_start.md) function to provide links to callback functions which the webserver will call at specific events. If a specific callback function is not supplied, CivetWeb will fallback to default internal callback routines. Callback functions give the application detailed control over how specific events should be handled. A pointer to a `mg_callbacks` structure is passed as parameter to the [`mg_start()`](mg_start.md) function to provide links to callback functions which the webserver will call at specific events. If a specific callback function is not supplied, LibHTTP will fallback to default internal callback routines. Callback functions give the application detailed control over how specific events should be handled.
### See Also ### See Also

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_check_feature( feature );` ### `mg_check_feature( feature );`
@@ -16,18 +16,18 @@
### Description ### Description
The function `mg_check_feature()` can be called from an application program to check of specific features have been compiled in the civetweb version which the application has been linked to. The feature to check is provided as an unsigned integer parameter. If the function is available in the currently linked library version, a value **> 0** is returned. Otherwise the function `mg_check_feature()` returns the value **0**. The function `mg_check_feature()` can be called from an application program to check of specific features have been compiled in the LibHTTP version which the application has been linked to. The feature to check is provided as an unsigned integer parameter. If the function is available in the currently linked library version, a value **> 0** is returned. Otherwise the function `mg_check_feature()` returns the value **0**.
The following parameter values can be used: The following parameter values can be used:
| Value | Compilation option | Description | | Value | Compilation option | Description |
| :---: | :---: | :--- | | :---: | :---: | :--- |
| **1** | NO_FILES | *Able to serve files*. If this feature is available, the webserver is able to serve files directly from a directory tree. | | **1** | NO_FILES | *Able to serve files*. If this feature is available, the webserver is able to serve files directly from a directory tree. |
| **2** | NO_SSL | *Support for HTTPS*. If this feature is available, the webserver van use encryption in the client-server connection. SSLv2, SSLv3, TLSv1.0, TLSv1.1 and TLSv1.2 are supported depending on the SSL library CivetWeb has been compiled with, but which protocols are used effectively when the server is running is dependent on the options used when the server is started. | | **2** | NO_SSL | *Support for HTTPS*. If this feature is available, the webserver van use encryption in the client-server connection. SSLv2, SSLv3, TLSv1.0, TLSv1.1 and TLSv1.2 are supported depending on the SSL library LibHTTP has been compiled with, but which protocols are used effectively when the server is running is dependent on the options used when the server is started. |
| **4** | NO_CGI | *Support for CGI*. If this feature is available, external CGI scripts can be called by the webserver. | | **4** | NO_CGI | *Support for CGI*. If this feature is available, external CGI scripts can be called by the webserver. |
| **8** | USE_IPV6 | *Support IPv6*. The CivetWeb library is capable of communicating over both IPv4 and IPv6, but IPv6 support is only available if it has been enabled at compile time. | | **8** | USE_IPV6 | *Support IPv6*. The LibHTTP library is capable of communicating over both IPv4 and IPv6, but IPv6 support is only available if it has been enabled at compile time. |
| **16** | USE_WEBSOCKET | Support for web sockets. WebSockets support is available in the CivetWeb library if the proper options has been used during cimpile time. | | **16** | USE_WEBSOCKET | Support for web sockets. WebSockets support is available in the LibHTTP library if the proper options has been used during cimpile time. |
| **32** | USE_LUA | *Support for Lua scripts and Lua server pages*. CivetWeb supports server side scripting through the Lua language, if that has been enabled at compile time. Lua is an efficient scripting language which is less resource heavy than for example PHP. | | **32** | USE_LUA | *Support for Lua scripts and Lua server pages*. LibHTTP supports server side scripting through the Lua language, if that has been enabled at compile time. Lua is an efficient scripting language which is less resource heavy than for example PHP. |
| **64** | USE_DUKTAPE | *Support for server side JavaScript*. Server side JavaScript can be used for dynamic page generation if the proper options have been set at compile time. Please note that client side JavaScript execution is always available if it has been enabled in the connecting browser. | | **64** | USE_DUKTAPE | *Support for server side JavaScript*. Server side JavaScript can be used for dynamic page generation if the proper options have been set at compile time. Please note that client side JavaScript execution is always available if it has been enabled in the connecting browser. |
| **128** | NO_CACHING | *Support for caching*. The webserver will support caching, if it has not been disabled while compiling the library. | | **128** | NO_CACHING | *Support for caching*. The webserver will support caching, if it has not been disabled while compiling the library. |

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `struct mg_client_options;` ### `struct mg_client_options;`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_close_connection( conn );` ### `mg_close_connection( conn );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_connect_client( host, port, use_ssl, error_buffer, error_buffer_size );` ### `mg_connect_client( host, port, use_ssl, error_buffer, error_buffer_size );`
@@ -20,7 +20,7 @@
### Description ### Description
The function `mg_connect_client()` connects to a TCP server as a client. This server can be a HTTP server but this is not necessary. The function returns a pointer to a connection structure when the connection is established and NULL otherwise. The host may be on IPv4 or IPv6, but IPv6 is not enabled in every Civetweb installation. Specifically the use of IPv6 communications has to be enabled when the library is compiled. At runtime you can use the [`mg_check_feature()`](mg_check_feature.md) function with the parameter `USE_IPV6` to check if IPv6 communication is supported. The function `mg_connect_client()` connects to a TCP server as a client. This server can be a HTTP server but this is not necessary. The function returns a pointer to a connection structure when the connection is established and NULL otherwise. The host may be on IPv4 or IPv6, but IPv6 is not enabled in every LibHTTP installation. Specifically the use of IPv6 communications has to be enabled when the library is compiled. At runtime you can use the [`mg_check_feature()`](mg_check_feature.md) function with the parameter `USE_IPV6` to check if IPv6 communication is supported.
### See Also ### See Also

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_connect_client_secure( client_options, error_buffer, error_buffer_size );` ### `mg_connect_client_secure( client_options, error_buffer, error_buffer_size );`
@@ -20,7 +20,7 @@
The function `mg_connect_client_secure()` creates a secure connection with a server. The information about the connection and server is passed in a structure and an error message may be returned in a local buffer. The function returns a pointer to a `struct mg_connection` structure when successful and NULL otherwise. The function `mg_connect_client_secure()` creates a secure connection with a server. The information about the connection and server is passed in a structure and an error message may be returned in a local buffer. The function returns a pointer to a `struct mg_connection` structure when successful and NULL otherwise.
Please note that IPv6 communication is supported by Civetweb, but only if the use of IPv6 was enabled at compile time. The check while running a program if IPv6 communication is possible you can call [`mg_check_feature()`](mg_check_feature.md) with the `USE_IPV6` parameter to check if IPv6 communications can be used. Please note that IPv6 communication is supported by LibHTTP, but only if the use of IPv6 was enabled at compile time. The check while running a program if IPv6 communication is possible you can call [`mg_check_feature()`](mg_check_feature.md) with the `USE_IPV6` parameter to check if IPv6 communications can be used.
### See Also ### See Also

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_connect_websocket_client( host, port, use_ssl, error_buffer, error_buffer_size, path, origin, data_func, close_func, user-data);` ### `mg_connect_websocket_client( host, port, use_ssl, error_buffer, error_buffer_size, path, origin, data_func, close_func, user-data);`
@@ -27,7 +27,7 @@
The function `mg_connect_websocket_client()` connects to a websocket on a server as a client. Data and close events are processed with callback functions which must be provided in the call. The function `mg_connect_websocket_client()` connects to a websocket on a server as a client. Data and close events are processed with callback functions which must be provided in the call.
Civetweb supports both IPv4 and IPv6 communication, but only if the use if IPv6 has been enabled at compile time. When running an application it is possible to check if IPv6 addressing is available by calling the [`mg_check_feature()`](mg_check_feature.md) function with the `USE_IPV6` parameter. LibHTTP supports both IPv4 and IPv6 communication, but only if the use if IPv6 has been enabled at compile time. When running an application it is possible to check if IPv6 addressing is available by calling the [`mg_check_feature()`](mg_check_feature.md) function with the `USE_IPV6` parameter.
### See Also ### See Also

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_cry( conn, fmt, ... );` ### `mg_cry( conn, fmt, ... );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_download( host, port, use_ssl, error_buffer, error_buffer_size, fmt, ... );` ### `mg_download( host, port, use_ssl, error_buffer, error_buffer_size, fmt, ... );`
@@ -29,7 +29,7 @@ The format string is a format string from the `printf()` series of functions to
`conn = mg_download( "google.com", 80, 0, ebuf, sizeof(ebuf), `conn = mg_download( "google.com", 80, 0, ebuf, sizeof(ebuf),
"%s", "GET / HTTP/1.0\r\nHost: google.com\r\n\r\n" );` "%s", "GET / HTTP/1.0\r\nHost: google.com\r\n\r\n" );`
Please note that although Civetweb supports both IPv4 and IPv6 communication that IPv6 addressing is only available if it was enabled at compile time. When running an application it is possible to check if IPv6 support has been compiled in by using the [`mg_check_feature()`](md_check_feature.md) function with the parameter `USE_IPV6`. Please note that although LibHTTP supports both IPv4 and IPv6 communication that IPv6 addressing is only available if it was enabled at compile time. When running an application it is possible to check if IPv6 support has been compiled in by using the [`mg_check_feature()`](md_check_feature.md) function with the parameter `USE_IPV6`.
### See Also ### See Also

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `struct mg_form_data_handler;` ### `struct mg_form_data_handler;`
@@ -10,17 +10,17 @@
||The callback function `field_found()` is called when a new field has been found. The return value of this callback is used to define how the field should be processed. The parameters contain the following information:| ||The callback function `field_found()` is called when a new field has been found. The return value of this callback is used to define how the field should be processed. The parameters contain the following information:|
||**`key`** - The name of the field as it was named with the `name` tag in the HTML source.| ||**`key`** - The name of the field as it was named with the `name` tag in the HTML source.|
||**`filename`** - The name of the file to upload. Please not that this parameter is only valid when the input type was set to `file`. Otherwise this parameter has the value `NULL`.| ||**`filename`** - The name of the file to upload. Please not that this parameter is only valid when the input type was set to `file`. Otherwise this parameter has the value `NULL`.|
||**`path`** - This is an output parameter used to store the full name of the file including the path to store an incoming file at the computer. This parameter must be provided by the application to Civetweb when a form field of type `file` is found. Please not that together with setting this parameter, the callback function must return `FORM_FIELD_STORAGE_STORE`.i With any other return value the contents of the `path` buffer is ignored by Civetweb.| ||**`path`** - This is an output parameter used to store the full name of the file including the path to store an incoming file at the computer. This parameter must be provided by the application to LibHTTP when a form field of type `file` is found. Please not that together with setting this parameter, the callback function must return `FORM_FIELD_STORAGE_STORE`.i With any other return value the contents of the `path` buffer is ignored by LibHTTP.|
||**`pathlen`** - The length of the buffer where the output path can be stored.| ||**`pathlen`** - The length of the buffer where the output path can be stored.|
||**`user_data`** - A pointer to the value of the field `user_data` of the structure `struct mg_form_data_handler`.| ||**`user_data`** - A pointer to the value of the field `user_data` of the structure `struct mg_form_data_handler`.|
||The callback function `field_found()` can return the following values back to Civetweb:| ||The callback function `field_found()` can return the following values back to LibHTTP:|
||**`FORM_FIELD_STORAGE_SKIP`** - Ignore the field and continue with processing the next field| ||**`FORM_FIELD_STORAGE_SKIP`** - Ignore the field and continue with processing the next field|
||**`FORM_FIELD_STORAGE_GET`** - Call the callback function `field_get()` to receive the form data| ||**`FORM_FIELD_STORAGE_GET`** - Call the callback function `field_get()` to receive the form data|
||**`FORM_FIELD_STORAGE_STORE`** - Store a file as `path` and overwrite that file if it already exists| ||**`FORM_FIELD_STORAGE_STORE`** - Store a file as `path` and overwrite that file if it already exists|
||**`FORM_FIELD_STORAGE_ABORT`** - Stop parsing the request and ignore all remaining form fields| ||**`FORM_FIELD_STORAGE_ABORT`** - Stop parsing the request and ignore all remaining form fields|
|**`field_get`**|**`int field_get( const char *key, const char *value, size_t valuelen, void *user_data );`**| |**`field_get`**|**`int field_get( const char *key, const char *value, size_t valuelen, void *user_data );`**|
|**`field_store`**|**`int field_store( const char *path, long long file_size, void *user_data );`**| |**`field_store`**|**`int field_store( const char *path, long long file_size, void *user_data );`**|
||If the callback function `field_found()` returned `FORM_FIELD_STORAGE_STORE`, Civetweb will try to store the received data in a file. If writing the file is successful, the callback function `field_store()` is called. This function is only called after completion of a full upload, not if a file has only partly been uploaded. When only part of a file is received, Civetweb will delete that partly upload in the background and not inform the main application through this callback. The following parameters are provided in the function call:| ||If the callback function `field_found()` returned `FORM_FIELD_STORAGE_STORE`, LibHTTP will try to store the received data in a file. If writing the file is successful, the callback function `field_store()` is called. This function is only called after completion of a full upload, not if a file has only partly been uploaded. When only part of a file is received, LibHTTP will delete that partly upload in the background and not inform the main application through this callback. The following parameters are provided in the function call:|
||**`path`** -| ||**`path`** -|
||**`file_size`** - The path on the server where the file was stored| ||**`file_size`** - The path on the server where the file was stored|
||**`user_data`** - The size of the stored file in bytes| ||**`user_data`** - The size of the stored file in bytes|

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_get_builtin_mime_type( file_name );` ### `mg_get_builtin_mime_type( file_name );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_get_context( conn );` ### `mg_get_context( conn );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_get_cookie( cookie, var_name, buf, buf_len );` ### `mg_get_cookie( cookie, var_name, buf, buf_len );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_get_header( conn, name );` ### `mg_get_header( conn, name );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_get_option( ctx, name );` ### `mg_get_option( ctx, name );`
@@ -17,7 +17,7 @@
### Description ### Description
When starting the CivetWeb webserver, options are provided to set the wanted behaviour of the server. The options which were used during startup can be queried through the `mg_get_option()` function. Options are read-only and cannot be changed while the webserver is running. The function returns a pointer to a text string containing the value of the queried option, or NULL if an error occured. It is guaranteed however that if a valid option name is provided as a parameter to this function, that a pointer to a string is returned and not NULL. In case an option was empty or NULL during initialisation, `mg_get_option()` will return a pointer to an empty string. When starting the LibHTTP webserver, options are provided to set the wanted behaviour of the server. The options which were used during startup can be queried through the `mg_get_option()` function. Options are read-only and cannot be changed while the webserver is running. The function returns a pointer to a text string containing the value of the queried option, or NULL if an error occured. It is guaranteed however that if a valid option name is provided as a parameter to this function, that a pointer to a string is returned and not NULL. In case an option was empty or NULL during initialisation, `mg_get_option()` will return a pointer to an empty string.
### See Also ### See Also

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### ~~`mg_get_ports( ctx, size, ports, ssl );`~~ ### ~~`mg_get_ports( ctx, size, ports, ssl );`~~
@@ -21,7 +21,7 @@
This function is deprecated. Use [`mg_get_server_ports()`](mg_get_server_ports.md) instead. This function is deprecated. Use [`mg_get_server_ports()`](mg_get_server_ports.md) instead.
The function `mg_get_ports()` returns a list of ports the Civetweb server is listening on. The port numbers are stored in a buffer of integers which is supplied by the calling party. The function also stores information if SSL is used on the ports. This information is stored in a second buffer which should be capable of storing the same amount of items as the ports buffer. The function `mg_get_ports()` returns a list of ports the LibHTTP server is listening on. The port numbers are stored in a buffer of integers which is supplied by the calling party. The function also stores information if SSL is used on the ports. This information is stored in a second buffer which should be capable of storing the same amount of items as the ports buffer.
The function returns the number of ports actually stored in the buffer. The function returns the number of ports actually stored in the buffer.

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_get_request_info( conn );` ### `mg_get_request_info( conn );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_get_response( conn, ebuf, ebuf_len, timeout );` ### `mg_get_response( conn, ebuf, ebuf_len, timeout );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_get_response_code_text( conn, response_code );` ### `mg_get_response_code_text( conn, response_code );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_get_server_ports( ctx, size, ports );` ### `mg_get_server_ports( ctx, size, ports );`
@@ -18,7 +18,7 @@
### Description ### Description
The `mg_get_server_ports()` returns a list with server ports on which the Civetweb server is listening. The ports are returned for a given context and stored with additional information like the SSL and redirection state in a list of structures. The list of structures must be allocated by the calling routine. The size of the structure is also passed to `mg_get_server_ports()`. The `mg_get_server_ports()` returns a list with server ports on which the LibHTTP server is listening. The ports are returned for a given context and stored with additional information like the SSL and redirection state in a list of structures. The list of structures must be allocated by the calling routine. The size of the structure is also passed to `mg_get_server_ports()`.
The function returns the number of items in the list, or a negative value if an error occured. The function returns the number of items in the list, or a negative value if an error occured.

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_get_user_connection_data( conn );` ### `mg_get_user_connection_data( conn );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_get_user_data( ctx );` ### `mg_get_user_data( ctx );`
@@ -16,7 +16,7 @@
### Description ### Description
The function `mg_get_user_data()` returns the user data associated with a Civetweb context. This is a pointer value which has previously been used in the call to [`mg_start()`](mg_start.md) to initialize the server context. The function `mg_get_user_data()` returns the user data associated with a LibHTTP context. This is a pointer value which has previously been used in the call to [`mg_start()`](mg_start.md) to initialize the server context.
### See Also ### See Also

View File

@@ -1,24 +0,0 @@
# Civetweb API Reference
### ~~`mg_get_valid_option_names();`~~
### Parameters
*none*
### Return Value
| Type | Description |
| :--- | :--- |
|`const char **`|An array with strings where the even elements represent the option names, and the odd element the option values The array is NULL terminated.|
### Description
The function `mg_get_valid_option_names()` is depricated. Use [`mg_get_valid_options()`](mg_get_valid_options.md) instead.
This function returns an array with option/value pairs describing the valid configuration options for Civetweb. En element value of NULL signals the end of the list.
### See Also
* [`struct mg_option;`](mg_option.md)
* [`mg_get_valid_options();`](mg_get_valid_options.md)

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_get_valid_options();` ### `mg_get_valid_options();`
@@ -14,7 +14,7 @@
### Description ### Description
The function `mg_get_valid_options()` returns an array with all valid configuration options of Civetweb. Each element in the array is a structure with three fields which represent the name of the option, the value of the option and the type of the value. The array is terminated with an element for which the name is `NULL`. See for more details about this structure the documentation of [`struct mg_option`](mg_option.md). The function `mg_get_valid_options()` returns an array with all valid configuration options of LibHTTP. Each element in the array is a structure with three fields which represent the name of the option, the value of the option and the type of the value. The array is terminated with an element for which the name is `NULL`. See for more details about this structure the documentation of [`struct mg_option`](mg_option.md).
### See Also ### See Also

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_get_var( data, data_len, var_name, dst, dst_len );` ### `mg_get_var( data, data_len, var_name, dst, dst_len );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_get_var2( data, data_len, var_name, dst, dst_len, occurrence );` ### `mg_get_var2( data, data_len, var_name, dst, dst_len, occurrence );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_handle_form_request( conn, fdh );` ### `mg_handle_form_request( conn, fdh );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `struct mg_header;` ### `struct mg_header;`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_lock_connection( conn );` ### `mg_lock_connection( conn );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_lock_context( ctx );` ### `mg_lock_context( ctx );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_md5( buf, ... );` ### `mg_md5( buf, ... );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_modify_passwords_file( passwords_file_name, domain, user, password );` ### `mg_modify_passwords_file( passwords_file_name, domain, user, password );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `struct mg_option;` ### `struct mg_option;`
@@ -12,7 +12,7 @@
### Description ### Description
A list of valid configuration options of the Civetweb instance can be retrieved with a call to [`mg_get_valid_options()`](mg_get_valid_options.md). This function fills a list of `struct mg_option` structures where the content of each structure represents a configuration option. Each structure contains three fields. One field contains the name of the option, the second contains the value of the option and the third is an identifier used to define the type of the option and how the value contents should be interpreted. A list of valid configuration options of the LibHTTP instance can be retrieved with a call to [`mg_get_valid_options()`](mg_get_valid_options.md). This function fills a list of `struct mg_option` structures where the content of each structure represents a configuration option. Each structure contains three fields. One field contains the name of the option, the second contains the value of the option and the third is an identifier used to define the type of the option and how the value contents should be interpreted.
The field `type` can be one of the following values: The field `type` can be one of the following values:

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_printf( conn, fmt, ... );` ### `mg_printf( conn, fmt, ... );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_read( conn, buf, len );` ### `mg_read( conn, buf, len );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `struct mg_request_info;` ### `struct mg_request_info;`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_send_file( conn, path );` ### `mg_send_file( conn, path );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_send_mime_file( conn, path, mime_type );` ### `mg_send_mime_file( conn, path, mime_type );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_send_mime_file2( conn, path, mime_type, additional_headers );` ### `mg_send_mime_file2( conn, path, mime_type, additional_headers );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `struct mg_server_ports;` ### `struct mg_server_ports;`
@@ -17,7 +17,7 @@
### Description ### Description
A call to the function [`mg_get_server_ports()`](mg_get_server_ports.md) returns a list of structures with information about each running Civetweb service. These structures are of type `struct mg_server_ports` and contain the base information of each service. A call to the function [`mg_get_server_ports()`](mg_get_server_ports.md) returns a list of structures with information about each running LibHTTP service. These structures are of type `struct mg_server_ports` and contain the base information of each service.
### See Also ### See Also

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_set_auth_handler( ctx, uri, handler, cbdata );` ### `mg_set_auth_handler( ctx, uri, handler, cbdata );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_set_request_handler( ctx, uri, handler, cbdata );` ### `mg_set_request_handler( ctx, uri, handler, cbdata );`
@@ -19,7 +19,7 @@
### Description ### Description
The function `mg_set_request_handler()` hooks a callback function on a URI. That callback function is called whenever a client requests the specific URI. The callback function receives the connection information and optional user supplied data as parameters and can serve information back to the client. When the callback function does not send any information back to the client, it should return **0** to signal Civetweb that the Civetweb core should handle the request. A return value between 1 and 999 is used to tell Civetweb that the request has been handled and no further processing is necessary. The returned code is stored as the status code in the access log, it is therefore recommended, although not mandatory to return a status code which matches the state of the request. The function `mg_set_request_handler()` hooks a callback function on a URI. That callback function is called whenever a client requests the specific URI. The callback function receives the connection information and optional user supplied data as parameters and can serve information back to the client. When the callback function does not send any information back to the client, it should return **0** to signal LibHTTP that the LibHTTP core should handle the request. A return value between 1 and 999 is used to tell LibHTTP that the request has been handled and no further processing is necessary. The returned code is stored as the status code in the access log, it is therefore recommended, although not mandatory to return a status code which matches the state of the request.
### See Also ### See Also

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_set_user_connection_data( conn, data );` ### `mg_set_user_connection_data( conn, data );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_set_websocket_handler( ctx, uri, connect_handler, ready_handler, data_handler, close_handler, cbdata );` ### `mg_set_websocket_handler( ctx, uri, connect_handler, ready_handler, data_handler, close_handler, cbdata );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_start( callbacks, user_data, options );` ### `mg_start( callbacks, user_data, options );`
@@ -15,9 +15,9 @@ The option list can be used to set the following options:
| Option | Default | Description | | Option | Default | Description |
| :--- | :--- | :--- | | :--- | :--- | :--- |
| **`cgi_environment`** | *empty* | The option `cgi_environment` can contain extra variables to be passed to the CGI script in addition to the standard environment variables. The lust must be a comma separated list of name=value pairs like this: `VARIABLE1=VALUE1,VARIABLE2=VALUE2`.| | **`cgi_environment`** | *empty* | The option `cgi_environment` can contain extra variables to be passed to the CGI script in addition to the standard environment variables. The lust must be a comma separated list of name=value pairs like this: `VARIABLE1=VALUE1,VARIABLE2=VALUE2`.|
| **`cgi_interpreter`**| *empty* | The option `cgi_interpreter` can contain a path to an executable which will be used as a CGI interpreter for **all** CGI scripts regardless of the script file extension. If this option is not set (which is the default), CivetWeb looks at the first line of a CGI script to see if an interpreter is defined there. This first line is formatted as a shebang line as common in unix style shell scripts, but this will also work in Windows. For more information about the syntax, please see the Wikipedia page about the [shebang line](http://en.wikipedia.org/wiki/Shebang_(Unix\)).| | **`cgi_interpreter`**| *empty* | The option `cgi_interpreter` can contain a path to an executable which will be used as a CGI interpreter for **all** CGI scripts regardless of the script file extension. If this option is not set (which is the default), LibHTTP looks at the first line of a CGI script to see if an interpreter is defined there. This first line is formatted as a shebang line as common in unix style shell scripts, but this will also work in Windows. For more information about the syntax, please see the Wikipedia page about the [shebang line](http://en.wikipedia.org/wiki/Shebang_(Unix\)).|
| | |For example on a Windows system where both PHP and Perl CGI scripts are used, `#!/path/to/php-cgi.exe` and `#!/path/to/perl.exe` must be the first line of the respective CGI scripts. Note that the paths should be either full file paths, or file paths relative to the current working directory of the CivetWeb server. The current working directory may be dependent on the way the application is started. When started from the command line it is the directory from where the executable was called, but when starting it from a shortcut in a graphical desktop environment, it will be the directory where the executable is located, the default directory of the user or a directory mentioned in the shortcut, depending on the operating system and graphical user interface used.| | | |For example on a Windows system where both PHP and Perl CGI scripts are used, `#!/path/to/php-cgi.exe` and `#!/path/to/perl.exe` must be the first line of the respective CGI scripts. Note that the paths should be either full file paths, or file paths relative to the current working directory of the LibHTTP server. The current working directory may be dependent on the way the application is started. When started from the command line it is the directory from where the executable was called, but when starting it from a shortcut in a graphical desktop environment, it will be the directory where the executable is located, the default directory of the user or a directory mentioned in the shortcut, depending on the operating system and graphical user interface used.|
| | |If all CGIs use the same interpreter, it is more efficient to set the option `cgi_interpreter` to the path to that executable because in that case no processing of the shebang line is necessary. When using PHP, be sure to point tot php-cgi(.exe) and not the php(.exe) executable, as the latter is a stand alone interpreter which doesn't interface over CGI with CivetWeb. | | |If all CGIs use the same interpreter, it is more efficient to set the option `cgi_interpreter` to the path to that executable because in that case no processing of the shebang line is necessary. When using PHP, be sure to point tot php-cgi(.exe) and not the php(.exe) executable, as the latter is a stand alone interpreter which doesn't interface over CGI with LibHTTP.
| **`cgi_pattern`** | `**.cgi$|**.pl$|**.php$` | All files that match `cgi_pattern` are treated as CGI files. The default pattern allows CGI files to be anywhere. To restrict CGIs to a certain directory, use `/path/to/cgi-bin/**.cgi` as a pattern. Note that the full path of the local file is matched against the pattern, not the URI provided in the client request.| | **`cgi_pattern`** | `**.cgi$|**.pl$|**.php$` | All files that match `cgi_pattern` are treated as CGI files. The default pattern allows CGI files to be anywhere. To restrict CGIs to a certain directory, use `/path/to/cgi-bin/**.cgi` as a pattern. Note that the full path of the local file is matched against the pattern, not the URI provided in the client request.|
|**`put_delete_auth_file`**| *empty* | The option `put_delete_auth_file` defines the password file to be used for PUT and DELETE requests. Without a password file it is not possible to put new files to the server, or to delete existing ones. This only applies to direct HTTP requests which use the PUT and DELETE methods without server side scripting. PUT and DELETE requests might still be handled by Lua scripts and CGI pages. | |**`put_delete_auth_file`**| *empty* | The option `put_delete_auth_file` defines the password file to be used for PUT and DELETE requests. Without a password file it is not possible to put new files to the server, or to delete existing ones. This only applies to direct HTTP requests which use the PUT and DELETE methods without server side scripting. PUT and DELETE requests might still be handled by Lua scripts and CGI pages. |

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_start_thread( func, cbdata );` ### `mg_start_thread( func, cbdata );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_stop( ctx );` ### `mg_stop( ctx );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_store_body( conn, path );` ### `mg_store_body( conn, path );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_strcasecmp( s1, s2 );` ### `mg_strcasecmp( s1, s2 );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_strncasecmp( s1, s2, len );` ### `mg_strncasecmp( s1, s2, len );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # Libhttp API Reference
### `mg_unlock_connection( conn );` ### `mg_unlock_connection( conn );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_unlock_context( ctx );` ### `mg_unlock_context( ctx );`

View File

@@ -1,22 +0,0 @@
# Civetweb API Reference
### ~~`mg_upload( conn, destination_dir );`~~
### Parameters
| Parameter | Type | Description |
| :--- | :--- | :--- |
|**`conn`**|`struct mg_connection *`|Connection on which files to upload|
|**`destination_dir`**|`const char *`|The destination directory to upload to|
### Return Value
| Type | Description |
| :--- | :--- |
|`int`|Success or error code|
### Description
The function `mg_upload()` is deprecated and may be removed from future releases. Use of this function is therefore highly discouraged.
### See Also

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_url_decode( src, src_len, dst, dst_len, is_form_url_encoded );` ### `mg_url_decode( src, src_len, dst, dst_len, is_form_url_encoded );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_url_encode( src, dst, des_len );` ### `mg_url_encode( src, dst, des_len );`

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_version();` ### `mg_version();`
@@ -10,10 +10,10 @@
| Type | Description | | Type | Description |
| :--- | :--- | | :--- | :--- |
|`const char *`| A pointer to a text with the current CivetWeb version | |`const char *`| A pointer to a text with the current LibHTTP version |
### Description ### Description
The function `mg_version()` can be used to return the current CivetWeb version. The function returns a pointer to a string with the current major and minor version number separated with a dot, for example "1.9". The function `mg_version()` can be used to return the current LibHTTP version. The function returns a pointer to a string with the current major and minor version number separated with a dot, for example "1.9".
### See Also ### See Also

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_websocket_client_write( conn, opcode, data, data_len );` ### `mg_websocket_client_write( conn, opcode, data, data_len );`
@@ -19,7 +19,7 @@
### Description ### Description
The function `mg_websocket_client_write()` sends data to a websocket server wrapped in a masked websocket frame. The function issues calls to [`mg_lock_connection()`](mg_lock_connection.md) and [`mg_unlock_connection()`](mg_unlock_connection.md) to ensure that the transmission is not interrupted. Interruption can happen the the application is proactively communicating and responding to a request simultaneously. This function is available only, if Civetweb is compiled with the option `-DUSE_WEBSOCKET`. The function `mg_websocket_client_write()` sends data to a websocket server wrapped in a masked websocket frame. The function issues calls to [`mg_lock_connection()`](mg_lock_connection.md) and [`mg_unlock_connection()`](mg_unlock_connection.md) to ensure that the transmission is not interrupted. Interruption can happen the the application is proactively communicating and responding to a request simultaneously. This function is available only, if LibHTTP is compiled with the option `-DUSE_WEBSOCKET`.
The return value is the number of bytes written on success, **0** when the connection has been closed and **-1** if an error occured. The return value is the number of bytes written on success, **0** when the connection has been closed and **-1** if an error occured.

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_websocket_write( conn, opcode, data, data_len );` ### `mg_websocket_write( conn, opcode, data, data_len );`
@@ -21,7 +21,7 @@
The function `mg_websocket_write()` sends data to a websocket client wrapped in a websocket frame. The function issues calls to [`mg_lock_connection()`](mg_lock_connection.md) and [`mg_unlock_connaction()`](mg_unlock_connection.md) to ensure that the transmission is not interrupted. Data corruption can otherwise happn if the application is proactively communicating and responding to a request simultaneously. The function `mg_websocket_write()` sends data to a websocket client wrapped in a websocket frame. The function issues calls to [`mg_lock_connection()`](mg_lock_connection.md) and [`mg_unlock_connaction()`](mg_unlock_connection.md) to ensure that the transmission is not interrupted. Data corruption can otherwise happn if the application is proactively communicating and responding to a request simultaneously.
The function is available only when Civetweb is compilet with the `-DUSE_WEBSOCKET` option. The function is available only when LibHTTP is compiled with the `-DUSE_WEBSOCKET` option.
The function returns the number of bytes written, **0** when the connection has been closed and **-1** if an error occured. The function returns the number of bytes written, **0** when the connection has been closed and **-1** if an error occured.

View File

@@ -1,4 +1,4 @@
# Civetweb API Reference # LibHTTP API Reference
### `mg_write( conn, buf, len );` ### `mg_write( conn, buf, len );`

View File

@@ -1,12 +1,12 @@
Adding wolfSSL (formerly CyaSSL) support Adding wolfSSL (formerly CyaSSL) support
===== =====
In order to support SSL *HTTPS* connections in Civetweb, In order to support SSL *HTTPS* connections in LibHTTP,
you may wish to use the GPLv2 licensed CyaSSL library. By using this you may wish to use the GPLv2 licensed CyaSSL library. By using this
library, the resulting binary may have to have the GPL license unless library, the resulting binary may have to have the GPL license unless
you buy a commercial license from [wolfSSL](http://www.yassl.com/). you buy a commercial license from [wolfSSL](http://www.yassl.com/).
*Note: The following instructions have not been checked for the most recent versions of CivetWeb and wolfSSL. Some information might be outdated.* *Note: The following instructions have not been checked for the most recent versions of LibHTTP and wolfSSL. Some information might be outdated.*
Getting Started Getting Started
@@ -14,20 +14,20 @@ Getting Started
- Download Cayssl at https://www.wolfssl.com (formerly http://www.yassl.com/) - Download Cayssl at https://www.wolfssl.com (formerly http://www.yassl.com/)
- Extract the zip file - Extract the zip file
- To make this seemless, extract to a directory parallel to with Civetweb is - To make this seemless, extract to a directory parallel to with LibHTTP is
### Example Project ### Example Project
If you download cyaSSL to cyassl-2.7.0 in a directory parallel to Civetweb, you can open the *VS/civetweb_yassl* solution in Visual Studio. If you download cyaSSL to cyassl-2.7.0 in a directory parallel to LibHTTP, you can open the *VS/libhttp_yassl* solution in Visual Studio.
Build Configuration Build Configuration
---- ----
#### Required include paths for both civetweb and cyassl #### Required include paths for both LibHTTP and cyassl
- *cyassl_directory*\ - *cyassl_directory*\
- *cyassl_directory*\cyassl\ - *cyassl_directory*\cyassl\
#### Required civetweb preprocessor defines #### Required LibHTTP preprocessor defines
- USE_YASSL - USE_YASSL
- NO_SSL_DL - NO_SSL_DL

View File

@@ -1,4 +1,6 @@
/* Copyright (c) 2013-2014 the Civetweb developers /*
* Copyright (c) 2016 Lammert Bies
* Copyright (c) 2013-2014 the Civetweb developers
* Copyright (c) 2013 No Face Press, LLC * Copyright (c) 2013 No Face Press, LLC
* *
* License http://opensource.org/licenses/mit-license.php MIT License * License http://opensource.org/licenses/mit-license.php MIT License
@@ -8,22 +10,22 @@
#define _CIVETWEB_SERVER_H_ #define _CIVETWEB_SERVER_H_
#ifdef __cplusplus #ifdef __cplusplus
#include "civetweb.h" #include "libhttp.h"
#include <map> #include <map>
#include <string> #include <string>
#include <vector> #include <vector>
#include <stdexcept> #include <stdexcept>
// forward declaration // forward declaration
class CivetServer; class LibHTTPServer;
/** /**
* Exception class for thrown exceptions within the CivetHandler object. * Exception class for thrown exceptions within the LibHTTPHandler object.
*/ */
class CIVETWEB_API CivetException : public std::runtime_error class CIVETWEB_API LibHTTPException : public std::runtime_error
{ {
public: public:
CivetException(const std::string &msg) : std::runtime_error(msg) LibHTTPException(const std::string &msg) : std::runtime_error(msg)
{ {
} }
}; };
@@ -32,13 +34,13 @@ class CIVETWEB_API CivetException : public std::runtime_error
* Basic interface for a URI request handler. Handlers implementations * Basic interface for a URI request handler. Handlers implementations
* must be reentrant. * must be reentrant.
*/ */
class CIVETWEB_API CivetHandler class CIVETWEB_API LibHTTPHandler
{ {
public: public:
/** /**
* Destructor * Destructor
*/ */
virtual ~CivetHandler() virtual ~LibHTTPHandler()
{ {
} }
@@ -49,7 +51,7 @@ class CIVETWEB_API CivetHandler
* @param conn - the connection information * @param conn - the connection information
* @returns true if implemented, false otherwise * @returns true if implemented, false otherwise
*/ */
virtual bool handleGet(CivetServer *server, struct mg_connection *conn); virtual bool handleGet(LibHTTPServer *server, struct mg_connection *conn);
/** /**
* Callback method for POST request. * Callback method for POST request.
@@ -58,7 +60,7 @@ class CIVETWEB_API CivetHandler
* @param conn - the connection information * @param conn - the connection information
* @returns true if implemented, false otherwise * @returns true if implemented, false otherwise
*/ */
virtual bool handlePost(CivetServer *server, struct mg_connection *conn); virtual bool handlePost(LibHTTPServer *server, struct mg_connection *conn);
/** /**
* Callback method for HEAD request. * Callback method for HEAD request.
@@ -67,7 +69,7 @@ class CIVETWEB_API CivetHandler
* @param conn - the connection information * @param conn - the connection information
* @returns true if implemented, false otherwise * @returns true if implemented, false otherwise
*/ */
virtual bool handleHead(CivetServer *server, struct mg_connection *conn); virtual bool handleHead(LibHTTPServer *server, struct mg_connection *conn);
/** /**
* Callback method for PUT request. * Callback method for PUT request.
@@ -76,7 +78,7 @@ class CIVETWEB_API CivetHandler
* @param conn - the connection information * @param conn - the connection information
* @returns true if implemented, false otherwise * @returns true if implemented, false otherwise
*/ */
virtual bool handlePut(CivetServer *server, struct mg_connection *conn); virtual bool handlePut(LibHTTPServer *server, struct mg_connection *conn);
/** /**
* Callback method for DELETE request. * Callback method for DELETE request.
@@ -85,7 +87,7 @@ class CIVETWEB_API CivetHandler
* @param conn - the connection information * @param conn - the connection information
* @returns true if implemented, false otherwise * @returns true if implemented, false otherwise
*/ */
virtual bool handleDelete(CivetServer *server, struct mg_connection *conn); virtual bool handleDelete(LibHTTPServer *server, struct mg_connection *conn);
/** /**
* Callback method for OPTIONS request. * Callback method for OPTIONS request.
@@ -94,7 +96,7 @@ class CIVETWEB_API CivetHandler
* @param conn - the connection information * @param conn - the connection information
* @returns true if implemented, false otherwise * @returns true if implemented, false otherwise
*/ */
virtual bool handleOptions(CivetServer *server, struct mg_connection *conn); virtual bool handleOptions(LibHTTPServer *server, struct mg_connection *conn);
/** /**
* Callback method for PATCH request. * Callback method for PATCH request.
@@ -103,20 +105,20 @@ class CIVETWEB_API CivetHandler
* @param conn - the connection information * @param conn - the connection information
* @returns true if implemented, false otherwise * @returns true if implemented, false otherwise
*/ */
virtual bool handlePatch(CivetServer *server, struct mg_connection *conn); virtual bool handlePatch(LibHTTPServer *server, struct mg_connection *conn);
}; };
/** /**
* Basic interface for a URI authorization handler. Handler implementations * Basic interface for a URI authorization handler. Handler implementations
* must be reentrant. * must be reentrant.
*/ */
class CIVETWEB_API CivetAuthHandler class CIVETWEB_API LibHTTPAuthHandler
{ {
public: public:
/** /**
* Destructor * Destructor
*/ */
virtual ~CivetAuthHandler() virtual ~LibHTTPAuthHandler()
{ {
} }
@@ -128,20 +130,20 @@ class CIVETWEB_API CivetAuthHandler
* @param conn - the connection information * @param conn - the connection information
* @returns true if authorization succeeded, false otherwise * @returns true if authorization succeeded, false otherwise
*/ */
virtual bool authorize(CivetServer *server, struct mg_connection *conn) = 0; virtual bool authorize(LibHTTPServer *server, struct mg_connection *conn) = 0;
}; };
/** /**
* Basic interface for a websocket handler. Handlers implementations * Basic interface for a websocket handler. Handlers implementations
* must be reentrant. * must be reentrant.
*/ */
class CIVETWEB_API CivetWebSocketHandler class CIVETWEB_API LibHTTPWebSocketHandler
{ {
public: public:
/** /**
* Destructor * Destructor
*/ */
virtual ~CivetWebSocketHandler() virtual ~LibHTTPWebSocketHandler()
{ {
} }
@@ -153,7 +155,7 @@ class CIVETWEB_API CivetWebSocketHandler
* @param conn - the connection information * @param conn - the connection information
* @returns true to keep socket open, false to close it * @returns true to keep socket open, false to close it
*/ */
virtual bool handleConnection(CivetServer *server, virtual bool handleConnection(LibHTTPServer *server,
const struct mg_connection *conn); const struct mg_connection *conn);
/** /**
@@ -163,7 +165,7 @@ class CIVETWEB_API CivetWebSocketHandler
* @param server - the calling server * @param server - the calling server
* @param conn - the connection information * @param conn - the connection information
*/ */
virtual void handleReadyState(CivetServer *server, virtual void handleReadyState(LibHTTPServer *server,
struct mg_connection *conn); struct mg_connection *conn);
/** /**
@@ -176,7 +178,7 @@ class CIVETWEB_API CivetWebSocketHandler
* @data, data_len: payload, with mask (if any) already applied. * @data, data_len: payload, with mask (if any) already applied.
* @returns true to keep socket open, false to close it * @returns true to keep socket open, false to close it
*/ */
virtual bool handleData(CivetServer *server, virtual bool handleData(LibHTTPServer *server,
struct mg_connection *conn, struct mg_connection *conn,
int bits, int bits,
char *data, char *data,
@@ -188,25 +190,25 @@ class CIVETWEB_API CivetWebSocketHandler
* @param server - the calling server * @param server - the calling server
* @param conn - the connection information * @param conn - the connection information
*/ */
virtual void handleClose(CivetServer *server, virtual void handleClose(LibHTTPServer *server,
const struct mg_connection *conn); const struct mg_connection *conn);
}; };
/** /**
* CivetCallbacks * LibHTTPCallbacks
* *
* wrapper for mg_callbacks * wrapper for mg_callbacks
*/ */
struct CIVETWEB_API CivetCallbacks : public mg_callbacks { struct CIVETWEB_API LibHTTPCallbacks : public mg_callbacks {
CivetCallbacks(); LiBHTTPCallbacks();
}; };
/** /**
* CivetServer * LibHTTPServer
* *
* Basic class for embedded web server. This has an URL mapping built-in. * Basic class for embedded web server. This has an URL mapping built-in.
*/ */
class CIVETWEB_API CivetServer class CIVETWEB_API LibHTTPServer
{ {
public: public:
/** /**
@@ -216,7 +218,7 @@ class CIVETWEB_API CivetServer
* It is good practice to call getContext() after this in case there * It is good practice to call getContext() after this in case there
* were errors starting the server. * were errors starting the server.
* *
* Note: CivetServer should not be used as a static instance in a Windows * Note: LibHTTPServer should not be used as a static instance in a Windows
* DLL, since the constructor creates threads and the destructor joins * DLL, since the constructor creates threads and the destructor joins
* them again (creating/joining threads should not be done in static * them again (creating/joining threads should not be done in static
* constructors). * constructors).
@@ -224,17 +226,17 @@ class CIVETWEB_API CivetServer
* @param options - the web server options. * @param options - the web server options.
* @param callbacks - optional web server callback methods. * @param callbacks - optional web server callback methods.
* *
* @throws CivetException * @throws LibHTTPException
*/ */
CivetServer(const char **options, LibHTTPServer(const char **options,
const struct CivetCallbacks *callbacks = 0); const struct LibHTTPCallbacks *callbacks = 0);
CivetServer(std::vector<std::string> options, LibHTTPServer(std::vector<std::string> options,
const struct CivetCallbacks *callbacks = 0); const struct LibHTTPCallbacks *callbacks = 0);
/** /**
* Destructor * Destructor
*/ */
virtual ~CivetServer(); virtual ~LibHTTPServer();
/** /**
* close() * close()
@@ -255,7 +257,7 @@ class CIVETWEB_API CivetServer
} }
/** /**
* addHandler(const std::string &, CivetHandler *) * addHandler(const std::string &, LibHTTPHandler *)
* *
* Adds a URI handler. If there is existing URI handler, it will * Adds a URI handler. If there is existing URI handler, it will
* be replaced with this one. * be replaced with this one.
@@ -265,10 +267,10 @@ class CIVETWEB_API CivetServer
* @param uri - URI to match. * @param uri - URI to match.
* @param handler - handler instance to use. * @param handler - handler instance to use.
*/ */
void addHandler(const std::string &uri, CivetHandler *handler); void addHandler(const std::string &uri, LibHTTPHandler *handler);
void void
addHandler(const std::string &uri, CivetHandler &handler) addHandler(const std::string &uri, LibHTTPHandler &handler)
{ {
addHandler(uri, &handler); addHandler(uri, &handler);
} }
@@ -286,10 +288,10 @@ class CIVETWEB_API CivetServer
* @param handler - handler instance to use. * @param handler - handler instance to use.
*/ */
void addWebSocketHandler(const std::string &uri, void addWebSocketHandler(const std::string &uri,
CivetWebSocketHandler *handler); LibHTTPWebSocketHandler *handler);
void void
addWebSocketHandler(const std::string &uri, CivetWebSocketHandler &handler) addWebSocketHandler(const std::string &uri, LibHTTPWebSocketHandler &handler)
{ {
addWebSocketHandler(uri, &handler); addWebSocketHandler(uri, &handler);
} }
@@ -313,7 +315,7 @@ class CIVETWEB_API CivetServer
void removeWebSocketHandler(const std::string &uri); void removeWebSocketHandler(const std::string &uri);
/** /**
* addAuthHandler(const std::string &, CivetAuthHandler *) * addAuthHandler(const std::string &, LibHTTPAuthHandler *)
* *
* Adds a URI authorization handler. If there is existing URI authorization * Adds a URI authorization handler. If there is existing URI authorization
* handler, it will be replaced with this one. * handler, it will be replaced with this one.
@@ -323,10 +325,10 @@ class CIVETWEB_API CivetServer
* @param uri - URI to match. * @param uri - URI to match.
* @param handler - authorization handler instance to use. * @param handler - authorization handler instance to use.
*/ */
void addAuthHandler(const std::string &uri, CivetAuthHandler *handler); void addAuthHandler(const std::string &uri, LibHTTPAuthHandler *handler);
void void
addAuthHandler(const std::string &uri, CivetAuthHandler &handler) addAuthHandler(const std::string &uri, LibHTTPAuthHandler &handler)
{ {
addAuthHandler(uri, &handler); addAuthHandler(uri, &handler);
} }
@@ -532,18 +534,18 @@ class CIVETWEB_API CivetServer
bool append = false); bool append = false);
protected: protected:
class CivetConnection class LibHTTPConnection
{ {
public: public:
char *postData; char *postData;
unsigned long postDataLen; unsigned long postDataLen;
CivetConnection(); LibHTTPConnection();
~CivetConnection(); ~LibHTTPConnection();
}; };
struct mg_context *context; struct mg_context *context;
std::map<struct mg_connection *, class CivetConnection> connections; std::map<struct mg_connection *, class LibHTTPConnection> connections;
private: private:
/** /**
@@ -552,7 +554,7 @@ class CIVETWEB_API CivetServer
* Handles the incomming request. * Handles the incomming request.
* *
* @param conn - the connection information * @param conn - the connection information
* @param cbdata - pointer to the CivetHandler instance. * @param cbdata - pointer to the LibHTTPHandler instance.
* @returns 0 if implemented, false otherwise * @returns 0 if implemented, false otherwise
*/ */
static int requestHandler(struct mg_connection *conn, void *cbdata); static int requestHandler(struct mg_connection *conn, void *cbdata);
@@ -573,7 +575,7 @@ class CIVETWEB_API CivetServer
* Handles the authorization requests. * Handles the authorization requests.
* *
* @param conn - the connection information * @param conn - the connection information
* @param cbdata - pointer to the CivetAuthHandler instance. * @param cbdata - pointer to the LibHTTPAuthHandler instance.
* @returns 1 if authorized, 0 otherwise * @returns 1 if authorized, 0 otherwise
*/ */
static int authHandler(struct mg_connection *conn, void *cbdata); static int authHandler(struct mg_connection *conn, void *cbdata);

View File

@@ -1,4 +1,6 @@
/* Copyright (c) 2013-2016 the Civetweb developers /*
* Copyright (C) 2016 Lammert Bies
* Copyright (c) 2013-2016 the Civetweb developers
* Copyright (c) 2004-2013 Sergey Lyubka * Copyright (c) 2004-2013 Sergey Lyubka
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -95,47 +97,47 @@ struct client_cert {
}; };
/* This structure needs to be passed to mg_start(), to let civetweb know /* This structure needs to be passed to mg_start(), to let LibHTTP know
which callbacks to invoke. For a detailed description, see which callbacks to invoke. For a detailed description, see
https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md */ https://github.com/lammertb/libhttp/blob/master/docs/UserManual.md */
struct mg_callbacks { struct mg_callbacks {
/* Called when civetweb has received new HTTP request. /* Called when LibHTTP has received new HTTP request.
If the callback returns one, it must process the request If the callback returns one, it must process the request
by sending valid HTTP headers and a body. Civetweb will not do by sending valid HTTP headers and a body. LibHTTP will not do
any further processing. Otherwise it must return zero. any further processing. Otherwise it must return zero.
Note that since V1.7 the "begin_request" function is called Note that since V1.7 the "begin_request" function is called
before an authorization check. If an authorization check is before an authorization check. If an authorization check is
required, use a request_handler instead. required, use a request_handler instead.
Return value: Return value:
0: civetweb will process the request itself. In this case, 0: LibHTTP will process the request itself. In this case,
the callback must not send any data to the client. the callback must not send any data to the client.
1-999: callback already processed the request. Civetweb will 1-999: callback already processed the request. LibHTTP will
not send any data after the callback returned. The not send any data after the callback returned. The
return code is stored as a HTTP status code for the return code is stored as a HTTP status code for the
access log. */ access log. */
int (*begin_request)(struct mg_connection *); int (*begin_request)(struct mg_connection *);
/* Called when civetweb has finished processing request. */ /* Called when LibHTTP has finished processing request. */
void (*end_request)(const struct mg_connection *, int reply_status_code); void (*end_request)(const struct mg_connection *, int reply_status_code);
/* Called when civetweb is about to log a message. If callback returns /* Called when LibHTTP is about to log a message. If callback returns
non-zero, civetweb does not log anything. */ non-zero, LibHTTP does not log anything. */
int (*log_message)(const struct mg_connection *, const char *message); int (*log_message)(const struct mg_connection *, const char *message);
/* Called when civetweb is about to log access. If callback returns /* Called when LibHTTP is about to log access. If callback returns
non-zero, civetweb does not log anything. */ non-zero, LibHTTP does not log anything. */
int (*log_access)(const struct mg_connection *, const char *message); int (*log_access)(const struct mg_connection *, const char *message);
/* Called when civetweb initializes SSL library. /* Called when LibHTTP initializes SSL library.
Parameters: Parameters:
user_data: parameter user_data passed when starting the server. user_data: parameter user_data passed when starting the server.
Return value: Return value:
0: civetweb will set up the SSL certificate. 0: LibHTTP will set up the SSL certificate.
1: civetweb assumes the callback already set up the certificate. 1: LibHTTP assumes the callback already set up the certificate.
-1: initializing ssl fails. */ -1: initializing ssl fails. */
int (*init_ssl)(void *ssl_context, void *user_data); int (*init_ssl)(void *ssl_context, void *user_data);
/* Called when civetweb is closing a connection. The per-context mutex is /* Called when LibHTTP is closing a connection. The per-context mutex is
locked when this is invoked. This is primarily useful for noting when locked when this is invoked. This is primarily useful for noting when
a websocket is closing and removing it from any application-maintained a websocket is closing and removing it from any application-maintained
list of clients. list of clients.
@@ -143,7 +145,7 @@ struct mg_callbacks {
mg_set_websocket_handler instead. */ mg_set_websocket_handler instead. */
void (*connection_close)(const struct mg_connection *); void (*connection_close)(const struct mg_connection *);
/* Called when civetweb tries to open a file. Used to intercept file open /* Called when LibHTTP tries to open a file. Used to intercept file open
calls, and serve file data from memory instead. calls, and serve file data from memory instead.
Parameters: Parameters:
path: Full path to the file to open. path: Full path to the file to open.
@@ -157,22 +159,22 @@ struct mg_callbacks {
const char *path, const char *path,
size_t *data_len); size_t *data_len);
/* Called when civetweb is about to serve Lua server page, if /* Called when LibHTTP is about to serve Lua server page, if
Lua support is enabled. Lua support is enabled.
Parameters: Parameters:
lua_context: "lua_State *" pointer. */ lua_context: "lua_State *" pointer. */
void (*init_lua)(const struct mg_connection *, void *lua_context); void (*init_lua)(const struct mg_connection *, void *lua_context);
/* Called when civetweb is about to send HTTP error to the client. /* Called when LibHTTP is about to send HTTP error to the client.
Implementing this callback allows to create custom error pages. Implementing this callback allows to create custom error pages.
Parameters: Parameters:
status: HTTP error status code. status: HTTP error status code.
Return value: Return value:
1: run civetweb error handler. 1: run LibHTTP error handler.
0: callback already handled the error. */ 0: callback already handled the error. */
int (*http_error)(struct mg_connection *, int status); int (*http_error)(struct mg_connection *, int status);
/* Called after civetweb context has been created, before requests /* Called after LibHTTP context has been created, before requests
are processed. are processed.
Parameters: Parameters:
ctx: context handle */ ctx: context handle */
@@ -188,7 +190,7 @@ struct mg_callbacks {
*/ */
void (*init_thread)(const struct mg_context *ctx, int thread_type); void (*init_thread)(const struct mg_context *ctx, int thread_type);
/* Called when civetweb context is deleted. /* Called when LibHTTP context is deleted.
Parameters: Parameters:
ctx: context handle */ ctx: context handle */
void (*exit_context)(const struct mg_context *ctx); void (*exit_context)(const struct mg_context *ctx);
@@ -200,7 +202,7 @@ struct mg_callbacks {
Parameters: Parameters:
callbacks: mg_callbacks structure with user-defined callbacks. callbacks: mg_callbacks structure with user-defined callbacks.
options: NULL terminated list of option_name, option_value pairs that options: NULL terminated list of option_name, option_value pairs that
specify Civetweb configuration parameters. specify LibHTTP configuration parameters.
Side-effects: on UNIX, ignores SIGCHLD and SIGPIPE signals. If custom Side-effects: on UNIX, ignores SIGCHLD and SIGPIPE signals. If custom
processing is required for these, signal handlers must be set up processing is required for these, signal handlers must be set up
@@ -215,7 +217,7 @@ struct mg_callbacks {
}; };
struct mg_context *ctx = mg_start(&my_func, NULL, options); struct mg_context *ctx = mg_start(&my_func, NULL, options);
Refer to https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md Refer to https://github.com/lammertb/libhttp/blob/master/docs/UserManual.md
for the list of valid option and their possible values. for the list of valid option and their possible values.
Return: Return:
@@ -228,7 +230,7 @@ CIVETWEB_API struct mg_context *mg_start(const struct mg_callbacks *callbacks,
/* Stop the web server. /* Stop the web server.
Must be called last, when an application wants to stop the web server and Must be called last, when an application wants to stop the web server and
release all associated resources. This function blocks until all Civetweb release all associated resources. This function blocks until all LibHTTP
threads are stopped. Context pointer becomes invalid. */ threads are stopped. Context pointer becomes invalid. */
CIVETWEB_API void mg_stop(struct mg_context *); CIVETWEB_API void mg_stop(struct mg_context *);
@@ -281,7 +283,7 @@ CIVETWEB_API void mg_set_request_handler(struct mg_context *ctx,
Is called when the client intends to establish a websocket connection, Is called when the client intends to establish a websocket connection,
before websocket handshake. before websocket handshake.
Return value: Return value:
0: civetweb proceeds with websocket handshake. 0: LibHTTP proceeds with websocket handshake.
1: connection is closed immediately. 1: connection is closed immediately.
mg_websocket_ready_handler mg_websocket_ready_handler
@@ -352,7 +354,7 @@ CIVETWEB_API void mg_set_auth_handler(struct mg_context *ctx,
/* Get the value of particular configuration parameter. /* Get the value of particular configuration parameter.
The value returned is read-only. Civetweb does not allow changing The value returned is read-only. LibHTTP does not allow changing
configuration at run time. configuration at run time.
If given parameter name is not valid, NULL is returned. For valid If given parameter name is not valid, NULL is returned. For valid
names, return value is guaranteed to be non-NULL. If parameter is not names, return value is guaranteed to be non-NULL. If parameter is not
@@ -399,7 +401,7 @@ enum {
/* Return array of struct mg_option, representing all valid configuration /* Return array of struct mg_option, representing all valid configuration
options of civetweb.c. options of libhttp.c.
The array is terminated by a NULL name option. */ The array is terminated by a NULL name option. */
CIVETWEB_API const struct mg_option *mg_get_valid_options(void); CIVETWEB_API const struct mg_option *mg_get_valid_options(void);
@@ -416,7 +418,7 @@ struct mg_server_ports {
}; };
/* Get the list of ports that civetweb is listening on. /* Get the list of ports that LibHTTP is listening on.
The parameter size is the size of the ports array in elements. The parameter size is the size of the ports array in elements.
The caller is responsibility to allocate the required memory. The caller is responsibility to allocate the required memory.
This function returns the number of struct mg_server_ports elements This function returns the number of struct mg_server_ports elements
@@ -468,7 +470,7 @@ CIVETWEB_API int mg_write(struct mg_connection *, const void *buf, size_t len);
a request simultaneously. a request simultaneously.
Send data to a websocket client wrapped in a websocket frame. Send data to a websocket client wrapped in a websocket frame.
This function is available when civetweb is compiled with -DUSE_WEBSOCKET This function is available when LibHTTP is compiled with -DUSE_WEBSOCKET
Return: Return:
0 when the connection has been closed 0 when the connection has been closed
@@ -486,7 +488,7 @@ CIVETWEB_API int mg_websocket_write(struct mg_connection *conn,
a request simultaneously. a request simultaneously.
Send data to a websocket server wrapped in a masked websocket frame. Send data to a websocket server wrapped in a masked websocket frame.
This function is available when civetweb is compiled with -DUSE_WEBSOCKET This function is available when LibHTTP is compiled with -DUSE_WEBSOCKET
Return: Return:
0 when the connection has been closed 0 when the connection has been closed
@@ -822,7 +824,7 @@ CIVETWEB_API const char *mg_get_response_code_text(struct mg_connection *conn,
int response_code); int response_code);
/* Return CivetWeb version. */ /* Return LibHTTP version. */
CIVETWEB_API const char *mg_version(void); CIVETWEB_API const char *mg_version(void);
@@ -956,7 +958,7 @@ CIVETWEB_API int mg_get_response(struct mg_connection *conn,
int timeout); int timeout);
/* Check which features where set when civetweb has been compiled. /* Check which features where set when LibHTTP has been compiled.
Parameters: Parameters:
feature: specifies which feature should be checked feature: specifies which feature should be checked
1 serve files (NO_FILES not set) 1 serve files (NO_FILES not set)

View File

@@ -1,291 +0,0 @@
# The C API library
add_library(c-library civetweb.c)
set_target_properties(c-library PROPERTIES
OUTPUT_NAME "civetweb"
VERSION ${CIVETWEB_VERSION}
SOVERSION ${CIVETWEB_VERSION}
)
if (BUILD_SHARED_LIBS)
target_compile_definitions(c-library PRIVATE CIVETWEB_DLL_EXPORTS)
endif()
target_include_directories(
c-library PUBLIC
${PROJECT_SOURCE_DIR}/include)
install(
TARGETS c-library
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
COMPONENT c-library)
install(FILES
${PROJECT_SOURCE_DIR}/include/civetweb.h
DESTINATION include
COMPONENT c-library)
# Need Windows sockets if available
find_package(WinSock)
if (WINSOCK_FOUND)
target_link_libraries(c-library WINSOCK::WINSOCK)
endif()
# We need threading
find_package(Threads)
target_link_libraries(c-library ${CMAKE_THREAD_LIBS_INIT})
# Need the realtime library if we're using timers
find_package(LibRt)
if (CIVETWEB_ENABLE_WEBSOCKETS AND CIVETWEB_ENABLE_LUA AND LIBRT_FOUND)
target_link_libraries(c-library LIBRT::LIBRT)
endif()
# We need to link OpenSSL if not dynamically loading
if (CIVETWEB_ENABLE_SLL AND NOT CIVETWEB_ENABLE_OPENSLL_DYNAMIC_LOADING)
find_package(OpenSSL)
target_link_libraries(c-library ${OPENSSL_LIBRARIES})
else()
find_package(LibDl)
if (LIBDL_FOUND)
target_link_libraries(c-library -ldl)
endif()
endif()
# If Lua support is needed we build some extra Lua libraries
if (CIVETWEB_ENABLE_LUA)
include(ExternalProject)
# 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()
# If Lua is static we must build it from source
if (NOT CIVETWEB_ENABLE_LUA_SHARED)
if (LINUX)
set(LUA_MAKE_TARGET linux)
elseif(DARWIN)
set(LUA_MAKE_TARGET macosx)
elseif(FREEBSD)
set(LUA_MAKE_TARGET freebsd)
elseif(WINDOWS)
set(LUA_MAKE_TARGET mingw)
elseif(UNIX)
set(LUA_MAKE_TARGET posix)
else()
set(LUA_MAKE_TARGET generic)
endif()
set(LUA_BUILD_COMMAND "${CMAKE_MAKE_PROGRAM};${LUA_MAKE_TARGET}")
if (BUILD_SHARED_LIBS)
set(LUA_BUILD_COMMAND "${LUA_BUILD_COMMAND};MYCFLAGS=-fPIC")
endif()
ExternalProject_Add(lua
URL "http://www.lua.org/ftp/lua-${CIVETWEB_LUA_VERSION}.tar.gz"
URL_MD5 ${CIVETWEB_LUA_MD5_HASH}
PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ${LUA_BUILD_COMMAND}
BUILD_IN_SOURCE 1
INSTALL_COMMAND make install "INSTALL_TOP=<INSTALL_DIR>"
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(lua INSTALL_DIR)
set(LUA_INSTALL_DIR ${INSTALL_DIR})
unset(INSTALL_DIR)
link_directories("${LUA_INSTALL_DIR}/lib")
include_directories("${LUA_INSTALL_DIR}/include")
set(LUA_LIBRARIES "${LUA_INSTALL_DIR}/lib/liblua.a")
add_dependencies(c-library lua)
else()
find_package(Lua)
endif()
# Lua Filesystem Support
string(REPLACE "." "_" LUA_FILESYSTEM_VERSION_UNDERSCORE ${CIVETWEB_LUA_FILESYSTEM_VERSION})
ExternalProject_Add(luafilesystem
URL "https://github.com/keplerproject/luafilesystem/archive/v_${LUA_FILESYSTEM_VERSION_UNDERSCORE}.tar.gz"
URL_MD5 ${CIVETWEB_LUA_FILESYSTEM_MD5_HASH}
PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
PATCH_COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/luafilesystem/CMakeLists.txt" <SOURCE_DIR>/CMakeLists.txt
CMAKE_ARGS
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
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(luafilesystem INSTALL_DIR)
set(LUA_FILESYSTEM_INSTALL_DIR ${INSTALL_DIR})
unset(INSTALL_DIR)
link_directories("${LUA_FILESYSTEM_INSTALL_DIR}/lib")
include_directories("${LUA_FILESYSTEM_INSTALL_DIR}/include")
set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_FILESYSTEM_INSTALL_DIR}/lib/libluafilesystem.a")
add_dependencies(c-library luafilesystem)
# Lua SQLite Support
if (${CIVETWEB_LUA_SQLITE_VERSION} VERSION_EQUAL "0.9.3")
set(LUA_SQLITE_FILENAME lsqlite3_fsl09w.zip)
elseif (${CIVETWEB_LUA_SQLITE_VERSION} VERSION_EQUAL "0.9.2")
set(LUA_SQLITE_FILENAME lsqlite3_fsl09v.zip)
elseif (${CIVETWEB_LUA_SQLITE_VERSION} VERSION_EQUAL "0.9.1")
set(LUA_SQLITE_FILENAME lsqlite3_fsl09t.zip)
else()
message(FATAL_ERROR "The Lua SQLite archive filename is unknown for version ${CIVETWEB_LUA_SQLITE_VERSION}")
endif()
ExternalProject_Add(luasqlite
URL "http://lua.sqlite.org/index.cgi/zip/${LUA_SQLITE_FILENAME}"
URL_MD5 ${CIVETWEB_LUA_SQLITE_MD5_HASH}
PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
PATCH_COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/luasqlite/CMakeLists.txt" <SOURCE_DIR>/CMakeLists.txt
CMAKE_ARGS
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
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(luasqlite INSTALL_DIR)
set(LUA_SQLITE_INSTALL_DIR ${INSTALL_DIR})
unset(INSTALL_DIR)
link_directories("${LUA_SQLITE_INSTALL_DIR}/lib")
set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_SQLITE_INSTALL_DIR}/lib/libluasqlite.a")
add_dependencies(c-library luasqlite)
# Lua XML Support
if (${CIVETWEB_LUA_XML_VERSION} VERSION_EQUAL "1.8.0")
set(LUA_XML_FILENAME LuaXML_130610.zip)
elseif (${CIVETWEB_LUA_XML_VERSION} VERSION_EQUAL "1.7.4")
set(LUA_XML_FILENAME LuaXML_101012.zip)
else()
message(FATAL_ERROR "The Lua XML archive filename is unknown for version ${CIVETWEB_LUA_XML_VERSION}")
endif()
ExternalProject_Add(luaxml
URL "http://viremo.eludi.net/LuaXML/${LUA_XML_FILENAME}"
URL_MD5 ${CIVETWEB_LUA_XML_MD5_HASH}
PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
PATCH_COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/luaxml/CMakeLists.txt" <SOURCE_DIR>/CMakeLists.txt
CMAKE_ARGS
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
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(luaxml INSTALL_DIR)
set(LUA_XML_INSTALL_DIR ${INSTALL_DIR})
unset(INSTALL_DIR)
link_directories("${LUA_XML_INSTALL_DIR}/lib")
set(LUA_LIBRARIES "${LUA_LIBRARIES};${LUA_XML_INSTALL_DIR}/lib/libluaxml.a")
add_dependencies(c-library luaxml)
# SQLite Support
string (REGEX MATCHALL "[0-9]+" SQLITE_VERSION_MATCHES ${CIVETWEB_SQLITE_VERSION})
list(GET SQLITE_VERSION_MATCHES 0 SQLITE_VERSION_MAJOR)
list(GET SQLITE_VERSION_MATCHES 1 SQLITE_VERSION_MINOR)
list(GET SQLITE_VERSION_MATCHES 2 SQLITE_VERSION_PATCH)
set(SQLITE_FILE_VERSION ${SQLITE_VERSION_MAJOR}0${SQLITE_VERSION_MINOR}0${SQLITE_VERSION_PATCH}00)
ExternalProject_Add(sqlite
URL "http://www.sqlite.org/2015/sqlite-amalgamation-${SQLITE_FILE_VERSION}.zip"
URL_MD5 ${CIVETWEB_SQLITE_MD5_HASH}
PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
PATCH_COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/sqlite/CMakeLists.txt" <SOURCE_DIR>/CMakeLists.txt
CMAKE_ARGS
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
"-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
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(sqlite INSTALL_DIR)
set(SQLITE_INSTALL_DIR ${INSTALL_DIR})
unset(INSTALL_DIR)
link_directories("${SQLITE_INSTALL_DIR}/lib")
include_directories("${SQLITE_INSTALL_DIR}/include")
set(LUA_LIBRARIES "${LUA_LIBRARIES};${SQLITE_INSTALL_DIR}/lib/libsqlite.a")
add_dependencies(c-library sqlite)
# Link all the Lua libraries
target_link_libraries(c-library ${LUA_LIBRARIES})
endif()
# The web server executable
add_executable(c-executable main.c)
set_target_properties(c-executable PROPERTIES
OUTPUT_NAME "civetweb"
)
install(
TARGETS c-executable
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
COMPONENT server)
if (BUILD_SHARED_LIBS)
target_compile_definitions(c-executable PRIVATE CIVETWEB_DLL_IMPORTS)
endif()
target_include_directories(
c-executable PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(c-executable c-library)
if (LIBRT_FOUND)
target_link_libraries(c-executable LIBRT::LIBRT)
endif()
if (CIVETWEB_ENABLE_LUA)
add_library(lua-library third_party/lfs.c third_party/lsqlite3.c third_party/LuaXML_lib.c third_party/sqlite3.c)
set_target_properties(lua-library PROPERTIES
OUTPUT_NAME "lua-library"
VERSION ${CIVETWEB_VERSION}
SOVERSION ${CIVETWEB_VERSION}
)
target_include_directories(
lua-library PUBLIC
${PROJECT_SOURCE_DIR}/src/third_party/lua-5.2.4)
install(
TARGETS lua-library
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
COMPONENT lua-library)
endif()
# The C++ API library
if (CIVETWEB_ENABLE_CXX)
add_library(cxx-library CivetServer.cpp)
set_target_properties(cxx-library PROPERTIES
OUTPUT_NAME "cxx-library"
VERSION ${CIVETWEB_VERSION}
SOVERSION ${CIVETWEB_VERSION}
)
if (BUILD_SHARED_LIBS)
target_compile_definitions(cxx-library PRIVATE CIVETWEB_DLL_EXPORTS)
endif()
target_include_directories(
cxx-library PUBLIC
${PROJECT_SOURCE_DIR}/include)
install(
TARGETS cxx-library
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
COMPONENT cxx-library)
install(FILES
${PROJECT_SOURCE_DIR}/include/CivetServer.h
DESTINATION include
COMPONENT cxx-library)
endif()

View File

@@ -1,4 +1,6 @@
/* Copyright (c) 2013-2016 the Civetweb developers /*
* Copyright (C) 2016 Lammert Bies
* Copyright (c) 2013-2016 the Civetweb developers
* Copyright (c) 2004-2013 Sergey Lyubka * Copyright (c) 2004-2013 Sergey Lyubka
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -108,9 +110,9 @@ mg_static_assert(sizeof(void *) >= sizeof(int), "data type size check");
#endif /* __SYMBIAN32__ */ #endif /* __SYMBIAN32__ */
/* Include the header file here, so the CivetWeb interface is defined for the /* Include the header file here, so the LibHTTP interface is defined for the
* entire implementation, including the following forward definitions. */ * entire implementation, including the following forward definitions. */
#include "civetweb.h" #include "libhttp.h"
#ifndef IGNORE_UNUSED_RESULT #ifndef IGNORE_UNUSED_RESULT
@@ -1482,7 +1484,7 @@ struct mg_handler_info {
struct mg_context { struct mg_context {
volatile int stop_flag; /* Should we stop event loop */ volatile int stop_flag; /* Should we stop event loop */
SSL_CTX *ssl_ctx; /* SSL context */ SSL_CTX *ssl_ctx; /* SSL context */
char *config[NUM_OPTIONS]; /* Civetweb configuration parameters */ char *config[NUM_OPTIONS]; /* LibHTTP configuration parameters */
struct mg_callbacks callbacks; /* User-defined callback function */ struct mg_callbacks callbacks; /* User-defined callback function */
void *user_data; /* User-defined data */ void *user_data; /* User-defined data */
int context_type; /* 1 = server context, 2 = client context */ int context_type; /* 1 = server context, 2 = client context */
@@ -1782,7 +1784,7 @@ mg_set_thread_name(const char *name)
char threadName[16 + 1]; /* 16 = Max. thread length in Linux/OSX/.. */ char threadName[16 + 1]; /* 16 = Max. thread length in Linux/OSX/.. */
mg_snprintf( mg_snprintf(
NULL, NULL, threadName, sizeof(threadName), "civetweb-%s", name); NULL, NULL, threadName, sizeof(threadName), "libhttp-%s", name);
#if defined(_WIN32) #if defined(_WIN32)
#if defined(_MSC_VER) #if defined(_MSC_VER)
@@ -7728,7 +7730,7 @@ prepare_cgi_environment(struct mg_connection *conn,
addenv(env, "SERVER_NAME=%s", conn->ctx->config[AUTHENTICATION_DOMAIN]); addenv(env, "SERVER_NAME=%s", conn->ctx->config[AUTHENTICATION_DOMAIN]);
addenv(env, "SERVER_ROOT=%s", conn->ctx->config[DOCUMENT_ROOT]); addenv(env, "SERVER_ROOT=%s", conn->ctx->config[DOCUMENT_ROOT]);
addenv(env, "DOCUMENT_ROOT=%s", conn->ctx->config[DOCUMENT_ROOT]); addenv(env, "DOCUMENT_ROOT=%s", conn->ctx->config[DOCUMENT_ROOT]);
addenv(env, "SERVER_SOFTWARE=%s/%s", "Civetweb", mg_version()); addenv(env, "SERVER_SOFTWARE=%s/%s", "LibHTTP", mg_version());
/* Prepare the environment block */ /* Prepare the environment block */
addenv(env, "%s", "GATEWAY_INTERFACE=CGI/1.1"); addenv(env, "%s", "GATEWAY_INTERFACE=CGI/1.1");
@@ -10072,9 +10074,9 @@ get_request_handler(struct mg_connection *conn,
} }
/* This is the heart of the Civetweb's logic. /* This is the heart of the LibHTTP's logic.
* This function is called when the request is read, parsed and validated, * This function is called when the request is read, parsed and validated,
* and Civetweb must decide what action to take: serve a file, or * and LibHTTP must decide what action to take: serve a file, or
* a directory, or call embedded function, etcetera. */ * a directory, or call embedded function, etcetera. */
static void static void
handle_request(struct mg_connection *conn) handle_request(struct mg_connection *conn)
@@ -10162,7 +10164,7 @@ handle_request(struct mg_connection *conn)
conn->status_code = i; conn->status_code = i;
return; return;
} else if (i == 0) { } else if (i == 0) {
/* civetweb should process the request */ /* LibHTTP should process the request */
} else { } else {
/* unspecified - may change with the next version */ /* unspecified - may change with the next version */
return; return;
@@ -11606,8 +11608,8 @@ set_ssl_option(struct mg_context *ctx)
? 0 ? 0
: (ctx->callbacks.init_ssl(ctx->ssl_ctx, ctx->user_data)); : (ctx->callbacks.init_ssl(ctx->ssl_ctx, ctx->user_data));
/* If callback returns 0, civetweb sets up the SSL certificate. /* If callback returns 0, LibHTTP sets up the SSL certificate.
* If it returns 1, civetweb assumes the calback already did this. * If it returns 1, LibHTTP assumes the calback already did this.
* If it returns -1, initializing ssl fails. */ * If it returns -1, initializing ssl fails. */
if (callback_ret < 0) { if (callback_ret < 0) {
mg_cry(fc(ctx), "SSL callback returned error: %i", callback_ret); mg_cry(fc(ctx), "SSL callback returned error: %i", callback_ret);
@@ -12205,7 +12207,7 @@ get_uri_type(const char *uri)
/* It could be an absolute uri: */ /* It could be an absolute uri: */
/* This function only checks if the uri is valid, not if it is /* This function only checks if the uri is valid, not if it is
* addressing the current server. So civetweb can also be used * addressing the current server. So LibHTTP can also be used
* as a proxy server. */ * as a proxy server. */
for (i = 0; abs_uri_protocols[i].proto != NULL; i++) { for (i = 0; abs_uri_protocols[i].proto != NULL; i++) {
if (mg_strncasecmp(uri, if (mg_strncasecmp(uri,