Procházet zdrojové kódy

Merge pull request #2 from civetweb/master

pull civetweb master
feneuilflo před 8 roky
rodič
revize
0f029805c7
100 změnil soubory, kde provedl 2747 přidání a 131 odebrání
  1. 2 0
      .gitignore
  2. 294 44
      .travis.yml
  3. 19 10
      CMakeLists.txt
  4. 18 0
      CREDITS.md
  5. 1 3
      LICENSE.md
  6. 13 3
      Makefile
  7. 34 25
      Qt/CivetWeb.pro
  8. 23 16
      README.md
  9. 64 3
      RELEASE_NOTES.md
  10. 5 4
      VisualStudio/civetweb_lua/civetweb_lua.vcxproj
  11. 6 0
      VisualStudio/civetweb_lua/civetweb_lua.vcxproj.filters
  12. 3 3
      VisualStudio/duktape_lib/duktape_lib.vcxproj
  13. 3 3
      VisualStudio/duktape_lib/duktape_lib.vcxproj.filters
  14. 2 0
      VisualStudio/unit_test/unit_test.vcxproj
  15. 6 0
      VisualStudio/unit_test/unit_test.vcxproj.filters
  16. 1 0
      _config.yml
  17. 20 8
      appveyor.yml
  18. 1 1
      contrib/buildroot/civetweb.mk
  19. 107 0
      docs/APIReference.md
  20. 27 0
      docs/Building.md
  21. 1 1
      docs/Contribution.md
  22. 49 0
      docs/Embedding.md
  23. 3 2
      docs/Installing.md
  24. 70 0
      docs/Interface_Changes_1.10.md
  25. 40 0
      docs/README.md
  26. 80 5
      docs/UserManual.md
  27. 1 0
      docs/_config.yml
  28. 21 0
      docs/api/client_cert.md
  29. 60 0
      docs/api/mg_callbacks.md
  30. 40 0
      docs/api/mg_check_feature.md
  31. 21 0
      docs/api/mg_client_options.md
  32. 21 0
      docs/api/mg_close_connection.md
  33. 29 0
      docs/api/mg_connect_client.md
  34. 30 0
      docs/api/mg_connect_client_secure.md
  35. 36 0
      docs/api/mg_connect_websocket_client.md
  36. 23 0
      docs/api/mg_cry.md
  37. 37 0
      docs/api/mg_download.md
  38. 29 0
      docs/api/mg_exit_library.md
  39. 36 0
      docs/api/mg_form_data_handler.md
  40. 24 0
      docs/api/mg_get_builtin_mime_type.md
  41. 24 0
      docs/api/mg_get_context.md
  42. 26 0
      docs/api/mg_get_context_info.md
  43. 29 0
      docs/api/mg_get_cookie.md
  44. 22 0
      docs/api/mg_get_header.md
  45. 24 0
      docs/api/mg_get_option.md
  46. 31 0
      docs/api/mg_get_ports.md
  47. 23 0
      docs/api/mg_get_request_info.md
  48. 29 0
      docs/api/mg_get_request_link.md
  49. 29 0
      docs/api/mg_get_response.md
  50. 25 0
      docs/api/mg_get_response_code_text.md
  51. 28 0
      docs/api/mg_get_server_ports.md
  52. 25 0
      docs/api/mg_get_system_info.md
  53. 23 0
      docs/api/mg_get_user_connection_data.md
  54. 23 0
      docs/api/mg_get_user_data.md
  55. 24 0
      docs/api/mg_get_valid_option_names.md
  56. 22 0
      docs/api/mg_get_valid_options.md
  57. 30 0
      docs/api/mg_get_var.md
  58. 31 0
      docs/api/mg_get_var2.md
  59. 24 0
      docs/api/mg_handle_form_request.md
  60. 18 0
      docs/api/mg_header.md
  61. 44 0
      docs/api/mg_init_library.md
  62. 26 0
      docs/api/mg_lock_connection.md
  63. 23 0
      docs/api/mg_lock_context.md
  64. 24 0
      docs/api/mg_md5.md
  65. 28 0
      docs/api/mg_modify_passwords_file.md
  66. 31 0
      docs/api/mg_option.md
  67. 27 0
      docs/api/mg_printf.md
  68. 26 0
      docs/api/mg_read.md
  69. 35 0
      docs/api/mg_request_info.md
  70. 27 0
      docs/api/mg_send_chunk.md
  71. 25 0
      docs/api/mg_send_file.md
  72. 26 0
      docs/api/mg_send_http_error.md
  73. 27 0
      docs/api/mg_send_mime_file.md
  74. 30 0
      docs/api/mg_send_mime_file2.md
  75. 24 0
      docs/api/mg_server_ports.md
  76. 30 0
      docs/api/mg_set_auth_handler.md
  77. 26 0
      docs/api/mg_set_request_handler.md
  78. 22 0
      docs/api/mg_set_user_connection_data.md
  79. 30 0
      docs/api/mg_set_websocket_handler.md
  80. 39 0
      docs/api/mg_start.md
  81. 26 0
      docs/api/mg_start_thread.md
  82. 22 0
      docs/api/mg_stop.md
  83. 24 0
      docs/api/mg_store_body.md
  84. 24 0
      docs/api/mg_strcasecmp.md
  85. 25 0
      docs/api/mg_strncasecmp.md
  86. 27 0
      docs/api/mg_unlock_connection.md
  87. 23 0
      docs/api/mg_unlock_context.md
  88. 22 0
      docs/api/mg_upload.md
  89. 27 0
      docs/api/mg_url_decode.md
  90. 25 0
      docs/api/mg_url_encode.md
  91. 19 0
      docs/api/mg_version.md
  92. 32 0
      docs/api/mg_websocket_client_write.md
  93. 34 0
      docs/api/mg_websocket_write.md
  94. 29 0
      docs/api/mg_write.md
  95. 8 0
      examples/README.md
  96. 0 0
      examples/_obsolete/chat/Makefile
  97. 0 0
      examples/_obsolete/chat/chat.c
  98. 0 0
      examples/_obsolete/docroot/favicon.ico
  99. 0 0
      examples/_obsolete/docroot/index.html
  100. 0 0
      examples/_obsolete/docroot/jquery.js

+ 2 - 0
.gitignore

@@ -112,6 +112,8 @@ ipch/
 *.opensdf
 *.sdf
 *.cachefile
+*.VC.db
+*.VC.VC.opendb
 
 # Visual Studio profiler
 *.psess

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 294 - 44
.travis.yml


+ 19 - 10
CMakeLists.txt

@@ -26,7 +26,7 @@ include(CMakeDependentOption)
 
 # Set up the project
 project (civetweb)
-set(CIVETWEB_VERSION "1.7.0" CACHE STRING "The version of the civetweb library")
+set(CIVETWEB_VERSION "1.10.0" CACHE STRING "The version of the civetweb library")
 string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" CIVETWEB_VERSION_MATCH "${CIVETWEB_VERSION}")
 if ("${CIVETWEB_VERSION_MATCH}" STREQUAL "")
   message(FATAL_ERROR "Must specify a semantic version: major.minor.patch")
@@ -48,12 +48,6 @@ endif()
 # C++ wrappers
 option(CIVETWEB_ENABLE_THIRD_PARTY_OUTPUT "Shows the output of third party dependency processing" OFF)
 
-# Max Request Size
-set(CIVETWEB_MAX_REQUEST_SIZE 16384 CACHE STRING
-  "The largest amount of content bytes allowed in a request")
-set_property(CACHE CIVETWEB_MAX_REQUEST_SIZE PROPERTY VALUE ${CIVETWEB_MAX_REQUEST_SIZE})
-message(STATUS "Max Request Size - ${CIVETWEB_MAX_REQUEST_SIZE}")
-
 # Thread Stack Size
 set(CIVETWEB_THREAD_STACK_SIZE 102400 CACHE STRING
   "The stack size in bytes for each thread created")
@@ -84,6 +78,10 @@ message(STATUS "IP Version 6 - ${CIVETWEB_ENABLE_IPV6}")
 option(CIVETWEB_ENABLE_WEBSOCKETS "Enable websockets connections" OFF)
 message(STATUS "Websockets support - ${CIVETWEB_ENABLE_WEBSOCKETS}")
 
+# Server statistics support
+option(CIVETWEB_ENABLE_SERVER_STATS "Enable server statistics" OFF)
+message(STATUS "Server statistics support - ${CIVETWEB_ENABLE_SERVER_STATS}")
+
 # Memory debugging
 option(CIVETWEB_ENABLE_MEMORY_DEBUGGING "Enable the memory debugging features" OFF)
 message(STATUS "Memory Debugging - ${CIVETWEB_ENABLE_MEMORY_DEBUGGING}")
@@ -188,6 +186,10 @@ message(STATUS "Duktape CGI support - ${CIVETWEB_ENABLE_DUKTAPE}")
 option(CIVETWEB_ENABLE_SSL "Enables the secure socket layer" ON)
 message(STATUS "SSL support - ${CIVETWEB_ENABLE_SSL}")
 
+# OpenSSL 1.1 API
+option(CIVETWEB_SSL_OPENSSL_API_1_1 "Use the OpenSSL 1.1 API" OFF)
+message(STATUS "Compile for OpenSSL 1.1 API - ${CIVETWEB_SSL_OPENSSL_API_1_1}")
+
 # Dynamically load or link the SSL libraries
 cmake_dependent_option(
   CIVETWEB_ENABLE_SSL_DYNAMIC_LOADING "Dynamically loads the SSL library rather than linking it" ON
@@ -369,6 +371,9 @@ endif()
 if (CIVETWEB_ENABLE_WEBSOCKETS)
   add_definitions(-DUSE_WEBSOCKET)
 endif()
+if (CIVETWEB_ENABLE_SERVER_STATS)
+  add_definitions(-DUSE_SERVER_STATS)
+endif()
 if (CIVETWEB_SERVE_NO_FILES)
   add_definitions(-DNO_FILES)
 endif()
@@ -399,8 +404,10 @@ else()
     add_definitions(-DCRYPTO_LIB="${CIVETWEB_SSL_CRYPTO_LIB}")
   endif()
 endif()
+if(CIVETWEB_SSL_OPENSSL_API_1_1)
+  add_definitions(-DOPENSSL_API_1_1)
+endif()
 add_definitions(-DUSE_STACK_SIZE=${CIVETWEB_THREAD_STACK_SIZE})
-add_definitions(-DMAX_REQUEST_SIZE=${CIVETWEB_MAX_REQUEST_SIZE})
 
 # Build the targets
 add_subdirectory(src)
@@ -409,14 +416,16 @@ add_subdirectory(src)
 include(CTest)
 if (BUILD_TESTING)
   # Check unit testing framework Version
-  set(CIVETWEB_CHECK_VERSION 0.10.0 CACHE STRING
+  set(CIVETWEB_CHECK_VERSION 0.11.0 CACHE STRING
     "The version of Check unit testing framework to build and include statically")
   set_property(CACHE CIVETWEB_CHECK_VERSION PROPERTY VALUE ${CIVETWEB_CHECK_VERSION})
   message(STATUS "Check Unit Testing Framework Version - ${CIVETWEB_CHECK_VERSION}")
   mark_as_advanced(CIVETWEB_CHECK_VERSION)
 
   # Check unit testing framework Verification Hash
-  set(CIVETWEB_CHECK_MD5_HASH 67a34c40b5bc888737f4e5ae82e9939f CACHE STRING
+  # Hash for Check 0.10.0: 67a34c40b5bc888737f4e5ae82e9939f
+  # Hash for Check 0.11.0: 1b14ee307dca8e954a8219c34484d7c4
+  set(CIVETWEB_CHECK_MD5_HASH 1b14ee307dca8e954a8219c34484d7c4 CACHE STRING
     "The hash of Check unit testing framework archive to be downloaded")
   set_property(CACHE CIVETWEB_CHECK_MD5_HASH PROPERTY VALUE ${CIVETWEB_CHECK_MD5_HASH})
   mark_as_advanced(CIVETWEB_CHECK_MD5_HASH)

+ 18 - 0
CREDITS.md

@@ -1,5 +1,7 @@
 # Civetweb Contributors
 
+* Abhishek Lekshmanan
+* Adam Bailey
 * Alex Kozlov
 * bel2125
 * Ben M. Ward
@@ -23,10 +25,13 @@
 * ehlertjd
 * Eric Tsau
 * Erik Beran
+* extergnoto
 * F-Secure Corporation
+* feneuilflo
 * Fernando G. Aranda
 * Grahack
 * grenclave
+* grunk
 * hansipie
 * HariKamath Kamath
 * Jack
@@ -43,10 +48,12 @@
 * Jordan Shelley
 * Joshua Boyd
 * Joshua D. Boyd
+* kakwa
 * kalphamon
 * Keith Kyzivat
 * Kevin Wojniak
 * Kimmo Mustonen
+* Lammert Bies
 * Lawrence
 * Li Peng
 * Lianghui
@@ -63,18 +70,27 @@
 * Nigel Stewart
 * nihildeb
 * No Face Press
+* palortoff
+* Patrick Drechsler
+* Patrick Trinkle
 * Paul Sokolovsky
+* Paulo Brizolara
+* pavel.pimenov
+* PavelVozenilek
 * Perttu Ahola
 * Peter Foerster
 * Philipp Friedenberger
 * Philipp Hasper
 * Red54
 * Richard Screene
+* pkvamme
 * Sage Weil
 * Sangwhan Moon
 * Saumitra Vikram
 * Scott Nations
+* sgmesservey
 * shantanugadgil
+* slidertom
 * SpaceLord
 * sunfch
 * thewaterymoon
@@ -83,7 +99,9 @@
 * Toni Wilk
 * Ulrich Hertlein
 * Walt Steverson
+* webxer
 * William Greathouse
+* xeoshow
 * xtne6f
 * Yehuda Sadeh
 

+ 1 - 3
LICENSE.md

@@ -11,7 +11,7 @@ Civetweb License
 
 ### Included with all features.
 
-> Copyright (c) 2013-2015 The CivetWeb developers ([CREDITS.md](https://github.com/civetweb/civetweb/blob/master/CREDITS.md))
+> Copyright (c) 2013-2017 The CivetWeb developers ([CREDITS.md](https://github.com/civetweb/civetweb/blob/master/CREDITS.md))
 >
 > Copyright (c) 2004-2013 Sergey Lyubka
 >
@@ -206,5 +206,3 @@ https://github.com/svaarala/duktape/blob/master/LICENSE.txt
 > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 > THE SOFTWARE.
 
-
-

+ 13 - 3
Makefile

@@ -110,6 +110,16 @@ endif
 ifdef WITH_WEBSOCKET
   CFLAGS += -DUSE_WEBSOCKET
 endif
+ifdef WITH_WEBSOCKETS
+  CFLAGS += -DUSE_WEBSOCKET
+endif
+
+ifdef WITH_SERVER_STAT
+  CFLAGS += -DUSE_SERVER_STATS
+endif
+ifdef WITH_SERVER_STATS
+  CFLAGS += -DUSE_SERVER_STATS
+endif
 
 ifdef CONFIG_FILE
   CFLAGS += -DCONFIG_FILE=\"$(CONFIG_FILE)\"
@@ -180,6 +190,7 @@ help:
 	@echo "   WITH_DEBUG=1          build with GDB debug support"
 	@echo "   WITH_IPV6=1           with IPV6 support"
 	@echo "   WITH_WEBSOCKET=1      build with web socket support"
+	@echo "   WITH_SERVER_STATS=1   build includes support for server statistics"
 	@echo "   WITH_CPP=1            build library with c++ classes"
 	@echo "   CONFIG_FILE=file      use 'file' as the config file"
 	@echo "   CONFIG_FILE2=file     use 'file' as the backup config file"
@@ -198,7 +209,6 @@ help:
 	@echo "   NO_SSL_DL             link against system libssl library"
 	@echo "   NO_FILES              do not serve files from a directory"
 	@echo "   NO_CACHING            disable caching (usefull for systems without timegm())"
-	@echo "   MAX_REQUEST_SIZE      maximum header size, default 16384"
 	@echo ""
 	@echo " Variables"
 	@echo "   TARGET_OS='$(TARGET_OS)'"
@@ -247,7 +257,7 @@ slib: lib$(CPROG).$(SHARED_LIB)
 
 clean:
 	$(RMRF) $(BUILD_DIR)
-	$(eval version=$(shell grep "define CIVETWEB_VERSION" include/civetweb.h | sed 's|.*VERSION "\(.*\)"|\1|g'))
+	$(eval version=$(shell grep -w "define CIVETWEB_VERSION" include/civetweb.h | sed 's|.*VERSION "\(.*\)"|\1|g'))
 	$(eval major=$(shell echo $(version) | cut -d'.' -f1))
 	$(RMRF) lib$(CPROG).a
 	$(RMRF) lib$(CPROG).so
@@ -269,7 +279,7 @@ lib$(CPROG).a: $(LIB_OBJECTS)
 
 lib$(CPROG).so: CFLAGS += -fPIC
 lib$(CPROG).so: $(LIB_OBJECTS)
-	$(eval version=$(shell grep "define CIVETWEB_VERSION" include/civetweb.h | sed 's|.*VERSION "\(.*\)"|\1|g'))
+	$(eval version=$(shell grep -w "define CIVETWEB_VERSION" include/civetweb.h | sed 's|.*VERSION "\(.*\)"|\1|g'))
 	$(eval major=$(shell echo $(version) | cut -d'.' -f1))
 	$(LCC) -shared -Wl,-soname,$@.$(major) -o $@.$(version).0 $(CFLAGS) $(LDFLAGS) $(LIB_OBJECTS)
 	ln -s -f $@.$(major) $@

+ 34 - 25
Qt/CivetWeb.pro

@@ -1,25 +1,34 @@
-TEMPLATE = app
-CONFIG += console
-CONFIG -= app_bundle
-CONFIG -= qt
-
-SOURCES += \
-    ../src/md5.inl \
-    ../src/mod_lua.inl \
-    ../src/timer.inl \
-    ../src/civetweb.c \
-    ../src/main.c
-
-include(deployment.pri)
-qtcAddDeployment()
-
-HEADERS += \
-    ../include/civetweb.h
-
-INCLUDEPATH +=  \
-    ../include/
-
-LIBS += -lws2_32 -lComdlg32
-
-DEFINES += USE_IPV6
-DEFINES += USE_WEBSOCKET
+TEMPLATE = app
+CONFIG += console
+CONFIG -= app_bundle
+CONFIG -= qt
+
+SOURCES += \
+    ../src/md5.inl \
+    ../src/sha1.inl \
+    ../src/handle_form.inl \
+    ../src/mod_lua.inl \
+    ../src/mod_duktape.inl \
+    ../src/timer.inl \
+    ../src/civetweb.c \
+    ../src/main.c
+
+#include(deployment.pri)
+#qtcAddDeployment()
+
+HEADERS += \
+    ../include/civetweb.h
+
+INCLUDEPATH +=  \
+    ../include/
+
+win32 {
+LIBS += -lws2_32 -lComdlg32 -lUser32 -lShell32 -lAdvapi32
+} else {
+LIBS += -lpthread -ldl -lm
+}
+
+
+DEFINES += USE_IPV6
+DEFINES += USE_WEBSOCKET
+DEFINES += USE_SERVER_STATS

+ 23 - 16
README.md

@@ -1,4 +1,4 @@
-![CivetWeb](https://raw.github.com/civetweb/civetweb/master/resources/civetweb_64x64.png "CivetWeb") CivetWeb
+![CivetWeb](https://raw.githubusercontent.com/civetweb/civetweb/master/resources/civetweb_64x64.png "CivetWeb") CivetWeb
 =======
 
 **The official home of CivetWeb is [https://github.com/civetweb/civetweb](https://github.com/civetweb/civetweb)**
@@ -16,7 +16,7 @@ Test coverage check ([coveralls](https://coveralls.io/github/civetweb/civetweb))
 
 [![Coverage Status](https://coveralls.io/repos/github/civetweb/civetweb/badge.svg?branch=master)](https://coveralls.io/github/civetweb/civetweb?branch=master)
 
-Static source code analysis ([Coverity](https://scan.coverity.com/projects/5784)): 
+Static source code analysis ([Coverity](https://scan.coverity.com/projects/5784)):
 
 [![Coverity Scan Build Status](https://scan.coverity.com/projects/5784/badge.svg)](https://scan.coverity.com/projects/5784)
 
@@ -49,6 +49,9 @@ Trouble tickets should be filed on GitHub
 Discussion/support group and announcements are at Google Groups
 [https://groups.google.com/d/forum/civetweb](https://groups.google.com/d/forum/civetweb)
 
+Source releases can be found on GitHub
+[https://github.com/civetweb/civetweb/releases](https://github.com/civetweb/civetweb/releases)
+
 
 Quick start documentation
 --------------------------
@@ -58,6 +61,7 @@ Quick start documentation
 - [docs/Building.md](https://github.com/civetweb/civetweb/blob/master/docs/Building.md) - Building the Server (quick start 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/OpenSSL.md](https://github.com/civetweb/civetweb/blob/master/docs/OpenSSL.md) - Adding HTTPS (SSL/TLS) support using OpenSSL.
+- [API documentation](https://github.com/civetweb/civetweb/tree/master/docs/api) - Additional documentation on the civetweb application programming interface ([civetweb.h](https://github.com/civetweb/civetweb/blob/master/include/civetweb.h)).
 - [RELEASE_NOTES.md](https://github.com/civetweb/civetweb/blob/master/RELEASE_NOTES.md) - Release Notes
 - [LICENSE.md](https://github.com/civetweb/civetweb/blob/master/LICENSE.md) - Copyright License
 
@@ -97,22 +101,22 @@ simplicity by a carefully selected list of features:
 ### Optionally included software
 
 <a href="http://lua.org">
-![Lua](https://raw.github.com/civetweb/civetweb/master/resources/lua-logo.jpg "Lua Logo")
+![Lua](https://raw.githubusercontent.com/civetweb/civetweb/master/resources/lua-logo.jpg "Lua Logo")
 </a>
 <a href="http://sqlite.org">
-![Sqlite3](https://raw.github.com/civetweb/civetweb/master/resources/sqlite3-logo.jpg "Sqlite3 Logo")
+![Sqlite3](https://raw.githubusercontent.com/civetweb/civetweb/master/resources/sqlite3-logo.jpg "Sqlite3 Logo")
 </a>
 <a href="http://keplerproject.github.io/luafilesystem/">
-![LuaFileSystem](https://raw.github.com/civetweb/civetweb/master/resources/luafilesystem-logo.jpg "LuaFileSystem Logo")
+![LuaFileSystem](https://raw.githubusercontent.com/civetweb/civetweb/master/resources/luafilesystem-logo.jpg "LuaFileSystem Logo")
 </a>
 <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.githubusercontent.com/civetweb/civetweb/master/resources/luasqlite-logo.jpg "LuaSQLite3 Logo")
 </a>
 <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.githubusercontent.com/civetweb/civetweb/master/resources/luaxml-logo.jpg "LuaXML Logo")
 </a>
 <a href="http://duktape.org">
-![Duktape](https://raw.github.com/civetweb/civetweb/master/resources/duktape-logo.png "Duktape Logo")
+![Duktape](https://raw.githubusercontent.com/civetweb/civetweb/master/resources/duktape-logo.png "Duktape Logo")
 </a>
 
 
@@ -130,7 +134,8 @@ Contributions
 Contributions are welcome provided all contributions carry the MIT license.
 
 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).
 
@@ -142,14 +147,16 @@ 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)
 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. 
-Since 2013, CivetWeb has seen many improvements from various authors 
-(Copyright (c) 2013-2016 the CivetWeb developers, MIT license).
+The license change and CivetWeb used to be mentioned on the Mongoose
+[Wikipedia](https://en.wikipedia.org/wiki/Mongoose_(web_server))
+page as well, but it's getting deleted (and added again) there every
+now and then.
+
+CivetWeb has been forked from the last MIT version of Mongoose.
+Since 2013, CivetWeb has seen many improvements from various authors
+(Copyright (c) 2013-2017 the CivetWeb developers, MIT license).
 A list of authors can be found in [CREDITS.md](https://github.com/civetweb/civetweb/blob/master/CREDITS.md).
 
 Using the CivetWeb 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.
-

+ 64 - 3
RELEASE_NOTES.md

@@ -1,10 +1,70 @@
-Release Notes v1.9 (work in progress)
+Release Notes v1.10 (work in progress)
 ===
-### Objectives: *Read client certificate information, bug fixes*
+### Objectives: *OpenSSL 1.1 support + to be defined*
 
 Changes
 -------
 
+- Fix timeout error when sending larger files
+- Add mg_send_chunk interface function
+- Allow to separate server private key and certificate chain in two different files
+- Support for multipart requests without quotes (for some C# clients)
+- Initialize SSL in mg_init_library, so https client functions can be used when no server is running
+- Allow "REPORT" HTTP method for REST calls to scripts
+- Allow to compile civetweb.c wih a C++ compiler
+- Lua: Remove internal length limits of encode/decode functions
+- Allow sub-resources of index script files
+- Remove deprecated "uri" member of the request from the interface
+- Improve documentation
+- Make auth domain check optional (configuration)
+- Update unit test framework to check 0.11.0
+- Limit depth of mg.include for Lua server pages
+- Additional unit tests
+- OpenSSL 1.1 support
+- Update version number
+
+
+Release Notes v1.9.1
+===
+### Objectives: *Bug fix*
+
+Changes
+-------
+
+- Add "open website" button for pre-built Windows binaries
+- Fix for connections closed prematurely
+- Update to a new check unit test framework and remove patches required for previous version
+- Update version number
+
+
+Release Notes v1.9
+===
+### Objectives: *Read SSI client certificate information, improve windows usability, use non-blocking sockets, bug fixes*
+
+Changes
+-------
+
+- Add library init/exit functions (call is now optional, but will be required in V1.10)
+- Windows: Show system information from the tray icon
+- Windows: Bring overlaid windows to top from the tray icon
+- Add Lua background script, running independent from server state
+- Move obsolete examples into separated directory
+- Change name of CMake generated C++ library to civetweb-cpp
+- Add option to set linger timeout
+- Update Duktape and Lua (third-party code)
+- Add continuous integration tests
+- Add API documentation
+- Limit recursions in .htpasswd files
+- Fix SCRIPT_NAME for CGI directory index files (index.php)
+- Use non-blocking sockets
+- stdint.h is now required and no longer optional
+- Rewrite connection close handling
+- Rewrite mg_fopen/mg_stat
+- Enhanced tray icon menu for Windows
+- Add subprotocol management for websocket connections
+- Partially rewrite timeout handling
+- Add option keep_alive_timeout_ms
+- Improve support for absolute URIs
 - Allow some additional compiler checks (higher warning level)
 - Add option for case sensitive file names for Windows
 - Short notation for listening_ports option when using IPv4 and IPv6 ports
@@ -14,6 +74,7 @@ Changes
 - Read client certificate information
 - Do not tolerate URIs with invalid characters
 - Fix mg_get_cookie to ignore substrings
+- Fix memory leak in form handling
 - Fix bug in timer logic (for Lua Websockets)
 - Updated version number
 
@@ -304,6 +365,6 @@ Changes
 
 - Renamed Mongoose to Civetweb in the code and documentation.
 - Replaced copyrighted images with new images
-- Created a new code respository at https://github.com/bel2125/civetweb
+- Created a new code respository at https://github.com/civetweb/civetweb
 - Created a distribution site at https://sourceforge.net/projects/civetweb/
 - Basic build testing

+ 5 - 4
VisualStudio/civetweb_lua/civetweb_lua.vcxproj

@@ -102,7 +102,7 @@
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.3.0\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.5.2\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -116,7 +116,7 @@
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.3.0\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.5.2\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -146,7 +146,7 @@
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <PreprocessorDefinitions>USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.3.0\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.5.2\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -164,7 +164,7 @@
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <PreprocessorDefinitions>USE_DUKTAPE;USE_IPV6;LUA_COMPAT_ALL;USE_LUA;USE_LUA_SQLITE3;USE_LUA_FILE_SYSTEM;USE_WEBSOCKET;WIN32;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.3.0\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>$(ProjectDir)..\..\include;$(ProjectDir)..\..\src\third_party;$(ProjectDir)..\..\src\third_party\lua-5.2.4\src;$(ProjectDir)..\..\src\third_party\duktape-1.5.2\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -203,6 +203,7 @@
   <ItemGroup>
     <None Include="..\..\src\handle_form.inl" />
     <None Include="..\..\src\md5.inl" />
+    <None Include="..\..\src\sha1.inl" />
     <None Include="..\..\src\mod_duktape.inl" />
     <None Include="..\..\src\mod_lua.inl" />
     <None Include="..\..\src\timer.inl" />

+ 6 - 0
VisualStudio/civetweb_lua/civetweb_lua.vcxproj.filters

@@ -56,12 +56,18 @@
     <None Include="..\..\src\md5.inl">
       <Filter>inl files</Filter>
     </None>
+    <None Include="..\..\src\sha1.inl">
+      <Filter>inl files</Filter>
+    </None>
     <None Include="..\..\src\mod_lua.inl">
       <Filter>inl files</Filter>
     </None>
     <None Include="..\..\src\timer.inl">
       <Filter>inl files</Filter>
     </None>
+    <None Include="..\..\src\file_ops.inl">
+      <Filter>inl files</Filter>
+    </None>
     <None Include="..\..\src\mod_duktape.inl">
       <Filter>inl files</Filter>
     </None>

+ 3 - 3
VisualStudio/duktape_lib/duktape_lib.vcxproj

@@ -144,11 +144,11 @@
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClInclude Include="..\..\src\third_party\duktape-1.3.0\src\duktape.h" />
-    <ClInclude Include="..\..\src\third_party\duktape-1.3.0\src\duk_config.h" />
+    <ClInclude Include="..\..\src\third_party\duktape-1.5.2\src\duktape.h" />
+    <ClInclude Include="..\..\src\third_party\duktape-1.5.2\src\duk_config.h" />
   </ItemGroup>
   <ItemGroup>
-    <ClCompile Include="..\..\src\third_party\duktape-1.3.0\src\duktape.c" />
+    <ClCompile Include="..\..\src\third_party\duktape-1.5.2\src\duktape.c" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">

+ 3 - 3
VisualStudio/duktape_lib/duktape_lib.vcxproj.filters

@@ -15,15 +15,15 @@
     </Filter>
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="..\..\src\third_party\duktape-1.3.0\src\duk_config.h">
+    <ClInclude Include="..\..\src\third_party\duktape-1.5.2\src\duk_config.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="..\..\src\third_party\duktape-1.3.0\src\duktape.h">
+    <ClInclude Include="..\..\src\third_party\duktape-1.5.2\src\duktape.h">
       <Filter>Header Files</Filter>
     </ClInclude>
   </ItemGroup>
   <ItemGroup>
-    <ClCompile Include="..\..\src\third_party\duktape-1.3.0\src\duktape.c">
+    <ClCompile Include="..\..\src\third_party\duktape-1.5.2\src\duktape.c">
       <Filter>Source Files</Filter>
     </ClCompile>
   </ItemGroup>

+ 2 - 0
VisualStudio/unit_test/unit_test.vcxproj

@@ -17,6 +17,7 @@
     <ClInclude Include="..\..\test\private_exe.h" />
     <ClInclude Include="..\..\test\public_func.h" />
     <ClInclude Include="..\..\test\public_server.h" />
+    <ClInclude Include="..\..\test\timertest.h" />
     <ClInclude Include="..\..\test\shared.h" />
   </ItemGroup>
   <ItemGroup>
@@ -25,6 +26,7 @@
     <ClCompile Include="..\..\test\private_exe.c" />
     <ClCompile Include="..\..\test\public_func.c" />
     <ClCompile Include="..\..\test\public_server.c" />
+    <ClInclude Include="..\..\test\timertest.c" />
     <ClCompile Include="..\..\test\shared.c" />
   </ItemGroup>
   <PropertyGroup Label="Globals">

+ 6 - 0
VisualStudio/unit_test/unit_test.vcxproj.filters

@@ -30,6 +30,9 @@
     <ClInclude Include="..\..\test\private.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\test\timertest.h">
+      <Filter>Headerdateien</Filter>
+    </ClInclude>
     <ClInclude Include="..\..\test\shared.h">
       <Filter>Headerdateien</Filter>
     </ClInclude>
@@ -50,6 +53,9 @@
     <ClCompile Include="..\..\test\private_exe.c">
       <Filter>Quelldateien</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\test\timertest.c">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>    
     <ClCompile Include="..\..\test\shared.c">
       <Filter>Quelldateien</Filter>
     </ClCompile>

+ 1 - 0
_config.yml

@@ -0,0 +1 @@
+theme: jekyll-theme-tactile

+ 20 - 8
appveyor.yml

@@ -1,11 +1,6 @@
 version: '{build}'
 
 
-configuration:
-  - Release
-  - Debug
-
-
 build:
 # no automatic build in script mode
 
@@ -32,6 +27,7 @@ environment:
       enable_websockets: YES
       no_cgi: NO
       no_caching: NO
+      configuration: Release
     - id: 2
       compiler: msvc-18-seh
       build_shared: YES
@@ -41,6 +37,7 @@ environment:
       enable_websockets: YES
       no_cgi: NO
       no_caching: NO
+      configuration: Release
     - id: 3
       compiler: msvc-18-seh
       build_shared: YES
@@ -50,6 +47,7 @@ environment:
       enable_websockets: YES
       no_cgi: NO
       no_caching: NO
+      configuration: Release
     - id: 4
       compiler: gcc-5.1.0-posix
       build_shared: NO
@@ -59,6 +57,7 @@ environment:
       enable_websockets: NO
       no_cgi: YES
       no_caching: YES
+      configuration: Release
     - id: 5
       compiler: gcc-5.1.0-posix
       build_shared: NO
@@ -68,6 +67,7 @@ environment:
       enable_websockets: YES
       no_cgi: NO
       no_caching: YES
+      configuration: Release
     - id: 6
       compiler: gcc-5.1.0-posix
       build_shared: NO
@@ -77,6 +77,7 @@ environment:
       enable_websockets: YES
       no_cgi: NO
       no_caching: YES
+      configuration: Release
     - id: 7
       compiler: gcc-5.1.0-posix
       build_shared: YES
@@ -86,6 +87,7 @@ environment:
       enable_websockets: YES
       no_cgi: NO
       no_caching: YES
+      configuration: Release
     - id: 8
       compiler: gcc-5.1.0-posix
       build_shared: YES
@@ -95,7 +97,17 @@ environment:
       enable_websockets: YES
       no_cgi: NO
       no_caching: YES
-
+      configuration: Release
+    - id: 9
+      compiler: msvc-18-seh
+      build_shared: NO
+      no_files: NO
+      enable_ipv6: YES
+      enable_ssl: YES
+      enable_websockets: YES
+      no_cgi: NO
+      no_caching: NO
+      configuration: Debug
 
 install:
   # Derive some extra information
@@ -223,8 +235,8 @@ after_test:
   - cd
   - dir
   - md dist
-  - cmake "-DCMAKE_INSTALL_PREFIX=%install_path%" -P "%build_path%/cmake_install.cmake"
-  - copy "%build_path%" dist\
+  - if "%build_type%"=="Release" (cmake "-DCMAKE_INSTALL_PREFIX=%install_path%" -P "%build_path%/cmake_install.cmake")
+  - if "%build_type%"=="Release" (copy "%build_path%" dist\)
   - dir dist\
 
 matrix:

+ 1 - 1
contrib/buildroot/civetweb.mk

@@ -4,7 +4,7 @@
 #
 ################################################################################
 
-CIVETWEB_VERSION = 1.9
+CIVETWEB_VERSION = 1.10
 CIVETWEB_SITE = http://github.com/civetweb/civetweb/tarball/v$(CIVETWEB_VERSION)
 CIVETWEB_LICENSE = MIT
 CIVETWEB_LICENSE_FILES = LICENSE.md

+ 107 - 0
docs/APIReference.md

@@ -0,0 +1,107 @@
+# CivetWeb API Reference
+
+CivetWeb 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
+codebase. A C++ wrapper is also available, although it is not guaranteed
+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
+the API can be found in [Embedding.md](Embedding.md).
+
+## Macros
+
+| Macro | Description |
+| :--- | :--- |
+| **`CIVETWEB_VERSION`** | The current version of the software as a string with the major and minor version number seperated with a dot. For version 1.9, this string will have the value "1.9", for thw first patch of this version "1.9.1". |
+| **`CIVETWEB_VERSION_MAJOR`** | The current major version as number, e.g., (1) for version 1.9. |
+| **`CIVETWEB_VERSION_MINOR`** | The current minor version as number, e.g., (9) for version 1.9. |
+| **`CIVETWEB_VERSION_PATCH`** | The current patch version as number, e.g., (0) for version 1.9 or (1) for version 1.9.1. |
+
+
+## Structures
+
+* [`struct client_cert;`](api/client_cert.md)
+* [`struct mg_client_options;`](api/mg_client_options.md)
+* [`struct mg_callbacks;`](api/mg_callbacks.md)
+* [`struct mg_form_data_handler;`](api/mg_form_data_handler.md)
+* [`struct mg_header;`](api/mg_header.md)
+* [`struct mg_option;`](api/mg_option.md)
+* [`struct mg_request_info;`](api/mg_request_info.md)
+* [`struct mg_server_ports;`](api/mg_server_ports.md)
+
+
+## Library API Functions
+
+* [`mg_init_library( feature );`](api/mg_init_library.md)
+* [`mg_exit_library( feature );`](api/mg_exit_library.md)
+
+* [`mg_check_feature( feature );`](api/mg_check_feature.md)
+* [`mg_version();`](api/mg_version.md)
+
+
+## Server API Functions
+
+* [`mg_start( callbacks, user_data, options );`](api/mg_start.md)
+* [`mg_stop( ctx );`](api/mg_stop.md)
+
+* [`mg_get_builtin_mime_type( file_name );`](api/mg_get_builtin_mime_type.md)
+* [`mg_get_option( ctx, name );`](api/mg_get_option.md)
+* [`mg_get_server_ports( ctx, size, ports );`](api/mg_get_server_ports.md)
+* [`mg_get_user_data( ctx );`](api/mg_get_user_data.md)
+* [`mg_set_auth_handler( ctx, uri, handler, cbdata );`](api/mg_set_auth_handler.md)
+* [`mg_set_request_handler( ctx, uri, handler, cbdata );`](api/mg_set_request_handler.md)
+* [`mg_set_websocket_handler( ctx, uri, connect_handler, ready_handler, data_handler, close_handler, cbdata );`](api/mg_set_websocket_handler.md)
+
+* [`mg_lock_context( ctx );`](api/mg_lock_context.md)
+* [`mg_unlock_context( ctx );`](api/mg_unlock_context.md)
+
+* [`mg_get_context( conn );`](api/mg_get_context.md)
+
+
+## Client API Functions
+
+* [`mg_connect_client( host, port, use_ssl, error_buffer, error_buffer_size );`](api/mg_connect_client.md)
+* [`mg_connect_websocket_client( host, port, use_ssl, error_buffer, error_buffer_size, path, origin, data_func, close_func, user_data);`](api/mg_connect_websocket_client.md)
+* [`mg_websocket_client_write( conn, opcode, data, data_len );`](api/mg_websocket_client_write.md)
+
+* [`mg_download( host, port, use_ssl, error_buffer, error_buffer_size, fmt, ... );`](api/mg_download.md)
+
+
+## Common API Functions
+
+* [`mg_close_connection( conn );`](api/mg_close_connection.md)
+* [`mg_cry( conn, fmt, ... );`](api/mg_cry.md)
+
+* [`mg_get_cookie( cookie, var_name, buf, buf_len );`](api/mg_get_cookie.md)
+* [`mg_get_header( conn, name );`](api/mg_get_header.md)
+* [`mg_get_request_info( conn );`](api/mg_get_request_info.md)
+* [`mg_get_response( conn, ebuf, ebuf_len, timeout );`](api/mg_get_response.md)
+* [`mg_get_response_code_text( conn, response_code );`](api/mg_get_response_code_text.md)
+* [`mg_get_user_connection_data( conn );`](api/mg_get_user_connection_data.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_var2( data, data_len, var_name, dst, dst_len, occurrence );`](api/mg_get_var2.md)
+* [`mg_handle_form_request( conn, fdh );`](api/mg_handle_form_request.md)
+* [`mg_lock_connection( conn );`](api/mg_lock_connection.md)
+* [`mg_md5( buf, ... );`](api/mg_md5.md)
+* [`mg_modify_passwords_file( passwords_file_name, domain, user, password );`](api/mg_modify_passwords_file.md)
+* [`mg_printf( conn, fmt, ... );`](api/mg_printf.md)
+* [`mg_read( conn, buf, len );`](api/mg_read.md)
+* [`mg_send_file( conn, path );`](api/mg_send_file.md)
+* [`mg_send_mime_file( conn, path, mime_type );`](api/mg_send_mime_file.md)
+* [`mg_send_mime_file2( conn, path, mime_type, additional_headers );`](api/mg_send_mime_file2.md)
+* [`mg_set_user_connection_data( conn, data );`](api/mg_set_user_connection_data.md)
+* [`mg_start_thread( f, p );`](api/mg_start_thread.md)
+* [`mg_store_body( conn, path );`](api/mg_store_body.md)
+* [`mg_strcasecmp( s1, s2 );`](api/mg_strcasecmp.md)
+* [`mg_strncasecmp( s1, s2, len );`](api/mg_strncasecmp.md)
+* [`mg_unlock_connection( conn );`](api/mg_unlock_connection.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_websocket_write( conn, opcode, data, data_len );`](api/mg_websocket_write.md)
+* [`mg_write( conn, buf, len );`](api/mg_write.md)
+
+
+## Deprecated:
+
+* [~~`mg_get_valid_option_names();`~~](api/mg_get_valid_option_names.md)
+* [~~`mg_upload( conn, destination_dir );`~~](api/mg_upload.md)

+ 27 - 0
docs/Building.md

@@ -103,6 +103,33 @@ make build WITH_LUA=1
 Note that the WITH_* options used for *make* are not identical to the
 preprocessor defines in the source code - usually USE_* is used there.
 
+## Changing PREFIX
+
+To change the target destination pass the `PREFIX` option to the command `make install` (not `make build`). Example usage:
+
+```
+$ make build
+$ make -n install PREFIX=/opt/civetweb
+```
+Note: The `-n` corresponds to the `--dry-run` option (it does not make any changes): You can see where `make install` would install. Example output of the above command:
+
+```
+$ make -n install PREFIX=/opt/civetweb
+install -d -m 755  "/opt/civetweb/share/doc/civetweb"
+install -m 644 resources/itworks.html /opt/civetweb/share/doc/civetweb/index.html
+install -m 644 resources/civetweb_64x64.png /opt/civetweb/share/doc/civetweb/
+install -d -m 755  "/opt/civetweb/etc"
+install -m 644 resources/civetweb.conf  "/opt/civetweb/etc/"
+sed -i 's#^document_root.*$#document_root /opt/civetweb/share/doc/civetweb#' "/opt/civetweb/etc/civetweb.conf"
+sed -i 's#^listening_ports.*$#listening_ports 8080#' "/opt/civetweb/etc/civetweb.conf"
+install -d -m 755  "/opt/civetweb/share/doc/civetweb"
+install -m 644 *.md "/opt/civetweb/share/doc/civetweb"
+install -d -m 755 "/opt/civetweb/bin"
+install -m 755 civetweb "/opt/civetweb/bin/"
+```
+
+If the output looks good: Just remove the `-n` option to actually install the software on your system.
+
 ## Setting compile flags
 
 Compile flags can be set using the *COPT* make option like so.

+ 1 - 1
docs/Contribution.md

@@ -3,7 +3,7 @@ Contributing to CivetWeb
 
 Contributions to CivetWeb 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 or create a thread on the CivetWeb discussion group. This is required, if the API ([civetweb.h](https://github.com/civetweb/civetweb/blob/master/include/civetweb.h)) is affected.
 - 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.
 - Contributor names are listed in CREDITS.md, unless you explicitly state you don't want your name to be listed there.

+ 49 - 0
docs/Embedding.md

@@ -198,3 +198,52 @@ All accepted sockets have `SO_RCVTIMEO` and `SO_SNDTIMEO` socket options set
 (controlled by the `request_timeout_ms` CivetWeb option, 30 seconds default)
 which specifies a read/write timeout on client connections.
 
+
+A minimal example
+------
+
+Initializing a HTTP server
+```C
+{
+	/* Server context handle */
+	struct mg_context *ctx;
+
+    /* Initialize the library */
+    mg_init_library(0);
+
+    /* Start the server */
+	ctx = mg_start(NULL, 0, NULL);
+
+    /* Add some handler */
+    mg_set_request_handler(ctx, "/hello", handler, "Hello world");
+
+    ... Run the application ...
+    
+	/* Stop the server */
+	mg_stop(ctx);
+
+    /* Un-initialize the library */
+    mg_exit_library();
+}
+```
+
+A simple callback
+```C
+static int
+handler(struct mg_connection *conn, void *ignored)
+{
+	const char *msg = "Hello world";
+	unsigned long len = (unsigned long)strlen(msg);
+
+	mg_printf(conn,
+	          "HTTP/1.1 200 OK\r\n"
+	          "Content-Length: %lu\r\n"
+	          "Content-Type: text/plain\r\n"
+	          "Connection: close\r\n\r\n",
+	          len);
+
+	mg_write(conn, msg, len);
+
+	return 200;
+}
+```

+ 3 - 2
docs/Installing.md

@@ -10,8 +10,9 @@ This pre-built version comes pre-built wit Lua support. Libraries for SSL suppor
 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)
+1. In case the Visual C++ Redistributable are not already installed:
+  32 Bit Version: Install the [Redistributable for Visual Studio 2010](http://www.microsoft.com/en-us/download/details.aspx?id=8328)
+  64 Bit Version: Install the [Redistributable for Visual Studio 2015](http://www.microsoft.com/en-us/download/details.aspx?id=48145)
 2. Download latest *civetweb-win.zip* from [SourceForge](https://sourceforge.net/projects/civetweb/files/)
 3. When started, Civetweb puts itself into the tray.
 

+ 70 - 0
docs/Interface_Changes_1.10.md

@@ -0,0 +1,70 @@
+# Interface changes
+
+## Proposed interface changes for 1.10
+
+Status: To be discussed
+
+### Server interface
+
+#### mg\_start / mg\_init\_library
+
+Calling mg\_init\_library is recommended before calling mg\_start.
+
+Compatibility:
+Initially, mg\_init\_library will be called implicitly if it has 
+not been called before mg\_start.
+If mg\_init\_library was not called, mg\_stop may leave memory leaks.
+
+#### mg\_websocket\_write functions
+
+Calling mg\_lock\_connection is no longer called implicitly
+in mg\_websocket\_write functions. 
+If you use websocket write functions them from two threads,
+you must call mg\_lock\_connection explicitly, just like for any
+other connection.
+
+This is an API harmonization issue.
+
+Compatibility:
+If a websocket connection was used in only one thread, there is
+no incompatibility. If a websocket connection was used in multiple
+threads, the user has to add the mg\_lock\_connection before and
+the mg\_unlock\_connection after the websocket write call.
+
+#### open\_file member of mg\_callbacks
+
+This member is going to be removed.
+It is superseeded by mg\_add\_request\_handler.
+
+Compatibility:
+Current code using open\_file needs to be changed.
+Instructions how to do this will be provided.
+
+
+### Client interface
+
+
+#### mg\_init\_library
+
+Calling mg\_init\_library is required before calling any client
+function. In particular, the TLS initialization must be done
+before using mg\_connect\_client\_secure.
+
+Compatibility:
+Some parts of the client interface did not work, if mg\_start
+was not called before. Now server and client become independent.
+
+#### mg\_connect\_client (family)
+
+mg_connect_client needs several new parameters (options).
+
+Details are to be defined.
+
+mg_connect_client and mg_download should return a different kind of
+mg_connection than used in server callbacks. At least, there should
+be a function mg_get_response_info, instead of using 
+mg_get_request_info, and getting the HTTP response code from the
+server by looking into the uri member of struct mg_request_info.
+
+
+

+ 40 - 0
docs/README.md

@@ -0,0 +1,40 @@
+![CivetWeb](https://raw.github.com/civetweb/civetweb/master/resources/civetweb_64x64.png "CivetWeb") CivetWeb
+=======
+
+CivetWeb is an easy to use, powerful, C/C++ embeddable web server with optional CGI, SSL and Lua support.
+
+CivetWeb can be used by developers as a library, to add web server functionality to an existing application.
+CivetWeb uses an [MIT license](https://github.com/civetweb/civetweb/blob/master/LICENSE.md).
+
+It can also be used by end users as a stand-alone web server. It is available as single executable, no installation is required.
+
+The current stable version is 1.9.1 - [release notes](https://github.com/civetweb/civetweb/blob/master/RELEASE_NOTES.md)
+
+
+End users can download CivetWeb at SourceForge
+[https://sourceforge.net/projects/civetweb/](https://sourceforge.net/projects/civetweb/)
+
+Developers can contribute to CivetWeb via GitHub
+[https://github.com/civetweb/civetweb](https://github.com/civetweb/civetweb)
+
+Trouble tickets should be filed on GitHub
+[https://github.com/civetweb/civetweb/issues](https://github.com/civetweb/civetweb/issues)
+
+Discussion/support group and announcements are at Google Groups
+[https://groups.google.com/d/forum/civetweb](https://groups.google.com/d/forum/civetweb)
+
+Source releases can be found on GitHub
+[https://github.com/civetweb/civetweb/releases](https://github.com/civetweb/civetweb/releases)
+
+
+Documentation
+---------------
+
+- [Installing.md](Installing.md) - Install Guide (for end users using pre-built binaries)
+- [UserManual.md](UserManual.md) - End User Guide
+- [Building.md](Building.md) - Building the Server (quick start guide)
+- [Embedding.md](Embedding.md) - Embedding (how to add HTTP support to an existing application)
+- [OpenSSL.md](OpenSSL.md) - Adding HTTPS (SSL/TLS) support using OpenSSL.
+- [API documentation](api) - Additional documentation on the civetweb application programming interface ([civetweb.h](https://github.com/civetweb/civetweb/blob/master/include/civetweb.h)).
+
+[Authors](https://github.com/civetweb/civetweb/blob/master/CREDITS.md)

+ 80 - 5
docs/UserManual.md

@@ -235,12 +235,19 @@ are additional default index files, ordered before `index.cgi`.
 ### enable\_keep\_alive `no`
 Enable connection keep alive, either `yes` or `no`.
 
-Experimental feature. Allows clients to reuse TCP connection for subsequent
-HTTP requests, which improves performance.
+Allows clients to reuse TCP connection for subsequent HTTP requests, 
+which improves performance.
 For this to work when using request handlers it is important to add the
 correct Content-Length HTTP header for each request. If this is forgotten the
 client will time out.
 
+Note: If you set keep\_alive to `yes`, you should set keep\_alive\_timeout\_ms
+to some value > 0 (e.g. 500). If you set keep\_alive to `no`, you should set
+keep\_alive\_timeout\_ms to 0. Currently, this is done as a default value,
+but this configuration is redundant. In a future version, the keep\_alive 
+configuration option might be removed and automatically set to `yes` if 
+a timeout > 0 is set.
+
 ### access\_control\_list
 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
@@ -349,13 +356,47 @@ 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
 must be for a file name only, not including directory names. Example:
 
-    civetweb -hide_files_patterns secret.txt|*.hide
+    civetweb -hide_files_patterns secret.txt|**.hide
+
+Note: hide\_file\_patterns uses the pattern described above. If you want to
+hide all files with a certain extension, make sure to use **.extension
+(not just *.extension).
 
 ### request\_timeout\_ms `30000`
 Timeout for network read and network write operations, in milliseconds.
 If a client intends to keep long-running connection, either increase this
 value or (better) use keep-alive messages.
 
+### keep\_alive\_timeout\_ms `500` or `0`
+Idle timeout between two requests in one keep-alive connection.
+If keep alive is enabled, multiple requests using the same connection 
+are possible. This reduces the overhead for opening and closing connections
+when loading several resources from one server, but it also blocks one port
+and one thread at the server during the lifetime of this connection.
+Unfortunately, browsers do not close the keep-alive connection after loading
+all resources required to show a website.
+The server closes a keep-alive connection, if there is no additional request
+from the client during this timeout.
+
+Note: if enable\_keep\_alive is set to `no` the value of 
+keep\_alive\_timeout\_ms should be set to `0`, if enable\_keep\_alive is set 
+to `yes`, the value of keep\_alive\_timeout\_ms must be >0.
+Currently keep\_alive\_timeout\_ms is ignored if enable\_keep\_alive is no,
+but future versions my drop the enable\_keep\_alive configuration value and
+automatically use keep-alive if keep\_alive\_timeout\_ms is not 0.
+
+### linger\_timeout\_ms
+Set TCP socket linger timeout before closing sockets (SO\_LINGER option).
+The configured value is a timeout in milliseconds. Setting the value to 0
+will yield in abortive close (if the socket is closed from the server side).
+Setting the value to -1 will turn off linger.
+If the value is not set (or set to -2), CivetWeb will not set the linger
+option at all.
+
+Note: For consistency with other timeouts, the value is configured in
+milliseconds. However, the TCP socket layer usually only offers a timeout in 
+seconds, so the value should be an integer multiple of 1000.
+
 ### lua\_preload\_file
 This configuration option can be used to specify a Lua script file, which
 is executed before the actual web page script (Lua script, Lua server page
@@ -377,6 +418,18 @@ directly to the client. Lua script parts are delimited from the standard
 content by including them between <? and ?> tags.
 An example can be found in the test directory.
 
+### lua\_background\_script
+Experimental feature, and subject to change.
+Run a Lua script in the background, independent from any connection.
+The script is started before network access to the server is available.
+It can be used to prepare the document root (e.g., update files, compress
+files, ...), check for external resources, remove old log files, etc.
+
+The Lua state remains open until the server is stopped.
+In the future, some callback functions will be available to notify the
+script on changes of the server state.
+
+
 ### websocket\_root
 In case civetweb is built with Lua and websocket support, Lua scripts may
 be used for websockets as well. Since websockets use a different URL scheme
@@ -420,6 +473,18 @@ This value should not exceed one year (RFC 2616, Section 14.21).
 A value of 0 will send "do not cache" headers for all static files.
 For values <0 and values >31622400, the behavior is undefined.
 
+### strict\_transport\_security\_max\_age
+
+Set the `Strict-Transport-Security` header, and set the `max-age` value.
+This instructs web browsers to interact with the server only using HTTPS,
+never by HTTP. If set, it will be sent for every request handled directly
+by the server, except scripts (CGI, Lua, ..) and callbacks. They must 
+send HTTP headers on their own.
+
+The time is specified in seconds. If this configuration is not set, 
+or set to -1, no `Strict-Transport-Security` header will be sent.
+For values <-1 and values >31622400, the behavior is undefined.
+
 ### decode\_url `yes`
 URL encoded request strings are decoded in the server, unless it is disabled
 by setting this option to `no`.
@@ -485,6 +550,13 @@ This option can be used to enable or disable the use of the Linux `sendfile` sys
 ### case\_sensitive `no`
 This option can be uset to enable case URLs for Windows servers. It is only available for Windows systems. Windows file systems are not case sensitive, but they still store the file name including case. If this option is set to `yes`, the comparison for URIs and Windows file names will be case sensitive.
 
+### additional\_header
+Send additional HTTP response header line for every request.
+The full header line including key and value must be specified, excluding the carriage return line feed.
+
+Example:
+"X-Frame-Options: SAMEORIGIN"
+
 
 # Lua Scripts and Lua Server Pages
 Pre-built Windows and Mac civetweb binaries have built-in Lua scripting
@@ -551,7 +623,7 @@ mg (table):
 
     mg.read()                  -- reads a chunk from POST data, returns it as a string
     mg.write(str)              -- writes string to the client
-    mg.include(path)           -- sources another Lua file
+    mg.include(filename)       -- include another Lua Page file (Lua Pages only)
     mg.redirect(uri)           -- internal redirect to a given URI
     mg.onerror(msg)            -- error handler, can be overridden
     mg.version                 -- a string that holds Civetweb version
@@ -599,10 +671,13 @@ connect (function):
     end
 
 
+All filename arguments are either absolute or relative to the civetweb working
+directory (not the document root or the Lua script/page file).
+    
 **IMPORTANT: Civetweb does not send HTTP headers for Lua pages. Therefore,
 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') ?>
+    <? mg.write('HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n') ?>
     <html><body>
       ... the rest of the web page ...
 

+ 1 - 0
docs/_config.yml

@@ -0,0 +1 @@
+theme: jekyll-theme-tactile

+ 21 - 0
docs/api/client_cert.md

@@ -0,0 +1,21 @@
+# Civetweb API Reference
+
+### `struct client_cert;`
+
+### Fields
+
+| Field | Type | Description |
+| :--- | :--- | :--- |
+|**`subject`**|`const char *`| The subject of the certificate |
+|**`issuer`**|`const char *`| The issuer of the certificate |
+|**`serial`**|`const char *`| The serial number of the certificate |
+|**`finger`**|`const char *`| The fingerprint of the certificate |
+
+### Description
+
+The structure `client_cert` is used as a sub-structure in the [`mg_request_info`](mg_request_info.md) structure to store information of an optional client supplied certificate.
+
+### See Also
+
+* [`struct mg_request_info;`](mg_request_info.md)
+* [`mg_get_request_info();`](mg_get_request_info.md)

+ 60 - 0
docs/api/mg_callbacks.md

@@ -0,0 +1,60 @@
+# Civetweb API Reference
+
+### `struct mg_callbacks;`
+
+### Fields
+
+| Field | Description |
+| :--- | :--- |
+|**`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. |
+|**`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.*|
+|**`end_request`**|**`void (*end_request)(const struct mg_connection *conn, int reply_status_code);`**|
+| |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.|
+|**`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.|
+|**`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.|
+|**`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.|
+|**`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.|
+|**`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.|
+|**`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:|
+| |**0** - The master thread is created |
+| |**1** - A worker thread which handles client connections 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 );`**|
+| |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.|
+|**`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.|
+|**`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 implemented 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 );`**|
+| |*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.|
+|~~`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: |
+| |**0** - CivetWeb can proceed with the handshake to accept the connection |
+| |**1** - CivetWeb 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 );`**|
+| |*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. |
+| | **`data`** - The pointer to the received data block. Masks--if any--have already been applied. |
+| | **`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.|
+|~~`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. |
+
+### 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.
+
+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.
+
+### See Also
+
+* [`mg_start();`](mg_start.md)
+* [`mg_stop();`](mg_stop.md)

+ 40 - 0
docs/api/mg_check_feature.md

@@ -0,0 +1,40 @@
+# Civetweb API Reference
+
+### `mg_check_feature( feature );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`feature`**|`unsigned`| A value indicating the feature to be checked |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`unsigned`| A value indicating if a feature is available. A positive value indicates available, while **0** is returned for an unavailable feature |
+
+### 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 following parameter values can be used:
+
+| 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. |
+| **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. |
+| **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. |
+| **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. |
+| **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. |
+| **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. |
+
+Parameter values other than the values mentioned above will give undefined results. Therefore&mdash;although the parameter values for the `mg_check_feature()` function are effectively bitmasks, you should't assume that combining two of those values with an OR to a new value will give any meaningful results when the function returns.
+
+### See Also
+
+* [`mg_get_option();`](mg_get_option.md)
+* [~~`mg_get_valid_option_names();`~~](mg_get_valid_option_names.md)
+* [`mg_get_valid_options();`](mg_get_valid_options.md)

+ 21 - 0
docs/api/mg_client_options.md

@@ -0,0 +1,21 @@
+# Civetweb API Reference
+
+### `struct mg_client_options;`
+
+### Fields
+
+| Field | Type | Description |
+| :--- | :--- | :--- |
+|**`host`**|`const char *`|The hostname or IP address to connect to|
+|**`port`**|`int`|The port on the server|
+|**`client_cert`**|`const char *`|Pointer to client certificate|
+|**`server_cert`**|`const char *`|Pointer to a server certificate|
+
+### Description
+
+The the `mgclient_options` structure contains host and security information to connect as a client to another host. A parameter of this type is used in the call to the function [`mg_connect_client_secure();`](mg_connect_client_secure.md). Please note that IPv6 addresses are only permitted if IPv6 support was enabled during compilation. You can use the function [`mg_check_feature()`](mg_check_feature.md) with the parameter `USE_IPV6` while running your application to check if IPv6 is supported.
+
+### See Also
+
+* [`mg_check_feature();`](mg_check_feature.md)
+* [`mg_connect_client_secure();`](mg_connect_client_secure.md)

+ 21 - 0
docs/api/mg_close_connection.md

@@ -0,0 +1,21 @@
+# Civetweb API Reference
+
+### `mg_close_connection( conn );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection which must be closed|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_close_connection()` is used to close a connection which was opened with the [`mg_download()`](mg_download.md) function. Use of this function to close a connection which was opened in another way is undocumented and may give unexpected results.
+
+### See Also
+
+* [`mg_download();`](mg_download.md)

+ 29 - 0
docs/api/mg_connect_client.md

@@ -0,0 +1,29 @@
+# Civetweb API Reference
+
+### `mg_connect_client( host, port, use_ssl, error_buffer, error_buffer_size );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`host`**|`const char *`|hostname or IP address of the server|
+|**`port`**|`int`|The port to connect to on the server|
+|**`use_ssl`**|`int`|Connects using SSL of this value is not zero|
+|**`error_buffer`**|`char *`|Buffer to store an error message|
+|**`error_buffer_size`**|`size_t`|Maximum size of the error buffer including the NUL terminator|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`struct mg_connection *`||
+
+### 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.
+ 
+### See Also
+
+* [`mg_check_feature();`](mg_check_feature.md)
+* [`mg_connect_client_secure();`](mg_connect_client_secure.md)
+* [`mg_connect_websocket_client();`](mg_connect_websocket_client.md)

+ 30 - 0
docs/api/mg_connect_client_secure.md

@@ -0,0 +1,30 @@
+# Civetweb API Reference
+
+### `mg_connect_client_secure( client_options, error_buffer, error_buffer_size );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`client_options`**|`const struct mg_client_options *`|Settings about the server connection|
+|**`error_buffer`**|`char *`|Buffer to store an error message|
+|**`error_buffer_size`**|`size_t`|Size of the error message buffer including the NUL terminator|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`struct mg_connection *`||
+
+### Description
+
+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.
+
+### See Also
+
+* [`struct mg_client_options;`](mg_client_options.md)
+* [`mg_check_feature();`](mg_check_feature.md)
+* [`mg_connect_client();`](mg_connect_client.md)
+* [`mg_connect_websocket_client();`](mg_connect_websocket_client.md)

+ 36 - 0
docs/api/mg_connect_websocket_client.md

@@ -0,0 +1,36 @@
+# Civetweb API Reference
+
+### `mg_connect_websocket_client( host, port, use_ssl, error_buffer, error_buffer_size, path, origin, data_func, close_func, user-data);`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`host`**|`const char *`|The hostname or IP address of the server|
+|**`port`**|`int`|The port on the server|
+|**`use_ssl`**|`int`|Use SSL if this parameter is not equal to zero|
+|**`error_buffer`**|`char *`|Buffer to store an error message|
+|**`error_buffer_size`**|`size_t`|Size of the error message buffer including the NUL terminator|
+|**`path`**|`const char *`|The server path to connect to, for example `/app` if you want to connect to `localhost/app`|
+|**`origin`**|`const char *`|The value of the `Origin` HTTP header|
+|**`data_func`**|`mg_websocket_data_handler`|Callback which is used to process data coming back from the server|
+|**`close_func`**|`mg_websocket_close_handler`|Callback which is called when the connection is to be closed|
+|**`user_data`**|`void *`|User supplied argument|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`struct mg_connection *`|A pointer to the connection structure, or NULL if connecting failed|
+
+### Description
+
+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.
+
+### See Also
+
+* [`mg_check_feature();`](mg_check_feature.md)
+* [`mg_connect_client();`](mg_connect_client.md)
+* [`mg_connect_client_secure();`](mg_connect_client_secure.md)

+ 23 - 0
docs/api/mg_cry.md

@@ -0,0 +1,23 @@
+# Civetweb API Reference
+
+### `mg_cry( conn, fmt, ... );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`const struct mg_connection *`|The connection on which a problem occured|
+|**`fmt`**|`const char *`|Format string without a line return|
+|**`...`**|*various*|Parameters depending on the format string|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_cry()` is called when something happens on a connection. The function takes a format string similar to the `printf()` series of functions with parameters and creates a text string which can then be used for logging. The `mg_cry()` function prints the output to the opened error log stream. Log messages can be processed with the `log_message()` callback function specified in the `struct mg_callbacks` structure.
+
+### See Also
+
+* [`struct mg_callbacks;`](mg_callbacks.md)

+ 37 - 0
docs/api/mg_download.md

@@ -0,0 +1,37 @@
+# Civetweb API Reference
+
+### `mg_download( host, port, use_ssl, error_buffer, error_buffer_size, fmt, ... );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`host`**|`const char *`|The hostname or IP address of the server|
+|**`port`**|`int`|The port number on the server|
+|**`use_ssl`**|`int`|Use SSL if this value is not equal zero|
+|**`error_buffer`**|`char *`|Buffer to store an error message|
+|**`error_buffer_size`**|`size_t`|Size of the error message buffer including the terminating NUL|
+|**`fmt`**|`const char *`|Format string specifying the remote command to execute|
+|**`...`**|*various*|Parameters used in the format string|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`struct mg_connection *`|A pointer to the connection structure if successful and NULL otherwise|
+
+### Description
+
+The `mg_download()` function is used to download data from a remote webserver. The server address can either be specified as a hostname or IP address and SSL can be used if needed. If the function succeeds, a pointer is returned to a connection structure. The connection must be closed with a call to the [`mg_close_connection()`](mg_close_connection.md) function.
+
+The format string is a format string from the `printf()` series of functions to specify the remote command. An example to get the main index page from Google is the following call:
+
+`conn = mg_download( "google.com", 80, 0, ebuf, sizeof(ebuf),
+                     "%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`.
+
+### See Also
+
+* [`mg_check_feature();`](mg_check_feature.md)
+* [`mg_close_connection();`](mg_close_connection.md)

+ 29 - 0
docs/api/mg_exit_library.md

@@ -0,0 +1,29 @@
+# Civetweb API Reference
+
+### `mg_exit_library( );`
+
+### Parameters
+
+none
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`unsigned`| **0** is returned or error |
+
+### Description
+
+The function `mg_exit_library()` should be called from an application program, when the library should be unloaded.
+It must be called only from one thread (it is not guaranteed to be thread safe).
+
+Only use `mg_exit_library( );` when you used [`mg_init_library( feature );`](api/mg_init_library.md) before.
+
+The library init and exit functions are new in version 1.9 (as dummy implementation) and effective only from version 1.10.
+For compatibility reasons, other functions (such as [`mg_start();`](mg_start.md)) will initialize the required features as well,
+but they will no longer do a de-initialization, leaving a memory leak when the library is unloaded.
+
+### See Also
+
+* [`mg_init_library( feature );`](mg_init_library.md)
+* [`mg_check_feature( feature );`](mg_check_feature.md)

+ 36 - 0
docs/api/mg_form_data_handler.md

@@ -0,0 +1,36 @@
+# Civetweb API Reference
+
+### `struct mg_form_data_handler;`
+
+### Fields
+
+|Field|Description|
+|:---|:---|
+|**`field_found`**|**`int field_found( const char *key, const char *filename, char *path, size_t pathlen, void *user_data )`**;|
+||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.|
+||**`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.|
+||**`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`.|
+||The callback function `field_found()` can return the following values back to Civetweb:|
+||**`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_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|
+|**`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 );`**|
+||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:|
+||**`path`** -|
+||**`file_size`** - The path on the server where the file was stored|
+||**`user_data`** - The size of the stored file in bytes|
+|**`user_data`**|**`void *`** The value of the field `user_data` when the callback functions were registered with a call to `mg_handle_form_request();`|
+||The `user_data` field is a user supplied argument that will be passed as parameter to each of callback functions|
+
+### Description
+
+The structure `struct mg_form_data_handler` contains callback functions for handling form fields. Form fields give additional information back from a web page to the server which can be processed by these callback functions.
+
+### See Also
+
+* [`mg_handle_form_request();`](mg_handle_form_request.md)

+ 24 - 0
docs/api/mg_get_builtin_mime_type.md

@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `mg_get_builtin_mime_type( file_name );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`file_name`**|`const char *`|The name of the file for which the MIME type has to be determined|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`const char *`|A text string describing the MIME type|
+
+### Description
+
+The function `mg_get_builtin_mime_type()` tries to determine the MIME type of a given file. If the MIME type cannot be determined, the value `text/plain` is returned. Please note that this function does not an intelligent check of the file contents. The MIME type is solely determined based on the file name extension.
+
+### See Also
+
+* [`mg_send_mime_file();`](mg_send_mime_file.md)
+* [`mg_send_mime_file2();`](mg_send_mime_file2.md)

+ 24 - 0
docs/api/mg_get_context.md

@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `mg_get_context( conn );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`const struct mg_connection *`|The connection for which the context has to be returned|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`struct mg_context *`|A pointer to the context of the given connection|
+
+### Description
+
+The function `mg_get_context()` returns the context associated with a connection.
+
+### See Also
+
+* [`mg_start();`](mg_start.md)
+* [`mg_stop();`](mg_stop.md)

+ 26 - 0
docs/api/mg_get_context_info.md

@@ -0,0 +1,26 @@
+# Civetweb API Reference
+
+### `mg_get_context_info( ctx, buffer, buflen );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`struct mg_context *`|The server context handle|
+|**`buffer**|`char *`|A string buffer to store the information|
+|**`buflen**|`int`|Size of the string buffer (including space for a terminating 0)|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Available context information in bytes (excluding the terminating 0)|
+
+### Description
+
+The function `mg_get_context_info()` returns statistics information collected for the server context. This may be empty if the server has not been built with statistics support (`#define USE_SERVER_STATS`). Otherwise the returned string is in JSON format.
+
+### See Also
+
+* [`mg_get_system_info();`](mg_get_system_info.md)
+

+ 29 - 0
docs/api/mg_get_cookie.md

@@ -0,0 +1,29 @@
+# Civetweb API Reference
+
+### `mg_get_cookie( cookie, var_name, buf, buf_len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`cookie`**|`const char *`|The cookie name|
+|**`var_name`**|`const char *`|The variable name|
+|**`buf`**|`char *`|The buffer where to store the contents of the cookie|
+|**`buf_len`**|`size_t`|The length of the cookie buffer, including the terminating NUL|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|The length of the cookie or an error code|
+
+### Description
+
+The function `mg_get_cookie()` tries to fetch the value of a certain cookie variable. The contents will either be stored in an application provided buffer, or an error code will be returned. The destination buffer is guaranteed to be NUL terminated if the pointer of the buffer is not a NULL pointer and the size of the buffer is at least one byte.
+
+If the function succeeds, the return value of the function is the length in bytes of the cookie. The value **`-1`** is returned if the requested cookie could not be found and **`-2`** if the destination buffer is represented by a NULL pointer, is zero length or too short to store the whole cookie.
+
+### See Also
+
+* [`mg_get_var();`](mg_get_var.md)
+* [`mg_get_var2();`](mg_get_var2.md)

+ 22 - 0
docs/api/mg_get_header.md

@@ -0,0 +1,22 @@
+# Civetweb API Reference
+
+### `mg_get_header( conn, name );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`| A pointer referencing the connection |
+|**`name`**|`const char *`| The name of the request header |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`const char *`| A pointer to the value of the request header, or NULL of no matching header count be found |
+
+### Description
+
+HTTP and HTTPS clients can send request headers to the server to provide details about the communication. These request headers can for example specify the preferred language in which the server should respond and the supported compression algorithms. The function `mg_get_header()` can be called to return the contents of a specific request header. The function will return a pointer to the value text of the header when succesful, and NULL of no matching request header from the client could be found.
+
+### See Also

+ 24 - 0
docs/api/mg_get_option.md

@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `mg_get_option( ctx, name );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`const struct mg_context *`| A pointer to the webserver context |
+|**`name`**|`const char *`| The name of the option to query |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`const char *`| A pointer to the option value in text, or NULL if an error occured |
+
+### 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.
+
+### See Also
+
+* [`mg_start();`](mg_start.md)

+ 31 - 0
docs/api/mg_get_ports.md

@@ -0,0 +1,31 @@
+# Civetweb API Reference
+
+### ~~`mg_get_ports( ctx, size, ports, ssl );`~~
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`const struct mg_context *`||
+|**`size`**|`size_t`|The number of ports which can be stored in the buffer|
+|**`ports`**|`int *`|Buffer for storage of the port numbers|
+|**`ssl`**|`int *`|Buffer used to store if SSL is used for the ports|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`size_t`|The number of ports stored in the buffer|
+
+### Description
+
+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 returns the number of ports actually stored in the buffer.
+
+### See Also
+
+* [`struct mg_server_ports;`](mg_server_ports.md)
+* [`mg_get_server_ports();`](mg_get_server_ports.md)

+ 23 - 0
docs/api/mg_get_request_info.md

@@ -0,0 +1,23 @@
+# Civetweb API Reference
+
+### `mg_get_request_info( conn );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`const struct mg_connection *`|The connection for which the request info is needed|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`const struct mg_request_info *`|Pointer to the requested info, or NULL if an error occured|
+
+### Description
+
+The function `mg_get_request_info()` returns information about the request on a given connection. This information is returned as a pointer to a [`mg_request_info`](mg_request_info.md) structure. If an error occurs, a NULL pointer is returned instead.
+
+### See Also
+
+* [`struct mg_request_info;`](mg_request_info.md)

+ 29 - 0
docs/api/mg_get_request_link.md

@@ -0,0 +1,29 @@
+# Civetweb API Reference
+
+### `mg_get_request_link( conn, buf, buflen );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`| A pointer referencing the connection |
+|**`buf`**|`char *`| A buffer to store the link |
+|**`buflen`**|`size_t`| Size of the buffer |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`| Return code: <0 for error, >=0 for success |
+
+### Description
+
+Store a formatted link corresponding to the current request.
+
+E.g., returns
+`http://mydomain.com:8080/path/to/callback.ext`
+or 
+`http://127.0.0.1:8080/path/to/callback.ext`
+depending on the auth check settings.
+
+### See Also

+ 29 - 0
docs/api/mg_get_response.md

@@ -0,0 +1,29 @@
+# Civetweb API Reference
+
+### `mg_get_response( conn, ebuf, ebuf_len, timeout );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection to listen on|
+|**`ebuf`**|`char *`|Buffer to store an error message|
+|**`ebuf_len`**|`size_t`|Size of the error message buffer including the terminating NUL|
+|**`timeout`**|`int`|Time to wait for a response in milliseconds|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Success value of the wait|
+
+### Description
+
+The function `mg_get_reponse()` wait for a response from a remote server. A return value equal or greater than zero is an indication for success, a negative value us used to signal an error condition. A timeout can be specified which lets the function return after a specified number of milliseconds, even if no data is received from the remote party. If the timeout value is negative, the function will not return until data has been read or an unrecoverable error occurs.
+
+Error messages are stored in a caller supplied error message buffer.
+
+### See Also
+
+* [`mg_connect_client();`](mg_connect_client.md)
+* [`mg_connect_client_secure();`](mg_connect_client_secure.md)

+ 25 - 0
docs/api/mg_get_response_code_text.md

@@ -0,0 +1,25 @@
+# Civetweb API Reference
+
+### `mg_get_response_code_text( conn, response_code );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`| A pointer referencing the connection |
+|**`response_code`**|`int`| Response code for which the text is queried |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`const char *`| A pointer to a human readable text explaining the response code. |
+
+### Description
+
+The function `mg_get_response_code_text()` returns a pointer to a human readable text describing the HTTP response code which was provided as a parameter.
+
+### See Also
+
+* [`mg_get_builtin_mime_type();`](mg_get_builtin_mime_type.md)
+* [`mg_version();`](mg_version.md)

+ 28 - 0
docs/api/mg_get_server_ports.md

@@ -0,0 +1,28 @@
+# Civetweb API Reference
+
+### `mg_get_server_ports( ctx, size, ports );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`const struct mg_context *`|The context for which the server ports are requested|
+|**`size`**|`int`|The size of the buffer to store the port information|
+|**`ports`**|`struct mg_server_ports *`|Buffer to store the port information|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|The actual number of ports returned, or an error condition|
+
+### 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 function returns the number of items in the list, or a negative value if an error occured.
+
+### See Also
+
+* [~~`mg_get_ports();`~~](mg_get_ports.md)
+* [`struct mg_server_ports;`](mg_server_ports.md)

+ 25 - 0
docs/api/mg_get_system_info.md

@@ -0,0 +1,25 @@
+# Civetweb API Reference
+
+### `mg_get_system_info( buffer, buflen );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`buffer**|`char *`|A string buffer to store the information|
+|**`buflen**|`int`|Size of the string buffer (including space for a terminating 0)|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Available system information in bytes (excluding the terminating 0)|
+
+### Description
+
+The function `mg_get_system_info()` returns information collected for the system (operating system, compiler, version, ...). The string is in a human readable format - changes in the format are possible in future versions. This string should be included for support requests.
+
+### See Also
+
+* [`mg_get_context_info();`](mg_get_context_info.md)
+

+ 23 - 0
docs/api/mg_get_user_connection_data.md

@@ -0,0 +1,23 @@
+# Civetweb API Reference
+
+### `mg_get_user_connection_data( conn );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`const struct mg_connection *`|The connection for which to return the user data|
+
+### Return Value
+
+| Type | Description | 
+| :--- | :--- |
+|`void *`|A pointer to the user data, or NULL if no user data was registered with the connection|
+
+### Description
+
+The function `mg_get_user_connection_data()` returns the user data associated with a connection. This user data is represented with a pointer which has been prevously registered with a call to [`mg_set_user_connection_data();`](mg_set_user_connection_data.md). With this function it is possible to pass state information between callback functions refering to a specific connection.
+
+### See Also
+
+* [`mg_set_user_connection_data();`](mg_set_user_connection_data.md)

+ 23 - 0
docs/api/mg_get_user_data.md

@@ -0,0 +1,23 @@
+# Civetweb API Reference
+
+### `mg_get_user_data( ctx );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`const struct mg_context *`|The context for which the user data is requested|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`void *`||
+
+### 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.
+
+### See Also
+
+* [`mg_start();`](mg_start.md)

+ 24 - 0
docs/api/mg_get_valid_option_names.md

@@ -0,0 +1,24 @@
+# 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)

+ 22 - 0
docs/api/mg_get_valid_options.md

@@ -0,0 +1,22 @@
+# Civetweb API Reference
+
+### `mg_get_valid_options();`
+
+### Parameters
+
+*none*
+
+### Return Value
+
+| Type | Description | 
+| :--- | :--- |
+|`const struct mg_option *`|An array with all valid configuration options|
+
+### 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).
+
+### See Also
+
+* [`struct mg_option;`](mg_option.md)
+* [`mg_start();`](mg_start.md)

+ 30 - 0
docs/api/mg_get_var.md

@@ -0,0 +1,30 @@
+# Civetweb API Reference
+
+### `mg_get_var( data, data_len, var_name, dst, dst_len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`data`**|`const char *`|Encoded buffer from either POST data or the URI of a GET call|
+|**`data_len`**|`size_t`|Size of the encode buffer including the terminating NULL|
+|**`var_name`**|`const char *`|Name of the variable to search for|
+|**`dst`**|`char *`|Output buffer to store the content of the variable|
+|**`dst_len`**|`size_t`|Length of the output buffer|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|The length of the variable or an error code|
+
+### Description
+
+The function `mg_get_var()` returns the value of a variable which is passed to the server with either a POST method, or as a parameter in the URI of a GET call. The data pointer passed to the function points to a form-URI encoded buffer. This can either be POST data or the `request_info.query_string`. The name of the searched variable and a buffer to store the results are also parameters to the function.
+
+The function either returns the length of the variable when successful, **`-1`** if the variable could not be found and **`-2`** if the destination buffer is NULL, has size zero or is too small to store the resulting variable value.
+
+### See Also
+
+* [`mg_get_cookie();`](mg_get_cookie.md)
+* [`mg_get_var2();`](mg_get_var2.md)

+ 31 - 0
docs/api/mg_get_var2.md

@@ -0,0 +1,31 @@
+# Civetweb API Reference
+
+### `mg_get_var2( data, data_len, var_name, dst, dst_len, occurrence );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`data`**|`const char *`|Encoded data buffer from either POST data or a GET URI|
+|**`data_len`**|`size_t`|The size of the encoded data buffer|
+|**`var_name`**|`const char *`|The name of the variable to search for|
+|**`dst`**|`char *`|Destination buffer to store the variable content|
+|**`dst_len`**|`size_t`|The size of the destination buffer including the terminating NUL|
+|**`occurrence`**|`size_t`|The instance index of the wanted variable|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Length of the variable contents, or an error code|
+
+### Description
+
+The function `mg_get_var2()` can be used to return the contents of a variable passed to the server as either POST data, or in the URI in a GET call. The function is somilar to [`mg_get_var()`](mg_get_var.md) but the difference is that `mg_get_var2()` can be used if the same variable is present multiple times in the data. The `occurence` parameter is used to identify which instance of the variable must be returned where **`0`** is used for the first variable with the specified name, **`1`** for the second and so on.
+
+The function returns the length of the variable content in the return buffer, **`-1`** if a variable with the specified name could not be found and **`-2`** if the pointer to the result buffer is NULL, the size of the result buffer is zero or when the result buffer is too small to contain the variable content and terminating NUL.
+
+### See Also
+
+* [`mg_get_cookie();`](mg_get_cookie.md)
+* [`mg_get_var();`](mg_get_var.md)

+ 24 - 0
docs/api/mg_handle_form_request.md

@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `mg_handle_form_request( conn, fdh );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection on which form data must be processed|
+|**`fdh`**|`struct mg_form_data_handler`|Structure with callback functions to to the heavy work|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|The number of fields processed, or an error code|
+
+### Description
+
+The function `mg_handle_form_request()` processes form data on a connection. The function uses callback functions for the heavy lifting which are passed to the function as fields in a [`struct mg_form_data_handler`](mg_form_data_handler.md) structure. The number of processed fields is returned by the function, or a negative value when an error occured. I nthe situation where some fields are processed successfully (for example file downloads) and an error occurs later in the form processing, the function still returns a negative value. It is the responsibility of the calling party to do the necessary cleanup. The calling party should also do the cleanup of any files which are created, but not required anymore later.
+
+### See Also
+
+* [`struct mg_form_data_handler;`](mg_form_data_handler.md)

+ 18 - 0
docs/api/mg_header.md

@@ -0,0 +1,18 @@
+# Civetweb API Reference
+
+### `struct mg_header;`
+
+### Fields
+
+| Field | Type | Description |
+| :--- | :--- | :--- |
+|**`name`**|`const char *`| The name of the client request header |
+|**`value`**|`const char *`| The value of the client request header |
+
+### Description
+
+The structure `mg_header` is used as a sub-structure in the [`struct mg_request_info;`](mg_request_info.md) structure to store the name and value of one HTTP request header as sent by the client.
+
+### See Also
+
+* [`struct mg_request_info;`](mg_request_info.md)

+ 44 - 0
docs/api/mg_init_library.md

@@ -0,0 +1,44 @@
+# Civetweb API Reference
+
+### `mg_init_library( feature );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`feature`**|`unsigned`| A bitmask indicating the features to be ininialized |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`unsigned`| A value indicating the initialized features is available. **0** is returned or error |
+
+### Description
+
+The function `mg_init_library()` should be called from an application program before using any other function.
+It must be called only from one thread (it is not guaranteed to be thread safe).
+
+This function is new in version 1.9 (as dummy implementation) and effective only from version 1.10.
+For compatibility reasons, other functions (such as [`mg_start();`](mg_start.md)) will initialize the required features as well,
+but they will no longer do a de-initialization, leaving a memory leak when the library is unloaded.
+
+The following parameter values can be used:
+
+| 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. |
+| **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. |
+| **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. |
+| **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. |
+| **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. |
+| **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. |
+
+The parameters can added using bitwise or. Values above 255 are reserved, the behavior of the function is undefined if any unknown bit is set.
+
+### See Also
+
+* [`mg_check_feature( feature );`](api/mg_check_feature.md)
+* [`mg_exit_library( feature );`](api/mg_exit_library.md)

+ 26 - 0
docs/api/mg_lock_connection.md

@@ -0,0 +1,26 @@
+# Civetweb API Reference
+
+### `mg_lock_connection( conn );`
+
+### Parameters
+
+| Parameter | Type | Description |
+|**`conn`**|`struct mg_connection *`|The connection to retrieve a lock|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_lock_connection()` is specifically for websocket connections to lock connection. Using this function in combination with [`mg_unlock_connection();`](mg_unlock_connection.md) is necessary around [`mg_write()`](mg_write.md) and [`mg_printf()`](mg_printf.md) calls if the code has server-initiated communication, as well as with communication in direct response to a message.
+
+### See Also
+
+* [`mg_lock_context();`](mg_lock_context.md)
+* [`mg_printf();`](mg_printf.md)
+* [`mg_unlock_connection();`](mg_unlock_connection.md)
+* [`mg_unlock_context();`](mg_unlock_context.md)
+* [`mg_websocket_client_write();`](mg_websocket_client_write.md)
+* [`mg_websocket_write();`](mg_websocket_write.md)
+* [`mg_write();`](mg_write.md)

+ 23 - 0
docs/api/mg_lock_context.md

@@ -0,0 +1,23 @@
+# Civetweb API Reference
+
+### `mg_lock_context( ctx );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`struct mg_context *`|The context to put the lock on|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_lock_context()` can be used to acquire a lock for exclusive access to resources which are shared between connection of threads. The lock is context wide. The lock must be released with a call to [`mg_unlock_context()`](mg_unlock_context.md).
+
+### See Also
+
+* [`mg_lock_connection();`](mg_lock_connection.md)
+* [`mg_unlock_connection();`](mg_unlock_connection.md)
+* [`mg_unlock_context();`](mg_unlock_context.md)

+ 24 - 0
docs/api/mg_md5.md

@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `mg_md5( buf, ... );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`buf`**|`char[33]`|Storage buffer for the calculated MD5 sum|
+|**`...`**|`char *, ...`|NULL terminated list of pointers to strings with data|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`char *`|Pointer to the resulting MD5 string|
+
+### Description
+
+The function `mg_md5()` caluclates the MD5 checksum of a NULL terminated list of NUL terminated ASCII strings. The MD5 checksum is returned in human readable format as an MD5 string in a caller supplied buffer.
+
+The function returns a pointer to the supplied result buffer.
+
+### See Also

+ 28 - 0
docs/api/mg_modify_passwords_file.md

@@ -0,0 +1,28 @@
+# Civetweb API Reference
+
+### `mg_modify_passwords_file( passwords_file_name, domain, user, password );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`passwords_file_name`**|`const char *`|The path to the passwords file|
+|**`domain`**|`const char *`|The domain of the user record|
+|**`user`**|`const char *`|Username of the record to be added, changed or deleted|
+|**`password`**|`const char *`|Password associated with the user or NULL if the record must be deleted|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Success or error code|
+
+### Description
+
+The function `mg_modify_passwords_file()` allows an application to manipulate .htpasswd files on the fly by adding, deleting and changing user records. This is one of the several ways to implement authentication on the server side.
+
+If the password parameter is not `NULL` an entry is added to the password file. An existing records is modified in that case. If `NULL` is used as the password the enrty is removed from the file.
+
+The function returns 1 when successful and 0 if an error occurs.
+
+### See Also

+ 31 - 0
docs/api/mg_option.md

@@ -0,0 +1,31 @@
+# Civetweb API Reference
+
+### `struct mg_option;`
+
+### Fields
+
+| Field | Type | Description |
+| :--- | :--- | :--- |
+|**`name`**|`const char *`|Name of the option|
+|**`type`**|`int`|Type of the option|
+|**`default_value`**|`const char *`|Value of the option|
+
+### 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.
+
+The field `type` can be one of the following values:
+
+|Value|Description|
+| :--- | :--- |
+|**`CONFIG_TYPE_UNKNOWN`**|The type of the option value is unknown|
+|**`CONFIG_TYPE_NUMBER`**|The option value is an integer|
+|**`CONFIG_TYPE_STRING`**|The option value is a number|
+|**`CONFIG_TYPE_FILE`**|The option value is a file name|
+|**`CONFIG_TYPE_DIRECTORY`**|The option value is a directory name|
+|**`CONFIG_TYPE_BOOLEAN`**|The option value is a boolean|
+|**`CONFIG_TYPE_EXT_PATTERN`**|The option value is a list of regular expression patterns|
+
+### See Also
+
+* [`mg_get_valid_options();`](mg_get_valid_options.md)

+ 27 - 0
docs/api/mg_printf.md

@@ -0,0 +1,27 @@
+# Civetweb API Reference
+
+### `mg_printf( conn, fmt, ... );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection over which the data must be sent|
+|**`fmt`**|`const char *`|Format string|
+|**`...`**|*various*|Parameters as specified in the format string|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Number of bytes written or an error code|
+
+### Description
+
+The function `mg_printf()` can be used to send formatted strings over a connection. The functionality is comparable to the `printf()` family of functions in the standard C library. The function returns **0** when the connection has been closed, **-1** if an error occurred and otherwise the number of bytes written over the connection. Except for the formatting part, the `mg_printf()` function is identical to the function [`mg_write()`](mg_write.md).
+
+### See Also
+
+* [`mg_websocket_client_write();`](mg_websocket_client_write.md)
+* [`mg_websocket_write();`](mg_websocket_write.md)
+* [`mg_write();`](mg_write.md)

+ 26 - 0
docs/api/mg_read.md

@@ -0,0 +1,26 @@
+# Civetweb API Reference
+
+### `mg_read( conn, buf, len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`| A pointer referencing the connection |
+|**`buf`**|`void *`| A pointer to the location where the received data can be stored |
+|**`len`**|`size_t`| The maximum number of bytes to be stored in the buffer |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`| The number of read bytes, or a status indication |
+
+### Description
+
+The function `mg_read()` receives data over an existing connection. The data is handled as binary and is stored in a buffer whose address has been provided as a parameter. The function returns the number of read bytes when successful, the value **0** when the connection has been closed by peer and a negative value when no more data could be read from the connection.
+
+### See Also
+
+* [`mg_printf();`](mg_printf.md)
+* [`mg_write();`](mg_write.md)

+ 35 - 0
docs/api/mg_request_info.md

@@ -0,0 +1,35 @@
+# Civetweb API Reference
+
+### `struct mg_request_info;`
+
+### Fields
+
+| Field | Type | Description |
+| :--- | :--- | :--- |
+|**`request_method`**|`const char *`| The request method used by the client for the connection this can be **GET**, **POST** or one of the other common HTTP request methods |
+|**`request_uri`**|`const char *`| The absolute, relative or URL-encoded URI as it was sent in the request.  Example: "http://mydomain.com:8080/path/to/file.ext" or "/path/to/file.ext", depending on the client. |
+|**`local_uri`**|`const char *`| The relative URL-encoded URI as it references the local resource. If the request URI does not reference a resource on the local server, this field is NULL.  Example: "/path/to/file.ext" (even if the client used "http://mydomain.com:8080/path/to/file.ext" in the request) |
+|~~`uri`~~|`const char *`| *Deprecated. Use* `local_uri` *instead* |
+|**`http_version`**|`const char *`| The HTTP version as mentioned in the client request. This can be "1.0", "1.1", etc. |
+|**`query_string`**|`const char *`| The HTTP query string, defined as URL part after the first '?' character, not including '?'. NULL if there is no '?'. |
+|**`remote_user`**|`const char *`| The name of the authenticated remote user, or NULL if no authentication was used. Only used for HTTP (digest) authentication, not for cookie based authentication. |
+|**`remote addr`**|`char[48]`| The IP address of the remote client as a string. This can either represent an IPv4 or an IPv6 address.  Example: "127.0.0.1" |
+|~~`remote_ip`~~|`long`| *Deprecated. Use* `remote_addr` *instead* |
+|**`content_length`**|`long long`| The content length of the request body. This value can be -1 if no content length was provided. The request may still have body data, but the server cannot determine the length until all data has arrived (e.g. when the client closes the connection, or the final chunk of a chunked request has been received). |
+|**`remote_port`**|`int`| The port number at the client's side (an integer number between 1 and 65535). |
+|**`is_ssl`**|`int`| 1 if the connection is over SSL (https), and 0 if it is a plain connection (http) |
+|**`user_data`**|`void *`| A pointer to the `user_data` information which was provided as a parameter to `mg_start()`. |
+|**`conn_data`**|`void *`| A pointer to connection specific user data |
+|**`num_headers`**|`int`| The number of HTTP request headers sent by the client (see http_headers) |
+|**`http_headers`**|`struct mg_header[64]`| Array of structures with the HTTP request headers sent by the client. For the number of filled header fields, ee num_headers. |
+|**`client_cert`**|`struct client_cert *`| Pointer to the client certificate information, when available. This field is only filled for https connections using client certificates. |
+
+### Description
+
+The `mg_request_info` structure contains the client information of an existing connection.
+
+### See Also
+
+* [`struct client_cert;`](client_cert.md)
+* [`struct mg_header;`](mg_header.md)
+* [`mg_get_request_info();`](mg_get_request_info.md)

+ 27 - 0
docs/api/mg_send_chunk.md

@@ -0,0 +1,27 @@
+# Civetweb API Reference
+
+### `mg_send_chunk( conn, buf, len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`| A pointer to the connection to be used to send data |
+|**`chunk`**|`const void *`| A pointer to the data to be sent |
+|**`chunk_len`**|`size_t`| The number of bytes to be sent |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`| An integer indicating the amount of bytes sent, or failure |
+
+### Description
+
+The function `mg_send_chunk()` can be used to send a block of data, if chunked transfer encoding is used. Only use this function after sending a complete HTTP request or response header with the "Transfer-Encoding: chunked" header field set.
+The function returns the amount of bytes sent in case of success, or **-1** in case of an error.
+
+### See Also
+
+* [`mg_write();`](mg_write.md)
+* [`mg_printf();`](mg_print.md)

+ 25 - 0
docs/api/mg_send_file.md

@@ -0,0 +1,25 @@
+# Civetweb API Reference
+
+### `mg_send_file( conn, path );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection over which the file must be sent|
+|**`path`**|`const char *`|The full path and filename of the file|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_send_file()` sends the contents of a file over a connection to the remote peer. The function also adds the necessary HTTP headers.
+
+### See Also
+
+* [`mg_printf();`](mg_printf.md)
+* [`mg_send_mime_file();`](mg_send_mime_file.md)
+* [`mg_send_mime_file2();`](mg_send_mime_file2.md)
+* [`mg_write();`](mg_write.md)

+ 26 - 0
docs/api/mg_send_http_error.md

@@ -0,0 +1,26 @@
+# Civetweb API Reference
+
+### `mg_send_http_error( conn, status_code, fmt, ... );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection over which the file must be sent|
+|**`status_code`**|`int`|The HTTP status code to return|
+|**`fmt`**|`const char *`|Format string specifying the remote command to execute|
+|**`...`**|*various*|Parameters used in the format string|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_send_http_error()` sends a HTTP reply with the given status code and the content specified by fmt. The textual status code is determined from the numerical status code internally.
+
+### See Also
+
+* [`mg_printf();`](mg_printf.md)
+* [`mg_write();`](mg_write.md)
+* [`mg_send_file();`](mg_send_file.md)

+ 27 - 0
docs/api/mg_send_mime_file.md

@@ -0,0 +1,27 @@
+# Civetweb API Reference
+
+### `mg_send_mime_file( conn, path, mime_type );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection over which the file must be sent|
+|**`path`**|`const char *`|The full path and filename of the file|
+|**`mime_type`**|`const char *`|The mime type of the file, or NULL for automatic detection|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_send_mime_file()` sends a file over a connection including the HTTP headers. The function is similar to the [`mg_send_file()`](mg_send_file.md) with the additional functionality that the MIME type of the file can be specified. If the `mime_type` parameter is NULL, the routine will try to determine the MIME type based on the extension of the filename.
+
+### See Also
+
+* [`mg_get_builtin_mime_type();`](mg_get_builtin_mime_type.md)
+* [`mg_printf();`](mg_printf.md)
+* [`mg_send_file();`](mg_send_file.md)
+* [`mg_send_mime_file2();`](mg_send_mime_file2.md)
+* [`mg_write();`](mg_write.md)

+ 30 - 0
docs/api/mg_send_mime_file2.md

@@ -0,0 +1,30 @@
+# Civetweb API Reference
+
+### `mg_send_mime_file2( conn, path, mime_type, additional_headers );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection over which the file must be sent|
+|**`path`**|`const char *`|The full path and filename of the file|
+|**`mime_type`**|`const char *`|The mime type or NULL for automatic detection|
+|**`additional_headers`**|`const char *`|Additional headers to be sent|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_send_mime_file2()` can be used to send a file over a connection. The function is similar to [`mg_send_mime_file()`](mg_send_mime_file.md) with the additional functionality that user specified headers can be sent. The MIME type of the file can be specified in the function call, or will be automatically determined based on the extension of the filename if the `mime_type` parameter has the value NULL.
+
+Additional custom header fields can be added as a parameter. Please make sure that these header names begin with `X-` to prevent name clashes with other headers. If the `additional_headers` parameter is NULL, no custom headers will be added.
+
+### See Also
+
+* [`mg_get_builtin_mime_type();`](mg_get_builtin_mime_type.md)
+* [`mg_printf();`](mg_printf.md)
+* [`mg_send_file();`](mg_send_file.md)
+* [`mg_send_mime_file();`](mg_send_mime_file.md)
+* [`mg_write();`](mg_write.md)

+ 24 - 0
docs/api/mg_server_ports.md

@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `struct mg_server_ports;`
+
+### Fields
+
+| Field | Type | Description |
+| :--- | :--- | :--- |
+|**`protocol`**|`int`|The protocol mask where `IPv4` is **1**, `IPv6` is **2** and both `IPv4` and `IPv6` is **3**|
+|**`port`**|`int`|The port number on which the service listens|
+|**`is_ssl`**|`int`|**0** for `HTTP` communication, **1** for `HTTPS`|
+|**`is_redirect`**|`int`|**1** if all requests are redirected, otherwise **0**|
+|**`_reserved1`**|`int`|Reserved for internal use|
+|**`_reserved2`**|`int`|Reserved for internal use|
+|**`_reserved3`**|`int`|Reserved for internal use|
+|**`_reserved4`**|`int`|Reserved for internal use|
+
+### 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.
+
+### See Also
+
+* [`mg_get_server_ports();`](mg_get_server_ports.md)

+ 30 - 0
docs/api/mg_set_auth_handler.md

@@ -0,0 +1,30 @@
+# Civetweb API Reference
+
+### `mg_set_auth_handler( ctx, uri, handler, cbdata );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`struct mg_context *`|The context on which the handler must be set|
+|**`uri`**|`const char *`|The URI for the authorization handler|
+|**`handler`**|`mg_authorization_handler`|Callback function doing the actual authorization|
+|**`cbdata`**|`void *`|Optional user data|
+
+`int mg_authorization_handler( struct mg_connection *conn, void *cbdata );`
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_set_auth_handler()` hooks an authorization function to an URI to check if a user is authorized to visit that URI. The check is performed by a callback function of type `mg_authorization_handler`. The callback function is passed two parameters: the current connection and a pointer to optional user defined data which was passed to `mg_set_auth_handler()` when the callback was hooked to the URI.
+
+The callback function can return **0** to deny access, and **1** to allow access.
+
+The `mg_set_auth_handler()` function is very similar in use to [`mg_set_request_handler()`](mg_set_request_handler.md).
+
+### See Also
+
+* [`mg_set_request_handler();`](mg_set_request_handler.md)

+ 26 - 0
docs/api/mg_set_request_handler.md

@@ -0,0 +1,26 @@
+# Civetweb API Reference
+
+### `mg_set_request_handler( ctx, uri, handler, cbdata );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`struct mg_context *`|The context where the handler must be active|
+|**`uri`**|`const char *`|The URI to hook the handler on|
+|**`handler`**|`mg_request_handler`|Callback function doing the heavy lifting|
+|**`cbdata`**|`void *`|Optional user supplied data|
+
+`int mg_request_handler( struct mg_connection *conn, void *cbdata );`
+
+### Return Value
+
+*none*
+
+### 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.
+
+### See Also
+
+* [`mg_set_auth_handler();`](mg_set_auth_handler.md)

+ 22 - 0
docs/api/mg_set_user_connection_data.md

@@ -0,0 +1,22 @@
+# Civetweb API Reference
+
+### `mg_set_user_connection_data( conn, data );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|connection to add the user data|
+|**`data`**|`void *`|Pointer to the user data|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_set_user_connection_data()` can be used to add or change the user data pointer attached to a connection. Using the value NULL in the call will remove a previously assigned user data pointer.
+
+### See Also
+
+* [`mg_get_user_connection_data();`](mg_user_connection_data.md)

+ 30 - 0
docs/api/mg_set_websocket_handler.md

@@ -0,0 +1,30 @@
+# Civetweb API Reference
+
+### `mg_set_websocket_handler( ctx, uri, connect_handler, ready_handler, data_handler, close_handler, cbdata );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`mg_context *`|The context in which to add the handlers|
+|**`uri`**|`const char *`|The URI for which the handlers should be activated|
+|**`connect_handler`**|`mg_websocket_connect_handler`|Handler called when a connect is signalled|
+|**`ready_handler`**|`mg_websocket_ready_handler`|Handler called when the connection is ready|
+|**`data_handler`**|`mg_websocket_data_handler`|Handler called when data is received|
+|**`close_handler`**|`mg_websocket_close_handler`|Handler called when the connection closes|
+|**`cbdata`**|`void *`|User defined data|
+
+`int mg_websocket_connect_handler( const struct mg_connection *conn, void *cbdata );`
+`int mg_websocket_ready_handler( struct mg_connection *conn, void *cbdata );`
+`int mg_websocket_data_handler( struct mg_connection *conn, int opcode, char * buf, size_t buf_len, void *cbdata );`
+`int mg_websocket_close_handler( const struct mg_connection *conn,  void *cbdata );`
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_set_websocket_handler()` connects callback functions to a websocket URI. The callback functions are called when a state change is detected on the URI like an incomming connection or data received from a remote peer.
+
+### See Also

+ 39 - 0
docs/api/mg_start.md

@@ -0,0 +1,39 @@
+# Civetweb API Reference
+
+### `mg_start( callbacks, user_data, options );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`callbacks`**|`const struct mg_callbacks *`| A structure with optional callback functions to process requests from the web server |
+|**`user_data`**|`void *`| A pointer to optional user data |
+|**`options`**|`char **`| A list of options used to initialize the web server. The list consists of an NULL terminated list of option-value string pairs. |
+
+The option list can be used to set the following options:
+
+| 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_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\)).|
+| | |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.|
+| | |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.
+| **`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. |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`struct mg_context *`| A pointer to a context structure when successful, or NULL in case of failure |
+
+### Description
+
+The function `mg_start()` is the only function needed to call to initialize the webserver. After the function returns and a pointer to a context structure is provided, it is guaranteed that the server has started and is listening on the designated ports. In case of failure a NULL pointer is returned.  The behaviour of the web server is controlled by a list of callback functions and a list of options.  The callback functions can do application specific processing of events which are encountered by the webserver. If a specific callback function is set to NULL, the webserver uses their default callback routine. The options list controls how the webserver should be started and contains settings for for example the ports to listen on, the maximum number of threads created to handle requests in parallel and if settings for SSL encryption.
+
+As a side effect on Unix systems, SIGCHLD and SIGPIPE signals will be ignored. If custom processing is needed for these signals, signal handlers must be setup after the call to `mg_start()` has completed.
+
+### See Also
+
+* [`struct mg_callbacks;`](mg_callbacks.md)
+* [`mg_stop();`](mg_stop.md)

+ 26 - 0
docs/api/mg_start_thread.md

@@ -0,0 +1,26 @@
+# Civetweb API Reference
+
+### `mg_start_thread( func, cbdata );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`func`**|`mg_thread_func_t`|Function to start as a separate thread|
+|**`cbdata`**|`void *`|User defined data to be passed to the thread as parameter|
+
+`void mg_thread_func_t( void *cbdata );`
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Success or error code|
+
+### Description
+
+The function `mg_start_thread()` is a convenience function to create a detached thread. The function returns **0** when successful and another value if an error occured. A pointer to user supplied data can be passed which is then passed further on to the thread function as parameter.
+
+### See Also
+
+* [`mg_start();`](mg_start.md)

+ 22 - 0
docs/api/mg_stop.md

@@ -0,0 +1,22 @@
+# Civetweb API Reference
+
+### `mg_stop( ctx );`
+
+#### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|**`struct mg_context *`**| A pointer to the current webserver context |
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_stop()` is used to stop and cleanup a running webserver. A pointer to the context of the running webserver is provided as a parameter. The execution of this function may take some time because it waits until all threads have stopped and returns all memory to the heap. After the function returns, the location the context pointer points to is invalid. The function does not return a return value and it is therefore not possible to know if stopping the webserver succeeded or not.
+
+### See Also
+
+* [`mg_start();`](mg_start.md)
+* [`mg_start_thread();`](mg_start_thread.md)

+ 24 - 0
docs/api/mg_store_body.md

@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `mg_store_body( conn, path );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|connection on which to read the data|
+|**`path`**|`const char *`|file to store the request body|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`long long`|Number of bytes written to the file, or an error code|
+
+### Description
+
+The function `mg_store_body()` stores the body of an incoming request to a data file. The function returns the number of bytes stored in the file, or a negative value to indicate an error.
+
+### See Also
+
+* [`mg_read();`](mg_read.md)

+ 24 - 0
docs/api/mg_strcasecmp.md

@@ -0,0 +1,24 @@
+# Civetweb API Reference
+
+### `mg_strcasecmp( s1, s2 );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`s1`**|`const char *`|First string to compare|
+|**`s2`**|`const char *`|Second string to compare|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Integer value with the result of the comparison|
+
+### Description
+
+The function `mg_strcasecmp()` is a helper function to compare two strings. The comparison is case insensitive. The return value is **0** if both strings are equal, less then zero if the first string is less than the second in a lexical comparison, and greater than zero if the first string is greater than the second.
+
+### See Also
+
+* [`mg_strncasecmp();`](mg_strncasecmp.md)

+ 25 - 0
docs/api/mg_strncasecmp.md

@@ -0,0 +1,25 @@
+# Civetweb API Reference
+
+### `mg_strncasecmp( s1, s2, len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`s1`**|`const char *`|First string in the comparison|
+|**`s2`**|`const char *`|Second string in the comparison|
+|**`len`**|`size_t`|The maximum number of characters to compare|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|The result of the comparison|
+
+### Description
+
+The function `mg_strncasecmp()` is a helper function to compare two strings. The comparison is case insensitive and only a limited number of characters are compared. This limit is provided as third parameter in the function call. The return value is **0** if both strings are equal, less then zero if the first string is less than the second in a lexical comparison, and greater than zero if the first string is greater than the second.
+
+### See Also
+
+* [`mg_strcasecmp();`](mg_strcasecmp.md)

+ 27 - 0
docs/api/mg_unlock_connection.md

@@ -0,0 +1,27 @@
+# Civetweb API Reference
+
+### `mg_unlock_connection( conn );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|Connection to remove the lock from|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_unlock_connection()` removes the lock on a connection which was previously set with a call to [`mg_lock_connection()`](mg_lock_connection.md). Locking may be necessary when using [`mg_write()`](mg_write.md) or [`mg_printf()`](mg_printf.md) on websocket connections to prevent data corruption.
+
+### See Also
+
+* [`mg_lock_connection();`](mg_lock_connection.md)
+* [`mg_lock_context();`](mg_lock_context.md)
+* [`mg_printf();`](mg_printf.md)
+* [`mg_unlock_context();`](mg_unlock_context.md)
+* [`mg_websocket_client_write();`](mg_websocket_client_write.md)
+* [`mg_websocket_write();`](mg_websocket_write.md)
+* [`mg_write();`](mg_write.md)

+ 23 - 0
docs/api/mg_unlock_context.md

@@ -0,0 +1,23 @@
+# Civetweb API Reference
+
+### `mg_unlock_context( ctx );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`ctx`**|`struct mg_context *`|The context to remove the lock from|
+
+### Return Value
+
+*none*
+
+### Description
+
+The function `mg_unlock_contect()` removes a lock put previously on a context with a call to [`mg_lock_context()`](mg_lock_context.md). Locking a context may be necessary when accessing shared resources.
+
+### See Also
+
+* [`mg_lock_connection();`](mg_lock_connection.md)
+* [`mg_lock_context();`](mg_lock_context.md)
+* [`mg_unlock_connection();`](mg_unlock_connection.md)

+ 22 - 0
docs/api/mg_upload.md

@@ -0,0 +1,22 @@
+# 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

+ 27 - 0
docs/api/mg_url_decode.md

@@ -0,0 +1,27 @@
+# Civetweb API Reference
+
+### `mg_url_decode( src, src_len, dst, dst_len, is_form_url_encoded );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`src`**|`const char *`|Source data to convert|
+|**`src_len`**|`int`|Length of the source buffer|
+|**`dst`**|`char *`|Destination buffer to store the result|
+|**`dst_len`**|`int`|Length of the destination buffer|
+|**`is_form_url_encoded`**|`int`|Not equal zero when form decoding must be used|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|The number of bytes stored in the destination buffer, or **-1** if the buffer doesn't exist or is too small|
+
+### Description
+
+The function `mg_url_decode()` Decodes a in input buffer. Both normal URIs and form URIs can be decoded. In the latter case the space character is converted to a `+` as defined in [RFC 1866](http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt) in section 8.2.1.
+
+### See Also
+
+* [`mg_url_encode();`](mg_url_encode.md)

+ 25 - 0
docs/api/mg_url_encode.md

@@ -0,0 +1,25 @@
+# Civetweb API Reference
+
+### `mg_url_encode( src, dst, des_len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`src`**|`const char *`|Input string to encode|
+|**`dst`**|`char *`|Destination buffer to store the encoded result|
+|**`dst_len`**|`size_t`|Length of the destination buffer including the terminating NUL|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|The number of characters written in the destination buffer|
+
+### Description
+
+The function `mg_url_encode()` encodes a in input buffer. Both normal URIs and form URIs can be encoded. In the latter case the space character is converted to a `+` as defined in [RFC 1866](http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt) in section 8.2.1.
+
+### See Also
+
+* [`mg_url_decode();`](mg_url_decode.md)

+ 19 - 0
docs/api/mg_version.md

@@ -0,0 +1,19 @@
+# Civetweb API Reference
+
+### `mg_version();`
+
+### Parameters
+
+*none*
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`const char *`| A pointer to a text with the current CivetWeb version |
+
+### 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".
+
+### See Also

+ 32 - 0
docs/api/mg_websocket_client_write.md

@@ -0,0 +1,32 @@
+# Civetweb API Reference
+
+### `mg_websocket_client_write( conn, opcode, data, data_len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|Connection on which to send data|
+|**`opcode`**|`int`|Opcode|
+|**`data const`**|`char *`|The data to be written|
+|**`data_len`**|`size_t`|Length of the data buffer|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Number of bytes written or an error code|
+
+### 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 return value is the number of bytes written on success, **0** when the connection has been closed and **-1** if an error occured.
+
+### See Also
+
+* [`mg_lock_connection();`](mg_lock_connection.md)
+* [`mg_printf();`](mg_printf.md)
+* [`mg_unlock_connection();`](mg_unlock_connection.md)
+* [`mg_websocket_write();`](mg_websocket_write.md)
+* [`mg_write();`](mg_write.md)

+ 34 - 0
docs/api/mg_websocket_write.md

@@ -0,0 +1,34 @@
+# Civetweb API Reference
+
+### `mg_websocket_write( conn, opcode, data, data_len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|Connection on which the data must be written|
+|**`opcode`**|`int`|Opcode|
+|**`data`**|`const char *`|Data to be written to the client|
+|**`data_len`**|`size_t`|Length of the data|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`|Number of bytes written or an error code|
+
+### Description
+
+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 returns the number of bytes written, **0** when the connection has been closed and **-1** if an error occured.
+
+### See Also
+
+* [`mg_lock_connection();`](mg_lock_connection.md)
+* [`mg_printf();`](mg_printf.md)
+* [`mg_unlock_connection();`](mg_unlock_connection.md)
+* [`mg_websocket_client_write();`](mg_websocket_client_write.md)
+* [`mg_write();`](mg_write.md)

+ 29 - 0
docs/api/mg_write.md

@@ -0,0 +1,29 @@
+# Civetweb API Reference
+
+### `mg_write( conn, buf, len );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`| A pointer to the connection to be used to send data |
+|**`buf`**|`const void *`| A pointer to the blob of information to be sent |
+|**`len`**|`size_t`| The amount of bytes to be sent |
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`int`| An integer indicating the amount of bytes sent, or failure |
+
+### Description
+
+The function `mg_write()` can be used to send a blob of arbitrary data over a connection. The size of the data is provided as a parameter. The only length limitation on this function is `MAX_INT`, because the return value of this function will turn negative with larger blocks of data, although they may have been sent correctly. The function returns the amount of bytes sent in case of success, the value **0** when the connection has been closed, and **-1** in case of an error.
+
+### See Also
+
+* [`mg_lock_connection();`](mg_lock_connection.md)
+* [`mg_printf();`](mg_print.md)
+* [`mg_unlock_connection();`](mg_unlock_connection.md)
+* [`mg_websocket_client_write();`](mg_websocket_client_write.md)
+* [`mg_websocket_write();`](mg_websocket_write.md)

+ 8 - 0
examples/README.md

@@ -0,0 +1,8 @@
+
+Examples
+=====
+
+These examples show how to embed civetweb into a C ([embedded_c](https://github.com/civetweb/civetweb/tree/master/examples/embedded_c)) or a C++ ([embedded_cpp](https://github.com/civetweb/civetweb/tree/master/examples/embedded_cpp)) application.
+The C++ wrapper only offers a subset of the full C API, thus the C example is more complete than the C++ example.
+
+Some no longer maintained examples can be found in the ["obsolete"](https://github.com/civetweb/civetweb/tree/master/examples/_obsolete) folder. It is not guaranteed that they work in the current version - they are kept for reference, but might be removed in the future.

+ 0 - 0
examples/chat/Makefile → examples/_obsolete/chat/Makefile


+ 0 - 0
examples/chat/chat.c → examples/_obsolete/chat/chat.c


+ 0 - 0
examples/docroot/favicon.ico → examples/_obsolete/docroot/favicon.ico


+ 0 - 0
examples/docroot/index.html → examples/_obsolete/docroot/index.html


+ 0 - 0
examples/docroot/jquery.js → examples/_obsolete/docroot/jquery.js


Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů