1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Add potential library.

This commit is contained in:
Sandu Liviu Catalin 2020-09-04 23:50:12 +03:00
parent 1d4a28b244
commit 0aee307376
14 changed files with 25545 additions and 0 deletions

13
module/Library/Web.cpp Normal file
View File

@ -0,0 +1,13 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Web.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ================================================================================================
void Register_Web(HSQUIRRELVM vm)
{
}
} // Namespace:: SqMod

6
module/Library/Web.hpp Normal file
View File

@ -0,0 +1,6 @@
#pragma once
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------

View File

@ -44,6 +44,7 @@ extern void Register_SQLite(HSQUIRRELVM vm);
extern void Register_String(HSQUIRRELVM vm);
extern void Register_System(HSQUIRRELVM vm);
extern void Register_Utils(HSQUIRRELVM vm);
extern void Register_Web(HSQUIRRELVM vm);
extern void Register_XML(HSQUIRRELVM vm);
// ------------------------------------------------------------------------------------------------
@ -97,6 +98,7 @@ bool RegisterAPI(HSQUIRRELVM vm)
Register_String(vm);
Register_System(vm);
Register_Utils(vm);
Register_Web(vm);
Register_XML(vm);
Register_Constants(vm);

View File

@ -7,6 +7,7 @@ add_subdirectory(PUGIXML)
add_subdirectory(SQLite)
add_subdirectory(TinyDir)
add_subdirectory(Whirlpool)
add_subdirectory(CivetWeb)
add_subdirectory(SimpleSocket)
# Build our own mysql client on windows
if(WIN32 AND ENABLE_MYSQL)

27
module/Vendor/CivetWeb/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,27 @@
# Create the CivetWeb library
add_library(CivetWeb STATIC
include/civetweb.h
civetweb.c
)
# Configure include folders
target_include_directories(CivetWeb PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(CivetWeb PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
# Configure macro options
target_compile_definitions(CivetWeb PRIVATE _WIN32_WINNT=0x0601)
# Enable LTO
if (LTO_ENABLED)
target_link_libraries(CivetWeb PRIVATE -flto)
endif()
# Allow dynamic loading of SSL
target_link_libraries(CivetWeb PUBLIC dl)
# Find the available thread library
find_package(Threads)
target_link_libraries(CivetWeb PUBLIC ${CMAKE_THREAD_LIBS_INIT})
# OS and compiler checks.
if(WIN32)
target_link_libraries(CivetWeb PUBLIC Ws2_32)
endif()
# Need the realtime library if we're using timers
if(UNIX AND NOT APPLE)
target_link_libraries(CivetWeb PUBLIC rt)
endif()

242
module/Vendor/CivetWeb/CREDITS.md vendored Normal file
View File

@ -0,0 +1,242 @@
# Civetweb Contributors
* Abhishek Lekshmanan
* Abramo Bagnara
* Adam Bailey
* Alan Somers
* Alberto Bignotti
* Alex Kozlov
* AndreyArsov
* Anton Te
* beaver
* bel2125
* Ben M. Ward
* Bernhard Lehner
* BigJoe
* Bjoern Petri
* Braedy Kuzma
* Breno Ramalho Lemes
* brett
* Brian Lambert
* Brian Spratke
* cdbishop
* celeron55
* Charles Olivi
* Chris Han
* Chris Jones
* Chris Rehn
* Christian Mauderer
* Christopher Galas
* cjh
* Colden Cullen
* Colm Sloan
* Cortronic
* Daniel Oaks
* Daniel Rempel
* Danny Al-Gaaf
* Dave Brower
* daveelton
* David Arnold
* David Loffredo
* Dialga
* Domenico Di Iorio
* Drew Wells
* duong2179
* ehlertjd
* eugene
* Eric Tsau
* Erick Vieyra
* Erik Beran
* Erik Partridge
* extergnoto
* F-Secure Corporation
* Fabrice Fontaine
* feneuilflo
* Fernando G. Aranda
* Frank Hilliger
* Grahack
* Gregor Jasny
* grenclave
* grunk
* guangqing.chen
* Guilherme Amadio
* hansipie
* HariKamath Kamath
* Henry Chang
* Herumb Shandilya
* Herve Codina
* Iain Morton
* ImgBotApp
* Ivan Dlugos
* Jack
* Jacob Repp
* Jacob Skillin
* Jan Kowalewski
* Jan Willem Janssen
* Jeremy Lin
* Jesse Williamson
* Jim Evans
* jmc-
* Joakim L. Gilje
* Jochen Scheib
* Joe Mucchiello
* Joel Gallant
* Johan De Taeye
* John Faith
* Jordan
* Jordan Shelley
* Joshua Boyd
* Joshua D. Boyd
* k-mds
* kakwa
* kalphamon
* Karol Mroz
* Keith Holman
* Keith Kyzivat
* Ken Walters
* Kevin Branigan
* Kevin Wojniak
* Khem Raj
* Kimmo Mustonen
* Krzysztof Kozlowski
* Lammert Bies
* Lars Immisch
* Lawrence
* Li Peng
* Lianghui
* Luka Rahne
* Lukas Martanovic
* Maarten Fremouw
* makrsmark
* marco
* Mark Lakata
* Martin Gaida
* Mateusz Gralka
* Matt Clarkson
* Mellnik
* Mike Crowe
* mingodad
* Morgan McGuire
* mrdvlpr.xnu
* Nat!
* Neil Jensen
* newsoft
* nfrmtkr
* Nick Hildebrant
* 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
* Piotr Zierhoffer
* pkvamme
* Radoslaw Zarzynski
* Red54
* Retallack Mark mark.retallack
* Richard Screene
* Rimas Misevi-ìius
* Rinat Dobrokhotov
* ryankopf
* Sage Weil
* Sangwhan Moon
* Saumitra Vikram
* Scott Nations
* Sebastien Jodogne
* Sergey Linev
* sgmesservey
* shantanugadgil
* Sherwyn Sen
* shreyajaggi8
* Simon Hailes
* slidertom
* SpaceLord
* sunfch
* suzukibitman
* Símal Rasmussen
* Tamotsu Kanoh
* thewaterymoon
* Thiago Macedo
* THILMANT, Bernard
* Thomas Davis
* Thomas Klausner
* Thorsten Horstmann
* tnoho
* Tom Deblauwe
* Tomas Andrle
* Tomasz Gorochowik
* Toni Wilk
* Torben Jonas
* Uilian Ries
* Ulrich Hertlein
* Walt Steverson
* wangli28
* webxer
* William Greathouse
* xeoshow
* xtne6f
* Yehuda Sadeh
* Yury Z
* zhen.wang
and others.
# Mongoose Contributors
CivetWeb is based on the Mongoose code. The following users contributed to the original Mongoose release between 2010 and 2013. This list was generated from the Mongoose GIT logs. It does not contain contributions from the Mongoose mailing list. There is no record for contributors prior to 2010.
* Sergey Lyubka
* Arnout Vandecappelle (Essensium/Mind)
* Benoît Amiaux
* Cody Hanson
* Colin Leitner
* Daniel Oaks
* Eric Bakan
* Erik Oomen
* Filipp Kovalev
* Ger Hobbelt
* Hendrik Polczynski
* Henrique Mendonça
* Igor Okulist
* Jay
* Joe Mucchiello
* John Safranek
* Joseph Mainwaring
* José Miguel Gonçalves
* KIU Shueng Chuan
* Katerina Blinova
* Konstantin Sorokin
* Marin Atanasov Nikolov
* Matt Healy
* Miguel Morales
* Mikhail Nikalyukin
* MikieMorales
* Mitch Hendrickson
* Nigel Stewart
* Pavel
* Pavel Khlebovich
* Rogerz Zhang
* Sebastian Reinhard
* Stefan Doehla
* Thileepan
* abadc0de
* arvidn
* bick
* ff.feng
* jmucchiello
* jwang
* lsm
* migal
* mlamb
* nullable.type
* shantanugadgil
* tayS
* test
* valenok

246
module/Vendor/CivetWeb/LICENSE.md vendored Normal file
View File

@ -0,0 +1,246 @@
ALL LICENSES
=====
This document includes several copyright licenses for different
aspects of the software. Not all licenses may apply depending
on the features chosen.
Civetweb License
-----
### Included with all features.
> Copyright (c) 2013-2020 The CivetWeb developers ([CREDITS.md](https://github.com/civetweb/civetweb/blob/master/CREDITS.md))
>
> Copyright (c) 2004-2013 Sergey Lyubka
>
> Copyright (c) 2013 No Face Press, LLC (Thomas Davis)
>
> Copyright (c) 2013 F-Secure Corporation
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
Lua License
------
### Included only if built with Lua support.
http://www.lua.org/license.html
> Copyright (C) 1994-2015 Lua.org, PUC-Rio.
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
SQLite3 License
------
### Included only if built with Lua and SQLite support.
http://www.sqlite.org/copyright.html
> 2001-09-15
>
> The author disclaims copyright to this source code. In place of
> a legal notice, here is a blessing:
>
> May you do good and not evil.
> May you find forgiveness for yourself and forgive others.
> May you share freely, never taking more than you give.
lsqlite3 License
------
### Included only if built with Lua and SQLite support.
> Copyright (C) 2002-2016 Tiago Dionizio, Doug Currie
> All rights reserved.
> Author : Tiago Dionizio <tiago.dionizio@ist.utl.pt>
> Author : Doug Currie <doug.currie@alum.mit.edu>
> Library : lsqlite3 - an SQLite 3 database binding for Lua 5
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
Lua File System License
------
### Included only if built with Lua support.
http://keplerproject.github.io/luafilesystem/license.html
> Copyright Kepler Project 2003 (http://www.keplerproject.org/luafilesystem)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
LuaXML License
------
### Included only if built with Lua and LuaXML support.
Version 1.8.0 (Lua 5.2), 2013-06-10 by Gerald Franz, eludi.net
Modified and extended 2015 by Bernhard Nortmann, https://github.com/n1tehawk/LuaXML version 2.0.x, compatible with Lua 5.1 to 5.3 and LuaJIT.
> LuaXML License
>
> LuaXml is licensed under the terms of the MIT license reproduced below,
> the same as Lua itself. This means that LuaXml is free software and can be
> used for both academic and commercial purposes at absolutely no cost.
>
> Copyright (C) 2007-2013 Gerald Franz, eludi.net
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
Duktape License
------
### Included only if built with Duktape support.
https://github.com/svaarala/duktape/blob/master/LICENSE.txt
> ===============
> Duktape license
> ===============
>
> (http://opensource.org/licenses/MIT)
>
> Copyright (c) 2013-2017 by Duktape authors (see AUTHORS.rst)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
zlib License
------
### Included only if built with zlib support.
https://www.zlib.net/zlib_license.html
> zlib.h -- interface of the 'zlib' general purpose compression library
> version 1.2.11, January 15th, 2017
>
> Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
>
> This software is provided 'as-is', without any express or implied
> warranty. In no event will the authors be held liable for any damages
> arising from the use of this software.
>
> Permission is granted to anyone to use this software for any purpose,
> including commercial applications, and to alter it and redistribute it
> freely, subject to the following restrictions:
>
> 1. The origin of this software must not be misrepresented; you must not
> claim that you wrote the original software. If you use this software
> in a product, an acknowledgment in the product documentation would be
> appreciated but is not required.
> 2. Altered source versions must be plainly marked as such, and must not be
> misrepresented as being the original software.
> 3. This notice may not be removed or altered from any source distribution.
>
> Jean-loup Gailly Mark Adler
> jloup@gzip.org madler@alumni.caltech.edu

21103
module/Vendor/CivetWeb/civetweb.c vendored Normal file

File diff suppressed because it is too large Load Diff

1062
module/Vendor/CivetWeb/handle_form.inl vendored Normal file

File diff suppressed because it is too large Load Diff

1678
module/Vendor/CivetWeb/include/civetweb.h vendored Normal file

File diff suppressed because it is too large Load Diff

471
module/Vendor/CivetWeb/md5.inl vendored Normal file
View File

@ -0,0 +1,471 @@
/*
* This an amalgamation of md5.c and md5.h into a single file
* with all static declaration to reduce linker conflicts
* in Civetweb.
*
* The MD5_STATIC declaration was added to facilitate static
* inclusion.
* No Face Press, LLC
*/
/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
/*
Independent implementation of MD5 (RFC 1321).
This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
copyrighted.
The original and principal author of md5.h is L. Peter Deutsch
<ghost@aladdin.com>. Other authors are noted in the change history
that follows (in reverse chronological order):
2002-04-13 lpd Removed support for non-ANSI compilers; removed
references to Ghostscript; clarified derivation from RFC 1321;
now handles byte order either statically or dynamically.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
added conditionalization for C++ compilation from Martin
Purschke <purschke@bnl.gov>.
1999-05-03 lpd Original version.
*/
#if !defined(md5_INCLUDED)
#define md5_INCLUDED
/*
* This package supports both compile-time and run-time determination of CPU
* byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
* compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
* defined as non-zero, the code will be compiled to run only on big-endian
* CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
* run on either big- or little-endian CPUs, but will run slightly less
* efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
*/
typedef unsigned char md5_byte_t; /* 8-bit byte */
typedef unsigned int md5_word_t; /* 32-bit word */
/* Define the state of the MD5 Algorithm. */
typedef struct md5_state_s {
md5_word_t count[2]; /* message length in bits, lsw first */
md5_word_t abcd[4]; /* digest buffer */
md5_byte_t buf[64]; /* accumulate block */
} md5_state_t;
#if defined(__cplusplus)
extern "C" {
#endif
/* Initialize the algorithm. */
MD5_STATIC void md5_init(md5_state_t *pms);
/* Append a string to the message. */
MD5_STATIC void
md5_append(md5_state_t *pms, const md5_byte_t *data, size_t nbytes);
/* Finish the message and return the digest. */
MD5_STATIC void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
#if defined(__cplusplus)
} /* end extern "C" */
#endif
#endif /* md5_INCLUDED */
/*
Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
L. Peter Deutsch
ghost@aladdin.com
*/
/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */
/*
Independent implementation of MD5 (RFC 1321).
This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
copyrighted.
The original and principal author of md5.c is L. Peter Deutsch
<ghost@aladdin.com>. Other authors are noted in the change history
that follows (in reverse chronological order):
2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
either statically or dynamically; added missing #include <string.h>
in library.
2002-03-11 lpd Corrected argument list for main(), and added int return
type, in test program and T value program.
2002-02-21 lpd Added missing #include <stdio.h> in test program.
2000-07-03 lpd Patched to eliminate warnings about "constant is
unsigned in ANSI C, signed in traditional"; made test program
self-checking.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
1999-05-03 lpd Original version.
*/
#if !defined(MD5_STATIC)
#include <string.h>
#endif
#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
#if defined(ARCH_IS_BIG_ENDIAN)
#define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
#else
#define BYTE_ORDER (0)
#endif
#define T_MASK ((md5_word_t)~0)
#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87)
#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9)
#define T3 (0x242070db)
#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111)
#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050)
#define T6 (0x4787c62a)
#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec)
#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe)
#define T9 (0x698098d8)
#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850)
#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e)
#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841)
#define T13 (0x6b901122)
#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c)
#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71)
#define T16 (0x49b40821)
#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d)
#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf)
#define T19 (0x265e5a51)
#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855)
#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2)
#define T22 (0x02441453)
#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e)
#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437)
#define T25 (0x21e1cde6)
#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829)
#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278)
#define T28 (0x455a14ed)
#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa)
#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07)
#define T31 (0x676f02d9)
#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375)
#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd)
#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e)
#define T35 (0x6d9d6122)
#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3)
#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb)
#define T38 (0x4bdecfa9)
#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f)
#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f)
#define T41 (0x289b7ec6)
#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805)
#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a)
#define T44 (0x04881d05)
#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6)
#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a)
#define T47 (0x1fa27cf8)
#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a)
#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb)
#define T50 (0x432aff97)
#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58)
#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6)
#define T53 (0x655b59c3)
#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d)
#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82)
#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e)
#define T57 (0x6fa87e4f)
#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f)
#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb)
#define T60 (0x4e0811a1)
#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d)
#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca)
#define T63 (0x2ad7d2bb)
#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e)
static void
md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
{
md5_word_t a = pms->abcd[0], b = pms->abcd[1], c = pms->abcd[2],
d = pms->abcd[3];
md5_word_t t;
#if BYTE_ORDER > 0
/* Define storage only for big-endian CPUs. */
md5_word_t X[16];
#else
/* Define storage for little-endian or both types of CPUs. */
md5_word_t xbuf[16];
const md5_word_t *X;
#endif
{
#if BYTE_ORDER == 0
/*
* Determine dynamically whether this is a big-endian or
* little-endian machine, since we can use a more efficient
* algorithm on the latter.
*/
static const int w = 1;
if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
#endif
#if BYTE_ORDER <= 0 /* little-endian */
{
/*
* On little-endian machines, we can process properly aligned
* data without copying it.
*/
if (!((data - (const md5_byte_t *)0) & 3)) {
/* data are properly aligned, a direct assignment is possible */
/* cast through a (void *) should avoid a compiler warning,
see
https://github.com/bel2125/civetweb/issues/94#issuecomment-98112861
*/
X = (const md5_word_t *)(const void *)data;
} else {
/* not aligned */
memcpy(xbuf, data, 64);
X = xbuf;
}
}
#endif
#if BYTE_ORDER == 0
else /* dynamic big-endian */
#endif
#if BYTE_ORDER >= 0 /* big-endian */
{
/*
* On big-endian machines, we must arrange the bytes in the
* right order.
*/
const md5_byte_t *xp = data;
int i;
#if BYTE_ORDER == 0
X = xbuf; /* (dynamic only) */
#else
#define xbuf X /* (static only) */
#endif
for (i = 0; i < 16; ++i, xp += 4)
xbuf[i] = (md5_word_t)(xp[0]) + (md5_word_t)(xp[1] << 8)
+ (md5_word_t)(xp[2] << 16)
+ (md5_word_t)(xp[3] << 24);
}
#endif
}
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
/* Round 1. */
/* Let [abcd k s i] denote the operation
a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
#define SET(a, b, c, d, k, s, Ti) \
t = a + F(b, c, d) + X[k] + Ti; \
a = ROTATE_LEFT(t, s) + b
/* Do the following 16 operations. */
SET(a, b, c, d, 0, 7, T1);
SET(d, a, b, c, 1, 12, T2);
SET(c, d, a, b, 2, 17, T3);
SET(b, c, d, a, 3, 22, T4);
SET(a, b, c, d, 4, 7, T5);
SET(d, a, b, c, 5, 12, T6);
SET(c, d, a, b, 6, 17, T7);
SET(b, c, d, a, 7, 22, T8);
SET(a, b, c, d, 8, 7, T9);
SET(d, a, b, c, 9, 12, T10);
SET(c, d, a, b, 10, 17, T11);
SET(b, c, d, a, 11, 22, T12);
SET(a, b, c, d, 12, 7, T13);
SET(d, a, b, c, 13, 12, T14);
SET(c, d, a, b, 14, 17, T15);
SET(b, c, d, a, 15, 22, T16);
#undef SET
/* Round 2. */
/* Let [abcd k s i] denote the operation
a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
#define SET(a, b, c, d, k, s, Ti) \
t = a + G(b, c, d) + X[k] + Ti; \
a = ROTATE_LEFT(t, s) + b
/* Do the following 16 operations. */
SET(a, b, c, d, 1, 5, T17);
SET(d, a, b, c, 6, 9, T18);
SET(c, d, a, b, 11, 14, T19);
SET(b, c, d, a, 0, 20, T20);
SET(a, b, c, d, 5, 5, T21);
SET(d, a, b, c, 10, 9, T22);
SET(c, d, a, b, 15, 14, T23);
SET(b, c, d, a, 4, 20, T24);
SET(a, b, c, d, 9, 5, T25);
SET(d, a, b, c, 14, 9, T26);
SET(c, d, a, b, 3, 14, T27);
SET(b, c, d, a, 8, 20, T28);
SET(a, b, c, d, 13, 5, T29);
SET(d, a, b, c, 2, 9, T30);
SET(c, d, a, b, 7, 14, T31);
SET(b, c, d, a, 12, 20, T32);
#undef SET
/* Round 3. */
/* Let [abcd k s t] denote the operation
a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define SET(a, b, c, d, k, s, Ti) \
t = a + H(b, c, d) + X[k] + Ti; \
a = ROTATE_LEFT(t, s) + b
/* Do the following 16 operations. */
SET(a, b, c, d, 5, 4, T33);
SET(d, a, b, c, 8, 11, T34);
SET(c, d, a, b, 11, 16, T35);
SET(b, c, d, a, 14, 23, T36);
SET(a, b, c, d, 1, 4, T37);
SET(d, a, b, c, 4, 11, T38);
SET(c, d, a, b, 7, 16, T39);
SET(b, c, d, a, 10, 23, T40);
SET(a, b, c, d, 13, 4, T41);
SET(d, a, b, c, 0, 11, T42);
SET(c, d, a, b, 3, 16, T43);
SET(b, c, d, a, 6, 23, T44);
SET(a, b, c, d, 9, 4, T45);
SET(d, a, b, c, 12, 11, T46);
SET(c, d, a, b, 15, 16, T47);
SET(b, c, d, a, 2, 23, T48);
#undef SET
/* Round 4. */
/* Let [abcd k s t] denote the operation
a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
#define SET(a, b, c, d, k, s, Ti) \
t = a + I(b, c, d) + X[k] + Ti; \
a = ROTATE_LEFT(t, s) + b
/* Do the following 16 operations. */
SET(a, b, c, d, 0, 6, T49);
SET(d, a, b, c, 7, 10, T50);
SET(c, d, a, b, 14, 15, T51);
SET(b, c, d, a, 5, 21, T52);
SET(a, b, c, d, 12, 6, T53);
SET(d, a, b, c, 3, 10, T54);
SET(c, d, a, b, 10, 15, T55);
SET(b, c, d, a, 1, 21, T56);
SET(a, b, c, d, 8, 6, T57);
SET(d, a, b, c, 15, 10, T58);
SET(c, d, a, b, 6, 15, T59);
SET(b, c, d, a, 13, 21, T60);
SET(a, b, c, d, 4, 6, T61);
SET(d, a, b, c, 11, 10, T62);
SET(c, d, a, b, 2, 15, T63);
SET(b, c, d, a, 9, 21, T64);
#undef SET
/* Then perform the following additions. (That is increment each
of the four registers by the value it had before this block
was started.) */
pms->abcd[0] += a;
pms->abcd[1] += b;
pms->abcd[2] += c;
pms->abcd[3] += d;
}
MD5_STATIC void
md5_init(md5_state_t *pms)
{
pms->count[0] = pms->count[1] = 0;
pms->abcd[0] = 0x67452301;
pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;
pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301;
pms->abcd[3] = 0x10325476;
}
MD5_STATIC void
md5_append(md5_state_t *pms, const md5_byte_t *data, size_t nbytes)
{
const md5_byte_t *p = data;
size_t left = nbytes;
size_t offset = (pms->count[0] >> 3) & 63;
md5_word_t nbits = (md5_word_t)(nbytes << 3);
if (nbytes <= 0)
return;
/* Update the message length. */
pms->count[1] += (md5_word_t)(nbytes >> 29);
pms->count[0] += nbits;
if (pms->count[0] < nbits)
pms->count[1]++;
/* Process an initial partial block. */
if (offset) {
size_t copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
memcpy(pms->buf + offset, p, copy);
if (offset + copy < 64)
return;
p += copy;
left -= copy;
md5_process(pms, pms->buf);
}
/* Process full blocks. */
for (; left >= 64; p += 64, left -= 64)
md5_process(pms, p);
/* Process a final partial block. */
if (left)
memcpy(pms->buf, p, left);
}
MD5_STATIC void
md5_finish(md5_state_t *pms, md5_byte_t digest[16])
{
static const md5_byte_t pad[64] = {0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
md5_byte_t data[8];
int i;
/* Save the length before padding. */
for (i = 0; i < 8; ++i)
data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
/* Pad to 56 bytes mod 64. */
md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
/* Append the length. */
md5_append(pms, data, 8);
for (i = 0; i < 16; ++i)
digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
}
/* End of md5.inl */

323
module/Vendor/CivetWeb/sha1.inl vendored Normal file
View File

@ -0,0 +1,323 @@
/*
SHA-1 in C
By Steve Reid <sreid@sea-to-sky.net>
100% Public Domain
-----------------
Modified 7/98
By James H. Brown <jbrown@burgoyne.com>
Still 100% Public Domain
Corrected a problem which generated improper hash values on 16 bit machines
Routine SHA1Update changed from
void SHA1Update(SHA_CTX* context, unsigned char* data, unsigned int
len)
to
void SHA1Update(SHA_CTX* context, unsigned char* data, unsigned
long len)
The 'len' parameter was declared an int which works fine on 32 bit machines.
However, on 16 bit machines an int is too small for the shifts being done
against
it. This caused the hash function to generate incorrect values if len was
greater than 8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update().
Since the file IO in main() reads 16K at a time, any file 8K or larger would
be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million
"a"s).
I also changed the declaration of variables i & j in SHA1Update to
unsigned long from unsigned int for the same reason.
These changes should make no difference to any 32 bit implementations since
an
int and a long are the same size in those environments.
--
I also corrected a few compiler warnings generated by Borland C.
1. Added #include <process.h> for exit() prototype
2. Removed unused variable 'j' in SHA1Final
3. Changed exit(0) to return(0) at end of main.
ALL changes I made can be located by searching for comments containing 'JHB'
-----------------
Modified 8/98
By Steve Reid <sreid@sea-to-sky.net>
Still 100% public domain
1- Removed #include <process.h> and used return() instead of exit()
2- Fixed overwriting of finalcount in SHA1Final() (discovered by Chris Hall)
3- Changed email address from steve@edmweb.com to sreid@sea-to-sky.net
-----------------
Modified 4/01
By Saul Kravitz <Saul.Kravitz@celera.com>
Still 100% PD
Modified to run on Compaq Alpha hardware.
-----------------
Modified 07/2002
By Ralph Giles <giles@ghostscript.com>
Still 100% public domain
modified for use with stdint types, autoconf
code cleanup, removed attribution comments
switched SHA1Final() argument order for consistency
use SHA1_ prefix for public api
move public api to sha1.h
*/
/*
11/2016 adapted for CivetWeb:
include sha1.h in sha1.c,
rename to sha1.inl
remove unused #ifdef sections
make endian independent
align buffer to 4 bytes
remove unused variable assignments
*/
/*
Test Vectors (from FIPS PUB 180-1)
"abc"
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
A million repetitions of "a"
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*/
#include <stdint.h>
#include <string.h>
typedef struct {
uint32_t state[5];
uint32_t count[2];
uint8_t buffer[64];
} SHA_CTX;
#define SHA1_DIGEST_SIZE 20
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
/* blk0() and blk() perform the initial expand. */
/* I got the idea of expanding during the round function from SSLeay */
typedef union {
uint8_t c[64];
uint32_t l[16];
} CHAR64LONG16;
static uint32_t
blk0(CHAR64LONG16 *block, int i)
{
static const uint32_t n = 1u;
if ((*((uint8_t *)(&n))) == 1) {
/* little endian / intel byte order */
block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00)
| (rol(block->l[i], 8) & 0x00FF00FF);
}
return block->l[i];
}
#define blk(block, i) \
((block)->l[(i)&15] = \
rol((block)->l[((i) + 13) & 15] ^ (block)->l[((i) + 8) & 15] \
^ (block)->l[((i) + 2) & 15] ^ (block)->l[(i)&15], \
1))
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
#define R0(v, w, x, y, z, i) \
z += ((w & (x ^ y)) ^ y) + blk0(block, i) + 0x5A827999 + rol(v, 5); \
w = rol(w, 30);
#define R1(v, w, x, y, z, i) \
z += ((w & (x ^ y)) ^ y) + blk(block, i) + 0x5A827999 + rol(v, 5); \
w = rol(w, 30);
#define R2(v, w, x, y, z, i) \
z += (w ^ x ^ y) + blk(block, i) + 0x6ED9EBA1 + rol(v, 5); \
w = rol(w, 30);
#define R3(v, w, x, y, z, i) \
z += (((w | x) & y) | (w & x)) + blk(block, i) + 0x8F1BBCDC + rol(v, 5); \
w = rol(w, 30);
#define R4(v, w, x, y, z, i) \
z += (w ^ x ^ y) + blk(block, i) + 0xCA62C1D6 + rol(v, 5); \
w = rol(w, 30);
/* Hash a single 512-bit block. This is the core of the algorithm. */
static void
SHA1_Transform(uint32_t state[5], const uint8_t buffer[64])
{
uint32_t a, b, c, d, e;
/* Must use an aligned, read/write buffer */
CHAR64LONG16 block[1];
memcpy(block, buffer, sizeof(block));
/* Copy context->state[] to working vars */
a = state[0];
b = state[1];
c = state[2];
d = state[3];
e = state[4];
/* 4 rounds of 20 operations each. Loop unrolled. */
R0(a, b, c, d, e, 0);
R0(e, a, b, c, d, 1);
R0(d, e, a, b, c, 2);
R0(c, d, e, a, b, 3);
R0(b, c, d, e, a, 4);
R0(a, b, c, d, e, 5);
R0(e, a, b, c, d, 6);
R0(d, e, a, b, c, 7);
R0(c, d, e, a, b, 8);
R0(b, c, d, e, a, 9);
R0(a, b, c, d, e, 10);
R0(e, a, b, c, d, 11);
R0(d, e, a, b, c, 12);
R0(c, d, e, a, b, 13);
R0(b, c, d, e, a, 14);
R0(a, b, c, d, e, 15);
R1(e, a, b, c, d, 16);
R1(d, e, a, b, c, 17);
R1(c, d, e, a, b, 18);
R1(b, c, d, e, a, 19);
R2(a, b, c, d, e, 20);
R2(e, a, b, c, d, 21);
R2(d, e, a, b, c, 22);
R2(c, d, e, a, b, 23);
R2(b, c, d, e, a, 24);
R2(a, b, c, d, e, 25);
R2(e, a, b, c, d, 26);
R2(d, e, a, b, c, 27);
R2(c, d, e, a, b, 28);
R2(b, c, d, e, a, 29);
R2(a, b, c, d, e, 30);
R2(e, a, b, c, d, 31);
R2(d, e, a, b, c, 32);
R2(c, d, e, a, b, 33);
R2(b, c, d, e, a, 34);
R2(a, b, c, d, e, 35);
R2(e, a, b, c, d, 36);
R2(d, e, a, b, c, 37);
R2(c, d, e, a, b, 38);
R2(b, c, d, e, a, 39);
R3(a, b, c, d, e, 40);
R3(e, a, b, c, d, 41);
R3(d, e, a, b, c, 42);
R3(c, d, e, a, b, 43);
R3(b, c, d, e, a, 44);
R3(a, b, c, d, e, 45);
R3(e, a, b, c, d, 46);
R3(d, e, a, b, c, 47);
R3(c, d, e, a, b, 48);
R3(b, c, d, e, a, 49);
R3(a, b, c, d, e, 50);
R3(e, a, b, c, d, 51);
R3(d, e, a, b, c, 52);
R3(c, d, e, a, b, 53);
R3(b, c, d, e, a, 54);
R3(a, b, c, d, e, 55);
R3(e, a, b, c, d, 56);
R3(d, e, a, b, c, 57);
R3(c, d, e, a, b, 58);
R3(b, c, d, e, a, 59);
R4(a, b, c, d, e, 60);
R4(e, a, b, c, d, 61);
R4(d, e, a, b, c, 62);
R4(c, d, e, a, b, 63);
R4(b, c, d, e, a, 64);
R4(a, b, c, d, e, 65);
R4(e, a, b, c, d, 66);
R4(d, e, a, b, c, 67);
R4(c, d, e, a, b, 68);
R4(b, c, d, e, a, 69);
R4(a, b, c, d, e, 70);
R4(e, a, b, c, d, 71);
R4(d, e, a, b, c, 72);
R4(c, d, e, a, b, 73);
R4(b, c, d, e, a, 74);
R4(a, b, c, d, e, 75);
R4(e, a, b, c, d, 76);
R4(d, e, a, b, c, 77);
R4(c, d, e, a, b, 78);
R4(b, c, d, e, a, 79);
/* Add the working vars back into context.state[] */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;
}
/* SHA1Init - Initialize new context */
SHA_API void
SHA1_Init(SHA_CTX *context)
{
/* SHA1 initialization constants */
context->state[0] = 0x67452301;
context->state[1] = 0xEFCDAB89;
context->state[2] = 0x98BADCFE;
context->state[3] = 0x10325476;
context->state[4] = 0xC3D2E1F0;
context->count[0] = context->count[1] = 0;
}
SHA_API void
SHA1_Update(SHA_CTX *context, const uint8_t *data, const uint32_t len)
{
uint32_t i, j;
j = context->count[0];
if ((context->count[0] += (len << 3)) < j) {
context->count[1]++;
}
context->count[1] += (len >> 29);
j = (j >> 3) & 63;
if ((j + len) > 63) {
i = 64 - j;
memcpy(&context->buffer[j], data, i);
SHA1_Transform(context->state, context->buffer);
for (; i + 63 < len; i += 64) {
SHA1_Transform(context->state, &data[i]);
}
j = 0;
} else {
i = 0;
}
memcpy(&context->buffer[j], &data[i], len - i);
}
/* Add padding and return the message digest. */
SHA_API void
SHA1_Final(unsigned char *digest, SHA_CTX *context)
{
uint32_t i;
uint8_t finalcount[8];
for (i = 0; i < 8; i++) {
finalcount[i] =
(uint8_t)((context->count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8))
& 255); /* Endian independent */
}
SHA1_Update(context, (uint8_t *)"\x80", 1);
while ((context->count[0] & 504) != 448) {
SHA1_Update(context, (uint8_t *)"\x00", 1);
}
SHA1_Update(context, finalcount, 8); /* Should cause a SHA1_Transform() */
for (i = 0; i < SHA1_DIGEST_SIZE; i++) {
digest[i] =
(uint8_t)((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
}
/* Wipe variables */
memset(context, '\0', sizeof(*context));
}
/* End of sha1.inl */

294
module/Vendor/CivetWeb/timer.inl vendored Normal file
View File

@ -0,0 +1,294 @@
/* This file is part of the CivetWeb web server.
* See https://github.com/civetweb/civetweb/
* (C) 2014-2020 by the CivetWeb authors, MIT license.
*/
#if !defined(MAX_TIMERS)
#define MAX_TIMERS MAX_WORKER_THREADS
#endif
#if !defined(TIMER_RESOLUTION)
/* Timer resolution in ms */
#define TIMER_RESOLUTION (10)
#endif
typedef int (*taction)(void *arg);
typedef void (*tcancelaction)(void *arg);
struct ttimer {
double time;
double period;
taction action;
void *arg;
tcancelaction cancel;
};
struct ttimers {
pthread_t threadid; /* Timer thread ID */
pthread_mutex_t mutex; /* Protects timer lists */
struct ttimer *timers; /* List of timers */
unsigned timer_count; /* Current size of timer list */
unsigned timer_capacity; /* Capacity of timer list */
#if defined(_WIN32)
DWORD last_tick;
uint64_t now_tick64;
#endif
};
TIMER_API double
timer_getcurrenttime(struct mg_context *ctx)
{
#if defined(_WIN32)
/* GetTickCount returns milliseconds since system start as
* unsigned 32 bit value. It will wrap around every 49.7 days.
* We need to use a 64 bit counter (will wrap in 500 mio. years),
* by adding the 32 bit difference since the last call to a
* 64 bit counter. This algorithm will only work, if this
* function is called at least once every 7 weeks. */
uint64_t now_tick64 = 0;
DWORD now_tick = GetTickCount();
if (ctx->timers) {
pthread_mutex_lock(&ctx->timers->mutex);
ctx->timers->now_tick64 += now_tick - ctx->timers->last_tick;
now_tick64 = ctx->timers->now_tick64;
ctx->timers->last_tick = now_tick;
pthread_mutex_unlock(&ctx->timers->mutex);
}
return (double)now_tick64 * 1.0E-3;
#else
struct timespec now_ts;
(void)ctx;
clock_gettime(CLOCK_MONOTONIC, &now_ts);
return (double)now_ts.tv_sec + (double)now_ts.tv_nsec * 1.0E-9;
#endif
}
TIMER_API int
timer_add(struct mg_context *ctx,
double next_time,
double period,
int is_relative,
taction action,
void *arg,
tcancelaction cancel)
{
int error = 0;
double now;
if (!ctx->timers) {
return 1;
}
now = timer_getcurrenttime(ctx);
/* HCP24: if is_relative = 0 and next_time < now
* action will be called so fast as possible
* if additional period > 0
* action will be called so fast as possible
* n times until (next_time + (n * period)) > now
* then the period is working
* Solution:
* if next_time < now then we set next_time = now.
* The first callback will be so fast as possible (now)
* but the next callback on period
*/
if (is_relative) {
next_time += now;
}
/* You can not set timers into the past */
if (next_time < now) {
next_time = now;
}
pthread_mutex_lock(&ctx->timers->mutex);
if (ctx->timers->timer_count == MAX_TIMERS) {
error = 1;
} else if (ctx->timers->timer_count == ctx->timers->timer_capacity) {
unsigned capacity = (ctx->timers->timer_capacity * 2) + 1;
struct ttimer *timers =
(struct ttimer *)mg_realloc_ctx(ctx->timers->timers,
capacity * sizeof(struct ttimer),
ctx);
if (timers) {
ctx->timers->timers = timers;
ctx->timers->timer_capacity = capacity;
} else {
error = 1;
}
}
if (!error) {
/* Insert new timer into a sorted list. */
/* The linear list is still most efficient for short lists (small
* number of timers) - if there are many timers, different
* algorithms will work better. */
unsigned u = ctx->timers->timer_count;
for (; (u > 0) && (ctx->timers->timers[u - 1].time > next_time); u--) {
ctx->timers->timers[u] = ctx->timers->timers[u - 1];
}
ctx->timers->timers[u].time = next_time;
ctx->timers->timers[u].period = period;
ctx->timers->timers[u].action = action;
ctx->timers->timers[u].arg = arg;
ctx->timers->timers[u].cancel = cancel;
ctx->timers->timer_count++;
}
pthread_mutex_unlock(&ctx->timers->mutex);
return error;
}
static void
timer_thread_run(void *thread_func_param)
{
struct mg_context *ctx = (struct mg_context *)thread_func_param;
double d;
unsigned u;
int action_res;
struct ttimer t;
mg_set_thread_name("timer");
if (ctx->callbacks.init_thread) {
/* Timer thread */
ctx->callbacks.init_thread(ctx, 2);
}
/* Timer main loop */
d = timer_getcurrenttime(ctx);
while (STOP_FLAG_IS_ZERO(&ctx->stop_flag)) {
pthread_mutex_lock(&ctx->timers->mutex);
if ((ctx->timers->timer_count > 0)
&& (d >= ctx->timers->timers[0].time)) {
/* Timer list is sorted. First action should run now. */
/* Store active timer in "t" */
t = ctx->timers->timers[0];
/* Shift all other timers */
for (u = 1; u < ctx->timers->timer_count; u++) {
ctx->timers->timers[u - 1] = ctx->timers->timers[u];
}
ctx->timers->timer_count--;
pthread_mutex_unlock(&ctx->timers->mutex);
/* Call timer action */
action_res = t.action(t.arg);
/* action_res == 1: reschedule */
/* action_res == 0: do not reschedule, free(arg) */
if ((action_res > 0) && (t.period > 0)) {
/* Should schedule timer again */
timer_add(ctx,
t.time + t.period,
t.period,
0,
t.action,
t.arg,
t.cancel);
} else {
/* Allow user to free timer argument */
if (t.cancel != NULL) {
t.cancel(t.arg);
}
}
continue;
} else {
pthread_mutex_unlock(&ctx->timers->mutex);
}
/* TIMER_RESOLUTION = 10 ms seems reasonable.
* A faster loop (smaller sleep value) increases CPU load,
* a slower loop (higher sleep value) decreases timer accuracy.
*/
mg_sleep(TIMER_RESOLUTION);
d = timer_getcurrenttime(ctx);
}
/* Remove remaining timers */
for (u = 0; u < ctx->timers->timer_count; u++) {
t = ctx->timers->timers[u];
if (t.cancel != NULL) {
t.cancel(t.arg);
}
}
}
#if defined(_WIN32)
static unsigned __stdcall timer_thread(void *thread_func_param)
{
timer_thread_run(thread_func_param);
return 0;
}
#else
static void *
timer_thread(void *thread_func_param)
{
struct sigaction sa;
/* Ignore SIGPIPE */
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &sa, NULL);
timer_thread_run(thread_func_param);
return NULL;
}
#endif /* _WIN32 */
TIMER_API int
timers_init(struct mg_context *ctx)
{
/* Initialize timers data structure */
ctx->timers =
(struct ttimers *)mg_calloc_ctx(sizeof(struct ttimers), 1, ctx);
if (!ctx->timers) {
return -1;
}
ctx->timers->timers = NULL;
/* Initialize mutex */
if (0 != pthread_mutex_init(&ctx->timers->mutex, NULL)) {
mg_free(ctx->timers);
ctx->timers = NULL;
return -1;
}
/* For some systems timer_getcurrenttime does some initialization
* during the first call. Call it once now, ignore the result. */
(void)timer_getcurrenttime(ctx);
/* Start timer thread */
if (mg_start_thread_with_id(timer_thread, ctx, &ctx->timers->threadid)
!= 0) {
(void)pthread_mutex_destroy(&ctx->timers->mutex);
mg_free(ctx->timers);
ctx->timers = NULL;
return -1;
}
return 0;
}
TIMER_API void
timers_exit(struct mg_context *ctx)
{
if (ctx->timers) {
mg_join_thread(ctx->timers->threadid);
(void)pthread_mutex_destroy(&ctx->timers->mutex);
mg_free(ctx->timers->timers);
mg_free(ctx->timers);
ctx->timers = NULL;
}
}
/* End of timer.inl */

View File

@ -0,0 +1,77 @@
/* Additional defines for WolfSSL, see
* https://github.com/civetweb/civetweb/issues/583 */
/* Required for WOLFSSL_X509 */
#include <openssl/../internal.h>
#define i2d_X509 cw_i2d_X509
#define EVP_Digest cw_EVP_Digest
/* i2d_X509 has no valid implementation in wolfssl
*
* The letters i and d in for example i2d_X509 stand for "internal" (that is an
*internal C structure)
* and " DER ". So that i2d_X509 converts from internal to DER.
*
* For OpenSSL 0.9.7 and later if *out is NULL memory will be allocated for a
*buffer and the encoded
* data written to it. In this case *out is not incremented and it points to the
*start of the data
* just written.
*/
int
cw_i2d_X509(struct WOLFSSL_X509 *x, unsigned char **out)
{
if (!x || !x->derCert) {
return -1;
}
const int ret = (int)x->derCert->length;
if (out && (ret > 0)) {
if (*out == NULL) {
*out = mg_malloc(ret);
}
if (*out != NULL) {
memcpy(*out, x->derCert->buffer, ret);
}
}
return ret;
}
/* EVP_Digest not in wolfssl */
int
cw_EVP_Digest(const void *data,
size_t count,
unsigned char *md,
unsigned int *size,
const EVP_MD *type,
ENGINE *impl)
{
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
int ret;
if (ctx == NULL)
return 0;
/* EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_ONESHOT); */
ret = EVP_DigestInit_ex(ctx, type, impl)
&& EVP_DigestUpdate(ctx, data, count)
&& EVP_DigestFinal_ex(ctx, md, size);
EVP_MD_CTX_free(ctx);
return ret;
}
/*
* the variable SSL_OP_NO_TLSv1_1 is not defined within the context of
* wolfssl but since the methods using the value are all stubs, we can
* define it arbitrarily and it will not have any consequences
*/
#define SSL_OP_NO_TLSv1_1 (0x10000000L)