Cleanup whitespace from code and config

This commit is contained in:
fliiiix
2024-08-30 09:17:12 +02:00
committed by gittiver
parent e452aac963
commit 43cba57e70
15 changed files with 223 additions and 222 deletions

View File

@@ -49,7 +49,7 @@ ContinuationIndentWidth: '2'
Cpp11BracedListStyle: 'true'
FixNamespaceComments: 'true'
IncludeBlocks: Regroup
IncludeCategories:
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 2
@@ -87,7 +87,7 @@ SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'false'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
#SpacesInLineCommentPrefix:
#SpacesInLineCommentPrefix:
# Minimum: 1
# Maximum: -1
Standard: Cpp11

View File

@@ -20,7 +20,7 @@ jobs:
- name: prepate pip dependencies
run: pip3 install mkdocs-material mkdocs-redirects pyyaml mkdocs-meta-descriptions-plugin mike --no-input
- name: configure
run: cmake -B build -DCROW_AMALGAMATE=ON
run: cmake -B build -DCROW_AMALGAMATE=ON
- name: clean generated docs dir
run: rm -rf site docs/reference
- name: clone doxygen theme

View File

@@ -37,7 +37,7 @@ if (MSVC)
endif ()
include(FindPython3)
find_package(Python3)
find_package(Python3)
#####################################
# Define Options

View File

@@ -1,6 +1,6 @@
/*
* SHA1 Wikipedia Page: http://en.wikipedia.org/wiki/SHA-1
*
*
* Copyright (c) 2012-22 SAURAV MOHAPATRA <mohaps@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -16,7 +16,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
/**
* \file TinySHA1.hpp
* \author SAURAV MOHAPATRA <mohaps@gmail.com>
* \date 2012-22
@@ -39,175 +39,175 @@
*/
namespace sha1
{
/**
* \class SHA1
* \brief A tiny SHA1 algorithm implementation used internally in the
* Crow server (specifically in crow/websocket.h).
*/
class SHA1
{
public:
typedef uint32_t digest32_t[5];
typedef uint8_t digest8_t[20];
inline static uint32_t LeftRotate(uint32_t value, size_t count) {
return (value << count) ^ (value >> (32-count));
}
SHA1(){ reset(); }
virtual ~SHA1() {}
SHA1(const SHA1& s) { *this = s; }
const SHA1& operator = (const SHA1& s) {
memcpy(m_digest, s.m_digest, 5 * sizeof(uint32_t));
memcpy(m_block, s.m_block, 64);
m_blockByteIndex = s.m_blockByteIndex;
m_byteCount = s.m_byteCount;
return *this;
}
SHA1& reset() {
m_digest[0] = 0x67452301;
m_digest[1] = 0xEFCDAB89;
m_digest[2] = 0x98BADCFE;
m_digest[3] = 0x10325476;
m_digest[4] = 0xC3D2E1F0;
m_blockByteIndex = 0;
m_byteCount = 0;
return *this;
}
SHA1& processByte(uint8_t octet) {
this->m_block[this->m_blockByteIndex++] = octet;
++this->m_byteCount;
if(m_blockByteIndex == 64) {
this->m_blockByteIndex = 0;
processBlock();
}
return *this;
}
SHA1& processBlock(const void* const start, const void* const end) {
const uint8_t* begin = static_cast<const uint8_t*>(start);
const uint8_t* finish = static_cast<const uint8_t*>(end);
while(begin != finish) {
processByte(*begin);
begin++;
}
return *this;
}
SHA1& processBytes(const void* const data, size_t len) {
const uint8_t* block = static_cast<const uint8_t*>(data);
processBlock(block, block + len);
return *this;
}
const uint32_t* getDigest(digest32_t digest) {
size_t bitCount = this->m_byteCount * 8;
processByte(0x80);
if (this->m_blockByteIndex > 56) {
while (m_blockByteIndex != 0) {
processByte(0);
}
while (m_blockByteIndex < 56) {
processByte(0);
}
} else {
while (m_blockByteIndex < 56) {
processByte(0);
}
}
processByte(0);
processByte(0);
processByte(0);
processByte(0);
processByte( static_cast<unsigned char>((bitCount>>24) & 0xFF));
processByte( static_cast<unsigned char>((bitCount>>16) & 0xFF));
processByte( static_cast<unsigned char>((bitCount>>8 ) & 0xFF));
processByte( static_cast<unsigned char>((bitCount) & 0xFF));
memcpy(digest, m_digest, 5 * sizeof(uint32_t));
return digest;
}
const uint8_t* getDigestBytes(digest8_t digest) {
digest32_t d32;
getDigest(d32);
size_t di = 0;
digest[di++] = ((d32[0] >> 24) & 0xFF);
digest[di++] = ((d32[0] >> 16) & 0xFF);
digest[di++] = ((d32[0] >> 8) & 0xFF);
digest[di++] = ((d32[0]) & 0xFF);
digest[di++] = ((d32[1] >> 24) & 0xFF);
digest[di++] = ((d32[1] >> 16) & 0xFF);
digest[di++] = ((d32[1] >> 8) & 0xFF);
digest[di++] = ((d32[1]) & 0xFF);
digest[di++] = ((d32[2] >> 24) & 0xFF);
digest[di++] = ((d32[2] >> 16) & 0xFF);
digest[di++] = ((d32[2] >> 8) & 0xFF);
digest[di++] = ((d32[2]) & 0xFF);
digest[di++] = ((d32[3] >> 24) & 0xFF);
digest[di++] = ((d32[3] >> 16) & 0xFF);
digest[di++] = ((d32[3] >> 8) & 0xFF);
digest[di++] = ((d32[3]) & 0xFF);
digest[di++] = ((d32[4] >> 24) & 0xFF);
digest[di++] = ((d32[4] >> 16) & 0xFF);
digest[di++] = ((d32[4] >> 8) & 0xFF);
digest[di++] = ((d32[4]) & 0xFF);
return digest;
}
protected:
void processBlock() {
uint32_t w[80];
for (size_t i = 0; i < 16; i++) {
w[i] = (m_block[i*4 + 0] << 24);
w[i] |= (m_block[i*4 + 1] << 16);
w[i] |= (m_block[i*4 + 2] << 8);
w[i] |= (m_block[i*4 + 3]);
}
for (size_t i = 16; i < 80; i++) {
w[i] = LeftRotate((w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16]), 1);
}
uint32_t a = m_digest[0];
uint32_t b = m_digest[1];
uint32_t c = m_digest[2];
uint32_t d = m_digest[3];
uint32_t e = m_digest[4];
for (std::size_t i=0; i<80; ++i) {
uint32_t f = 0;
uint32_t k = 0;
if (i<20) {
f = (b & c) | (~b & d);
k = 0x5A827999;
} else if (i<40) {
f = b ^ c ^ d;
k = 0x6ED9EBA1;
} else if (i<60) {
f = (b & c) | (b & d) | (c & d);
k = 0x8F1BBCDC;
} else {
f = b ^ c ^ d;
k = 0xCA62C1D6;
}
uint32_t temp = LeftRotate(a, 5) + f + e + k + w[i];
e = d;
d = c;
c = LeftRotate(b, 30);
b = a;
a = temp;
}
m_digest[0] += a;
m_digest[1] += b;
m_digest[2] += c;
m_digest[3] += d;
m_digest[4] += e;
}
private:
digest32_t m_digest;
uint8_t m_block[64];
size_t m_blockByteIndex;
size_t m_byteCount;
};
/**
* \class SHA1
* \brief A tiny SHA1 algorithm implementation used internally in the
* Crow server (specifically in crow/websocket.h).
*/
class SHA1
{
public:
typedef uint32_t digest32_t[5];
typedef uint8_t digest8_t[20];
inline static uint32_t LeftRotate(uint32_t value, size_t count) {
return (value << count) ^ (value >> (32-count));
}
SHA1(){ reset(); }
virtual ~SHA1() {}
SHA1(const SHA1& s) { *this = s; }
const SHA1& operator = (const SHA1& s) {
memcpy(m_digest, s.m_digest, 5 * sizeof(uint32_t));
memcpy(m_block, s.m_block, 64);
m_blockByteIndex = s.m_blockByteIndex;
m_byteCount = s.m_byteCount;
return *this;
}
SHA1& reset() {
m_digest[0] = 0x67452301;
m_digest[1] = 0xEFCDAB89;
m_digest[2] = 0x98BADCFE;
m_digest[3] = 0x10325476;
m_digest[4] = 0xC3D2E1F0;
m_blockByteIndex = 0;
m_byteCount = 0;
return *this;
}
SHA1& processByte(uint8_t octet) {
this->m_block[this->m_blockByteIndex++] = octet;
++this->m_byteCount;
if(m_blockByteIndex == 64) {
this->m_blockByteIndex = 0;
processBlock();
}
return *this;
}
SHA1& processBlock(const void* const start, const void* const end) {
const uint8_t* begin = static_cast<const uint8_t*>(start);
const uint8_t* finish = static_cast<const uint8_t*>(end);
while(begin != finish) {
processByte(*begin);
begin++;
}
return *this;
}
SHA1& processBytes(const void* const data, size_t len) {
const uint8_t* block = static_cast<const uint8_t*>(data);
processBlock(block, block + len);
return *this;
}
const uint32_t* getDigest(digest32_t digest) {
size_t bitCount = this->m_byteCount * 8;
processByte(0x80);
if (this->m_blockByteIndex > 56) {
while (m_blockByteIndex != 0) {
processByte(0);
}
while (m_blockByteIndex < 56) {
processByte(0);
}
} else {
while (m_blockByteIndex < 56) {
processByte(0);
}
}
processByte(0);
processByte(0);
processByte(0);
processByte(0);
processByte( static_cast<unsigned char>((bitCount>>24) & 0xFF));
processByte( static_cast<unsigned char>((bitCount>>16) & 0xFF));
processByte( static_cast<unsigned char>((bitCount>>8 ) & 0xFF));
processByte( static_cast<unsigned char>((bitCount) & 0xFF));
memcpy(digest, m_digest, 5 * sizeof(uint32_t));
return digest;
}
const uint8_t* getDigestBytes(digest8_t digest) {
digest32_t d32;
getDigest(d32);
size_t di = 0;
digest[di++] = ((d32[0] >> 24) & 0xFF);
digest[di++] = ((d32[0] >> 16) & 0xFF);
digest[di++] = ((d32[0] >> 8) & 0xFF);
digest[di++] = ((d32[0]) & 0xFF);
digest[di++] = ((d32[1] >> 24) & 0xFF);
digest[di++] = ((d32[1] >> 16) & 0xFF);
digest[di++] = ((d32[1] >> 8) & 0xFF);
digest[di++] = ((d32[1]) & 0xFF);
digest[di++] = ((d32[2] >> 24) & 0xFF);
digest[di++] = ((d32[2] >> 16) & 0xFF);
digest[di++] = ((d32[2] >> 8) & 0xFF);
digest[di++] = ((d32[2]) & 0xFF);
digest[di++] = ((d32[3] >> 24) & 0xFF);
digest[di++] = ((d32[3] >> 16) & 0xFF);
digest[di++] = ((d32[3] >> 8) & 0xFF);
digest[di++] = ((d32[3]) & 0xFF);
digest[di++] = ((d32[4] >> 24) & 0xFF);
digest[di++] = ((d32[4] >> 16) & 0xFF);
digest[di++] = ((d32[4] >> 8) & 0xFF);
digest[di++] = ((d32[4]) & 0xFF);
return digest;
}
protected:
void processBlock() {
uint32_t w[80];
for (size_t i = 0; i < 16; i++) {
w[i] = (m_block[i*4 + 0] << 24);
w[i] |= (m_block[i*4 + 1] << 16);
w[i] |= (m_block[i*4 + 2] << 8);
w[i] |= (m_block[i*4 + 3]);
}
for (size_t i = 16; i < 80; i++) {
w[i] = LeftRotate((w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16]), 1);
}
uint32_t a = m_digest[0];
uint32_t b = m_digest[1];
uint32_t c = m_digest[2];
uint32_t d = m_digest[3];
uint32_t e = m_digest[4];
for (std::size_t i=0; i<80; ++i) {
uint32_t f = 0;
uint32_t k = 0;
if (i<20) {
f = (b & c) | (~b & d);
k = 0x5A827999;
} else if (i<40) {
f = b ^ c ^ d;
k = 0x6ED9EBA1;
} else if (i<60) {
f = (b & c) | (b & d) | (c & d);
k = 0x8F1BBCDC;
} else {
f = b ^ c ^ d;
k = 0xCA62C1D6;
}
uint32_t temp = LeftRotate(a, 5) + f + e + k + w[i];
e = d;
d = c;
c = LeftRotate(b, 30);
b = a;
a = temp;
}
m_digest[0] += a;
m_digest[1] += b;
m_digest[2] += c;
m_digest[3] += d;
m_digest[4] += e;
}
private:
digest32_t m_digest;
uint8_t m_block[64];
size_t m_blockByteIndex;
size_t m_byteCount;
};
}
#endif

View File

@@ -157,7 +157,7 @@
* using this macro.
*
* \see [Page of the guide "Routes" (Catchall routes)](https://crowcpp.org/master/guides/routes/#catchall-routes).
*/
*/
#define CROW_CATCHALL_ROUTE(app) app.catchall_route()
/**
@@ -169,7 +169,7 @@
* undefined route in the blueprint.
*
* \see [Page of the guide "Blueprint" (Define a custom Catchall route)](https://crowcpp.org/master/guides/blueprints/#define-a-custom-catchall-route).
*/
*/
#define CROW_BP_CATCHALL_ROUTE(blueprint) blueprint.catchall_rule()
@@ -178,7 +178,7 @@
* \brief The main namespace of the library. In this namespace
* is defined the most important classes and functions of the
* library.
*
*
* Within this namespace, the Crow class, Router class, Connection
* class, and other are defined.
*/
@@ -394,7 +394,7 @@ namespace crow
return res_stream_threshold_;
}
self_t& register_blueprint(Blueprint& blueprint)
{
router_.register_blueprint(blueprint);
@@ -428,7 +428,7 @@ namespace crow
}
#ifdef CROW_ENABLE_COMPRESSION
self_t& use_compression(compression::algorithm algorithm)
{
comp_algorithm_ = algorithm;
@@ -631,7 +631,7 @@ namespace crow
return ssl_used_;
}
#else
template<typename T, typename... Remain>
self_t& ssl_file(T&&, Remain&&...)
{

View File

@@ -144,7 +144,7 @@ namespace crow
req_.middleware_context = static_cast<void*>(&ctx_);
req_.middleware_container = static_cast<void*>(middlewares_);
req_.io_service = &adaptor_.get_io_service();
req_.remote_ip_address = adaptor_.remote_endpoint().address().to_string();
add_keep_alive_ = req_.keep_alive;
@@ -167,7 +167,7 @@ namespace crow
}
else
{
detail::middleware_call_helper<detail::middleware_call_criteria_only_global,
0, decltype(ctx_), decltype(*middlewares_)>({}, *middlewares_, req_, res, ctx_);
close_connection_ = true;
@@ -188,7 +188,7 @@ namespace crow
res.is_alive_helper_ = [self]() -> bool {
return self->adaptor_.is_open();
};
detail::middleware_call_helper<detail::middleware_call_criteria_only_global,
0, decltype(ctx_), decltype(*middlewares_)>({}, *middlewares_, req_, res, ctx_);
@@ -530,7 +530,7 @@ namespace crow
adaptor_.socket(), buffers_,
[self](const error_code& ec, std::size_t /*bytes_transferred*/) {
self->res.clear();
self->res_body_copy_.clear();
self->res_body_copy_.clear();
if (!self->continue_requested)
{
self->parser_.clear();
@@ -539,7 +539,7 @@ namespace crow
{
self->continue_requested = false;
}
if (!ec)
{
if (self->close_connection_)

View File

@@ -701,7 +701,7 @@ static const int8_t unhex[256] =
const char *body_mark = 0;
const unsigned int lenient = parser->lenient_http_headers;
const unsigned int allow_chunked_length = parser->allow_chunked_length;
uint32_t nread = parser->nread;
/* We're in an error state. Don't bother doing anything. */
@@ -1104,7 +1104,7 @@ reexecute:
}
case s_header_field:
{
{
const char* start = p;
for (; p != data + len; p++) {
ch = *p;
@@ -1112,7 +1112,7 @@ reexecute:
if (!c)
break;
switch (parser->header_state) {
case h_general: {
size_t left = data + len - p;
@@ -1292,7 +1292,7 @@ reexecute:
parser->header_state = h_matching_transfer_encoding_token;
}
break;
/* Multi-value `Transfer-Encoding` header */
case h_matching_transfer_encoding_token_start:
break;
@@ -1302,7 +1302,7 @@ reexecute:
CROW_SET_ERRNO(CHPE_INVALID_CONTENT_LENGTH);
goto error;
}
if (parser->flags & F_CONTENTLENGTH) {
CROW_SET_ERRNO(CHPE_UNEXPECTED_CONTENT_LENGTH);
goto error;
@@ -1359,12 +1359,12 @@ reexecute:
CROW_CALLBACK_DATA_NOADVANCE(header_value);
CROW_REEXECUTE();
}
if (!lenient && !CROW_IS_HEADER_CHAR(ch)) {
CROW_SET_ERRNO(CHPE_INVALID_HEADER_TOKEN);
goto error;
}
c = CROW_LOWER(ch);
switch (h_state) {
@@ -1428,7 +1428,7 @@ reexecute:
parser->content_length = t;
break;
}
case h_content_length_ws:
if (ch == ' ') break;
CROW_SET_ERRNO(CHPE_INVALID_CONTENT_LENGTH);
@@ -1506,11 +1506,11 @@ reexecute:
}
}
parser->header_state = h_state;
if (p == data + len)
--p;
CROW_COUNT_HEADER_SIZE(p - start);
break;
}
@@ -1586,7 +1586,7 @@ reexecute:
CROW_CALLBACK_NOTIFY(message_complete);
break;
}
/* Cannot use transfer-encoding and a content-length header together
per the HTTP specification. (RFC 7230 Section 3.3.3) */
if ((parser->uses_transfer_encoding == 1) &&
@@ -1604,7 +1604,7 @@ reexecute:
goto error;
}
}
parser->state = s_headers_done;
/* Set this here so that on_headers_complete() callbacks can see it */

View File

@@ -1885,7 +1885,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
sprintf_s(outbuf, sizeof(outbuf), "%f", v.num.d);
#else
snprintf(outbuf, sizeof(outbuf), "%f", v.num.d);
#endif
#endif
}
char *p = &outbuf[0], *o = nullptr; // o is the position of the first trailing 0
f_state = start;
@@ -2046,7 +2046,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
{
int64_t get(int64_t fallback)
{
if (ref.t() != type::Number || ref.nt == num_type::Floating_point ||
if (ref.t() != type::Number || ref.nt == num_type::Floating_point ||
ref.nt == num_type::Double_precision_floating_point)
return fallback;
return ref.num.si;

View File

@@ -33,7 +33,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
*
* As name suggest, crow uses [mustache](https://en.wikipedia.org/wiki/Mustache_(template_system))
* as main template rendering system.
*
*
* You may be interested in taking a look at the [Templating guide
* page](https://crowcpp.org/master/guides/templating/).
*/
@@ -90,7 +90,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
* \enum ActionType
* \brief Used in \ref Action to represent different parsing
* behaviors.
*
*
* \see \ref Action
*/
enum class ActionType
@@ -108,7 +108,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
* \struct Action
* \brief Used during mustache template compilation to
* represent parsing actions.
*
*
* \see \ref compile
* \see \ref template_t
*/

View File

@@ -96,7 +96,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
{}
virtual void validate() = 0;
void set_added() {
added_ = true;
}

View File

@@ -6,7 +6,7 @@ repo_url: https://github.com/CrowCpp/Crow
site_url: https://crowcpp.org
edit_uri: ""
theme:
theme:
name: material
font: false
language: 'en'
@@ -46,7 +46,7 @@ markdown_extensions:
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg
nav:
- Home: index.md
- Getting Started:
@@ -81,7 +81,7 @@ nav:
- Systemd run on startup: guides/syste.md
- API Reference:
- API Reference: 'reference/index.html'
extra:
version:
provider: mike

View File

@@ -35,7 +35,7 @@ __AUTHOR__="Jeroen de Bruijn"
# The branch should be empty except for an empty '.nojekyll' file and an
# 'index.html' file that redirects to master/index.html. Optionally you would
# also need a 'CNAME' file containing your custom domain (without http or www).
#
#
################################################################################
################################################################################
@@ -83,7 +83,7 @@ echo 'Removing old documentation...'
rm -rf *
echo 'Generating MkDocs documentation...'
# Copy the mkdocs documentation to the work directory and generate the mkdocs'
# Copy the mkdocs documentation to the work directory and generate the mkdocs'
# 'site' directory
cp ../../../mkdocs.yml .
cp -r ../../../docs .
@@ -102,7 +102,7 @@ echo 'Generating Doxygen code documentation...'
# Redirect both stderr and stdout to the log file AND the console.
doxygen $DOXYFILE 2>&1 | tee doxygen.log
# Rename mkdocs' output folder to 'html' to retain compatibility with the
# Rename mkdocs' output folder to 'html' to retain compatibility with the
# existing index.html and the rest of this code.
# Also remove any remaining documentation files.
mv site/* .
@@ -114,8 +114,8 @@ mv versions.json ../
################################################################################
##### Upload the documentation to the gh-pages branch of the repository. #####
# Only upload if Doxygen successfully created the documentation.
# Check this by verifying that the reference directory (for doxygen) and
# the file index.html (for mkdocs) both exist.
# Check this by verifying that the reference directory (for doxygen) and
# the file index.html (for mkdocs) both exist.
# This is a good indication that Doxygen and Mkdocs did their work.
if [ -d "reference" ] && [ -f "index.html" ]; then

View File

@@ -1,14 +1,14 @@
#!/bin/bash
##### Different color outputs (to distinguish errors from standard output) #####
prGreen() {
echo -e "\e[36m-->\e[92m $1\e[00m"
prGreen() {
echo -e "\e[36m-->\e[92m $1\e[00m"
}
prRed() {
echo -e "\e[36m-->\e[91m $1\e[00m"
prRed() {
echo -e "\e[36m-->\e[91m $1\e[00m"
}
prYellow() {
echo -e "\e[36m-->\e[93m $1\e[00m"
prYellow() {
echo -e "\e[36m-->\e[93m $1\e[00m"
}
##### Check whether the script is called properly #####

View File

@@ -36,7 +36,7 @@ static void start_web_server()
/**
* Called once at fuzzer start-up, initializes the web-server
* @return True,
* @return True,
*/
static bool initialize_web_server()
{

View File

@@ -551,7 +551,7 @@ TEST_CASE("validate can be called multiple times")
try
{
CROW_ROUTE(app, "/")([]() { return "1"; });
app.validate();
app.validate();
FAIL_CHECK();
}
catch (std::exception& e)
@@ -1001,6 +1001,7 @@ TEST_CASE("json_write_with_indent")
static constexpr char TabSeparator = '\t';
// Note: The following string needs to use tabs!
CHECK(R"({
"scores": [
1,