mirror of
https://github.com/drogonframework/drogon.git
synced 2025-08-01 00:02:49 -04:00
Compare commits
3 Commits
baea2dce47
...
674137e89d
Author | SHA1 | Date | |
---|---|---|---|
|
674137e89d | ||
|
ffc6e74f27 | ||
|
359b63fa77 |
20
.github/workflows/cpp.yml
vendored
20
.github/workflows/cpp.yml
vendored
@ -17,5 +17,25 @@ jobs:
|
|||||||
- name: Install dos2unix
|
- name: Install dos2unix
|
||||||
run: sudo apt-get install -y dos2unix
|
run: sudo apt-get install -y dos2unix
|
||||||
|
|
||||||
|
- name: Install clang-format-17
|
||||||
|
run: |
|
||||||
|
wget https://apt.llvm.org/llvm.sh
|
||||||
|
chmod +x ./llvm.sh
|
||||||
|
sudo ./llvm.sh 17
|
||||||
|
sudo apt-get install -y clang-format-17
|
||||||
|
|
||||||
- name: Check formatting
|
- name: Check formatting
|
||||||
run: ./format.sh && git diff --exit-code
|
run: ./format.sh && git diff --exit-code
|
||||||
|
env:
|
||||||
|
CLANG_FORMAT: clang-format-17
|
||||||
|
|
||||||
|
cpplint:
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install cpplint
|
||||||
|
run: pip install cpplint
|
||||||
|
|
||||||
|
- name: Run lint
|
||||||
|
run: cpplint --recursive .
|
||||||
|
41
CPPLINT.cfg
Normal file
41
CPPLINT.cfg
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# Stop searching for additional config files.
|
||||||
|
set noparent
|
||||||
|
|
||||||
|
exclude_files=trantor
|
||||||
|
exclude_files=build
|
||||||
|
|
||||||
|
# Use non-const reference rather than a pointer.
|
||||||
|
filter=-runtime/references
|
||||||
|
|
||||||
|
# CHECK macros are from Drogon, not Google Test.
|
||||||
|
filter=-readability/check
|
||||||
|
|
||||||
|
# Don't warn about the use of C++11 features.
|
||||||
|
filter=-build/c++11
|
||||||
|
|
||||||
|
filter=-build/include_subdir
|
||||||
|
|
||||||
|
# We prioritize clang-format for now.
|
||||||
|
filter=-whitespace
|
||||||
|
|
||||||
|
# We don't require a username in TODO comments.
|
||||||
|
filter=-readability/todo
|
||||||
|
|
||||||
|
# TODO: Fix these.
|
||||||
|
filter=-legal/copyright
|
||||||
|
filter=-build/storage_class
|
||||||
|
filter=-build/namespaces
|
||||||
|
filter=-build/include
|
||||||
|
filter=-build/header_guard
|
||||||
|
filter=-build/include_what_you_use
|
||||||
|
filter=-build/include_order
|
||||||
|
filter=-build/explicit_make_pair
|
||||||
|
filter=-runtime/explicit
|
||||||
|
filter=-runtime/string
|
||||||
|
filter=-runtime/int
|
||||||
|
filter=-readability/multiline_string
|
||||||
|
filter=-readability/inheritance
|
||||||
|
filter=-readability/casting
|
||||||
|
filter=-readability/braces
|
||||||
|
filter=-readability/fn_size
|
||||||
|
filter=-runtime/threadsafe_fn
|
@ -308,16 +308,18 @@ void create_model::createModelClassFromPG(
|
|||||||
data["hasPrimaryKey"] = (int)pkNumber;
|
data["hasPrimaryKey"] = (int)pkNumber;
|
||||||
if (pkNumber == 1)
|
if (pkNumber == 1)
|
||||||
{
|
{
|
||||||
*client << "SELECT \
|
*client << "SELECT "
|
||||||
pg_attribute.attname AS colname,\
|
"pg_attribute.attname AS colname,"
|
||||||
pg_type.typname AS typename,\
|
"pg_type.typname AS typename,"
|
||||||
pg_constraint.contype AS contype \
|
"pg_constraint.contype AS contype "
|
||||||
FROM pg_constraint \
|
"FROM pg_constraint "
|
||||||
INNER JOIN pg_class ON pg_constraint.conrelid = pg_class.oid \
|
"INNER JOIN pg_class ON pg_constraint.conrelid = "
|
||||||
INNER JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid \
|
"pg_class.oid "
|
||||||
AND pg_attribute.attnum = pg_constraint.conkey [ 1 ] \
|
"INNER JOIN pg_attribute ON pg_attribute.attrelid = "
|
||||||
INNER JOIN pg_type ON pg_type.oid = pg_attribute.atttypid \
|
"pg_class.oid "
|
||||||
WHERE pg_class.relname = $1 and pg_constraint.contype='p'"
|
"AND pg_attribute.attnum = pg_constraint.conkey [ 1 ] "
|
||||||
|
"INNER JOIN pg_type ON pg_type.oid = pg_attribute.atttypid "
|
||||||
|
"WHERE pg_class.relname = $1 and pg_constraint.contype='p'"
|
||||||
<< tableName << Mode::Blocking >>
|
<< tableName << Mode::Blocking >>
|
||||||
[&](bool isNull,
|
[&](bool isNull,
|
||||||
const std::string &colName,
|
const std::string &colName,
|
||||||
@ -345,16 +347,20 @@ void create_model::createModelClassFromPG(
|
|||||||
std::vector<std::string> pkNames, pkTypes, pkValNames;
|
std::vector<std::string> pkNames, pkTypes, pkValNames;
|
||||||
for (size_t i = 1; i <= pkNumber; ++i)
|
for (size_t i = 1; i <= pkNumber; ++i)
|
||||||
{
|
{
|
||||||
*client << "SELECT \
|
*client << "SELECT "
|
||||||
pg_attribute.attname AS colname,\
|
"pg_attribute.attname AS colname,"
|
||||||
pg_type.typname AS typename,\
|
"pg_type.typname AS typename,"
|
||||||
pg_constraint.contype AS contype \
|
"pg_constraint.contype AS contype "
|
||||||
FROM pg_constraint \
|
"FROM pg_constraint "
|
||||||
INNER JOIN pg_class ON pg_constraint.conrelid = pg_class.oid \
|
"INNER JOIN pg_class ON pg_constraint.conrelid = "
|
||||||
INNER JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid \
|
"pg_class.oid "
|
||||||
AND pg_attribute.attnum = pg_constraint.conkey [ $1 ] \
|
"INNER JOIN pg_attribute ON pg_attribute.attrelid = "
|
||||||
INNER JOIN pg_type ON pg_type.oid = pg_attribute.atttypid \
|
"pg_class.oid "
|
||||||
WHERE pg_class.relname = $2 and pg_constraint.contype='p'"
|
"AND pg_attribute.attnum = pg_constraint.conkey [ $1 ] "
|
||||||
|
"INNER JOIN pg_type ON pg_type.oid = "
|
||||||
|
"pg_attribute.atttypid "
|
||||||
|
"WHERE pg_class.relname = $2 and "
|
||||||
|
"pg_constraint.contype='p'"
|
||||||
<< (int)i << tableName << Mode::Blocking >>
|
<< (int)i << tableName << Mode::Blocking >>
|
||||||
[&](bool isNull, std::string colName, const std::string &type) {
|
[&](bool isNull, std::string colName, const std::string &type) {
|
||||||
if (isNull)
|
if (isNull)
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
# You can customize the clang-format path by setting the CLANG_FORMAT environment variable
|
# You can customize the clang-format path by setting the CLANG_FORMAT environment variable
|
||||||
CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
|
CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
|
||||||
|
|
||||||
# Check if clang-format version is 14 to avoid inconsistent formatting
|
# Check if clang-format version is 17 to avoid inconsistent formatting
|
||||||
$CLANG_FORMAT --version
|
$CLANG_FORMAT --version
|
||||||
if [[ ! $($CLANG_FORMAT --version) =~ "version 14" ]]; then
|
if [[ ! $($CLANG_FORMAT --version) =~ "version 17" ]]; then
|
||||||
echo "Error: clang-format version must be 14"
|
echo "Error: clang-format version must be 17"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ class DROGON_EXPORT DrClassMap
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
static std::unordered_map<std::string,
|
static std::unordered_map<std::string,
|
||||||
std::pair<DrAllocFunc, DrSharedAllocFunc>>
|
std::pair<DrAllocFunc, DrSharedAllocFunc>> &
|
||||||
&getMap();
|
getMap();
|
||||||
};
|
};
|
||||||
} // namespace drogon
|
} // namespace drogon
|
||||||
|
@ -194,8 +194,8 @@ class DROGON_EXPORT HttpAppFramework : public trantor::NonCopyable
|
|||||||
* returned.
|
* returned.
|
||||||
*/
|
*/
|
||||||
virtual const std::function<HttpResponsePtr(HttpStatusCode,
|
virtual const std::function<HttpResponsePtr(HttpStatusCode,
|
||||||
const HttpRequestPtr &req)>
|
const HttpRequestPtr &req)> &
|
||||||
&getCustomErrorHandler() const = 0;
|
getCustomErrorHandler() const = 0;
|
||||||
|
|
||||||
/// Get the plugin object registered in the framework
|
/// Get the plugin object registered in the framework
|
||||||
/**
|
/**
|
||||||
@ -1421,8 +1421,8 @@ class DROGON_EXPORT HttpAppFramework : public trantor::NonCopyable
|
|||||||
*
|
*
|
||||||
* @return std::pair<size_t, std::string>
|
* @return std::pair<size_t, std::string>
|
||||||
*/
|
*/
|
||||||
virtual const std::pair<unsigned int, std::string>
|
virtual const std::pair<unsigned int, std::string> &
|
||||||
&getFloatPrecisionInJson() const noexcept = 0;
|
getFloatPrecisionInJson() const noexcept = 0;
|
||||||
/// Create a database client
|
/// Create a database client
|
||||||
/**
|
/**
|
||||||
* @param dbType The database type is one of
|
* @param dbType The database type is one of
|
||||||
|
@ -162,27 +162,31 @@ class DROGON_EXPORT HttpRequest
|
|||||||
virtual const std::string &getCookie(const std::string &field) const = 0;
|
virtual const std::string &getCookie(const std::string &field) const = 0;
|
||||||
|
|
||||||
/// Get all headers of the request
|
/// Get all headers of the request
|
||||||
virtual const std::
|
virtual const std::unordered_map<std::string,
|
||||||
unordered_map<std::string, std::string, utils::internal::SafeStringHash>
|
std::string,
|
||||||
&headers() const = 0;
|
utils::internal::SafeStringHash> &
|
||||||
|
headers() const = 0;
|
||||||
|
|
||||||
/// Get all headers of the request
|
/// Get all headers of the request
|
||||||
const std::
|
const std::unordered_map<std::string,
|
||||||
unordered_map<std::string, std::string, utils::internal::SafeStringHash>
|
std::string,
|
||||||
&getHeaders() const
|
utils::internal::SafeStringHash> &
|
||||||
|
getHeaders() const
|
||||||
{
|
{
|
||||||
return headers();
|
return headers();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all cookies of the request
|
/// Get all cookies of the request
|
||||||
virtual const std::
|
virtual const std::unordered_map<std::string,
|
||||||
unordered_map<std::string, std::string, utils::internal::SafeStringHash>
|
std::string,
|
||||||
&cookies() const = 0;
|
utils::internal::SafeStringHash> &
|
||||||
|
cookies() const = 0;
|
||||||
|
|
||||||
/// Get all cookies of the request
|
/// Get all cookies of the request
|
||||||
const std::
|
const std::unordered_map<std::string,
|
||||||
unordered_map<std::string, std::string, utils::internal::SafeStringHash>
|
std::string,
|
||||||
&getCookies() const
|
utils::internal::SafeStringHash> &
|
||||||
|
getCookies() const
|
||||||
{
|
{
|
||||||
return cookies();
|
return cookies();
|
||||||
}
|
}
|
||||||
@ -300,14 +304,16 @@ class DROGON_EXPORT HttpRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get parameters of the request.
|
/// Get parameters of the request.
|
||||||
virtual const std::
|
virtual const std::unordered_map<std::string,
|
||||||
unordered_map<std::string, std::string, utils::internal::SafeStringHash>
|
std::string,
|
||||||
¶meters() const = 0;
|
utils::internal::SafeStringHash> &
|
||||||
|
parameters() const = 0;
|
||||||
|
|
||||||
/// Get parameters of the request.
|
/// Get parameters of the request.
|
||||||
const std::
|
const std::unordered_map<std::string,
|
||||||
unordered_map<std::string, std::string, utils::internal::SafeStringHash>
|
std::string,
|
||||||
&getParameters() const
|
utils::internal::SafeStringHash> &
|
||||||
|
getParameters() const
|
||||||
{
|
{
|
||||||
return parameters();
|
return parameters();
|
||||||
}
|
}
|
||||||
|
@ -244,14 +244,16 @@ class DROGON_EXPORT HttpResponse
|
|||||||
virtual void removeHeader(std::string key) = 0;
|
virtual void removeHeader(std::string key) = 0;
|
||||||
|
|
||||||
/// Get all headers of the response
|
/// Get all headers of the response
|
||||||
virtual const std::
|
virtual const std::unordered_map<std::string,
|
||||||
unordered_map<std::string, std::string, utils::internal::SafeStringHash>
|
std::string,
|
||||||
&headers() const = 0;
|
utils::internal::SafeStringHash> &
|
||||||
|
headers() const = 0;
|
||||||
|
|
||||||
/// Get all headers of the response
|
/// Get all headers of the response
|
||||||
const std::
|
const std::unordered_map<std::string,
|
||||||
unordered_map<std::string, std::string, utils::internal::SafeStringHash>
|
std::string,
|
||||||
&getHeaders() const
|
utils::internal::SafeStringHash> &
|
||||||
|
getHeaders() const
|
||||||
{
|
{
|
||||||
return headers();
|
return headers();
|
||||||
}
|
}
|
||||||
@ -280,13 +282,13 @@ class DROGON_EXPORT HttpResponse
|
|||||||
|
|
||||||
/// Get all cookies.
|
/// Get all cookies.
|
||||||
virtual const std::
|
virtual const std::
|
||||||
unordered_map<std::string, Cookie, utils::internal::SafeStringHash>
|
unordered_map<std::string, Cookie, utils::internal::SafeStringHash> &
|
||||||
&cookies() const = 0;
|
cookies() const = 0;
|
||||||
|
|
||||||
/// Get all cookies.
|
/// Get all cookies.
|
||||||
const std::
|
const std::
|
||||||
unordered_map<std::string, Cookie, utils::internal::SafeStringHash>
|
unordered_map<std::string, Cookie, utils::internal::SafeStringHash> &
|
||||||
&getCookies() const
|
getCookies() const
|
||||||
{
|
{
|
||||||
return cookies();
|
return cookies();
|
||||||
}
|
}
|
||||||
@ -580,8 +582,8 @@ class DROGON_EXPORT HttpResponse
|
|||||||
* newStreamResponse) returns the callback function. Otherwise a
|
* newStreamResponse) returns the callback function. Otherwise a
|
||||||
* null function.
|
* null function.
|
||||||
*/
|
*/
|
||||||
virtual const std::function<std::size_t(char *, std::size_t)>
|
virtual const std::function<std::size_t(char *, std::size_t)> &
|
||||||
&streamCallback() const = 0;
|
streamCallback() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief If the response is a async stream response (i.e. created by
|
* @brief If the response is a async stream response (i.e. created by
|
||||||
|
@ -22,8 +22,8 @@ namespace drogon
|
|||||||
{
|
{
|
||||||
namespace internal
|
namespace internal
|
||||||
{
|
{
|
||||||
static std::unordered_map<std::string, std::shared_ptr<DrObjectBase>>
|
static std::unordered_map<std::string, std::shared_ptr<DrObjectBase>> &
|
||||||
&getObjsMap()
|
getObjsMap()
|
||||||
{
|
{
|
||||||
static std::unordered_map<std::string, std::shared_ptr<DrObjectBase>>
|
static std::unordered_map<std::string, std::shared_ptr<DrObjectBase>>
|
||||||
singleInstanceMap;
|
singleInstanceMap;
|
||||||
@ -112,8 +112,8 @@ std::vector<std::string> DrClassMap::getAllClassName()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_map<std::string, std::pair<DrAllocFunc, DrSharedAllocFunc>>
|
std::unordered_map<std::string, std::pair<DrAllocFunc, DrSharedAllocFunc>> &
|
||||||
&DrClassMap::getMap()
|
DrClassMap::getMap()
|
||||||
{
|
{
|
||||||
static std::unordered_map<std::string,
|
static std::unordered_map<std::string,
|
||||||
std::pair<DrAllocFunc, DrSharedAllocFunc>>
|
std::pair<DrAllocFunc, DrSharedAllocFunc>>
|
||||||
|
@ -1039,8 +1039,9 @@ HttpAppFramework &HttpAppFrameworkImpl::setCustomErrorHandler(
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::function<HttpResponsePtr(HttpStatusCode, const HttpRequestPtr &req)>
|
const std::function<HttpResponsePtr(HttpStatusCode,
|
||||||
&HttpAppFrameworkImpl::getCustomErrorHandler() const
|
const HttpRequestPtr &req)> &
|
||||||
|
HttpAppFrameworkImpl::getCustomErrorHandler() const
|
||||||
{
|
{
|
||||||
return customErrorHandler_;
|
return customErrorHandler_;
|
||||||
}
|
}
|
||||||
|
@ -586,8 +586,8 @@ class HttpAppFrameworkImpl final : public HttpAppFramework
|
|||||||
|
|
||||||
bool areAllDbClientsAvailable() const noexcept override;
|
bool areAllDbClientsAvailable() const noexcept override;
|
||||||
const std::function<HttpResponsePtr(HttpStatusCode,
|
const std::function<HttpResponsePtr(HttpStatusCode,
|
||||||
const HttpRequestPtr &req)>
|
const HttpRequestPtr &req)> &
|
||||||
&getCustomErrorHandler() const override;
|
getCustomErrorHandler() const override;
|
||||||
|
|
||||||
bool isUsingCustomErrorHandler() const
|
bool isUsingCustomErrorHandler() const
|
||||||
{
|
{
|
||||||
|
@ -169,9 +169,10 @@ class HttpRequestImpl : public HttpRequest
|
|||||||
pathEncode_ = pathEncode;
|
pathEncode_ = pathEncode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::
|
const std::unordered_map<std::string,
|
||||||
unordered_map<std::string, std::string, utils::internal::SafeStringHash>
|
std::string,
|
||||||
¶meters() const override
|
utils::internal::SafeStringHash> &
|
||||||
|
parameters() const override
|
||||||
{
|
{
|
||||||
parseParametersOnce();
|
parseParametersOnce();
|
||||||
return parameters_;
|
return parameters_;
|
||||||
@ -341,16 +342,18 @@ class HttpRequestImpl : public HttpRequest
|
|||||||
return defaultVal;
|
return defaultVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::
|
const std::unordered_map<std::string,
|
||||||
unordered_map<std::string, std::string, utils::internal::SafeStringHash>
|
std::string,
|
||||||
&headers() const override
|
utils::internal::SafeStringHash> &
|
||||||
|
headers() const override
|
||||||
{
|
{
|
||||||
return headers_;
|
return headers_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::
|
const std::unordered_map<std::string,
|
||||||
unordered_map<std::string, std::string, utils::internal::SafeStringHash>
|
std::string,
|
||||||
&cookies() const override
|
utils::internal::SafeStringHash> &
|
||||||
|
cookies() const override
|
||||||
{
|
{
|
||||||
return cookies_;
|
return cookies_;
|
||||||
}
|
}
|
||||||
|
@ -133,9 +133,10 @@ class DROGON_EXPORT HttpResponseImpl : public HttpResponse
|
|||||||
removeHeaderBy(key);
|
removeHeaderBy(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::
|
const std::unordered_map<std::string,
|
||||||
unordered_map<std::string, std::string, utils::internal::SafeStringHash>
|
std::string,
|
||||||
&headers() const override
|
utils::internal::SafeStringHash> &
|
||||||
|
headers() const override
|
||||||
{
|
{
|
||||||
return headers_;
|
return headers_;
|
||||||
}
|
}
|
||||||
@ -206,8 +207,8 @@ class DROGON_EXPORT HttpResponseImpl : public HttpResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
const std::
|
const std::
|
||||||
unordered_map<std::string, Cookie, utils::internal::SafeStringHash>
|
unordered_map<std::string, Cookie, utils::internal::SafeStringHash> &
|
||||||
&cookies() const override
|
cookies() const override
|
||||||
{
|
{
|
||||||
return cookies_;
|
return cookies_;
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#elif !defined(__MINGW32__)
|
#elif !defined(__MINGW32__)
|
||||||
#define stat _wstati64
|
#define stat _wstati64
|
||||||
#define S_ISREG(m) (((m)&0170000) == (0100000))
|
#define S_ISREG(m) (((m) & 0170000) == (0100000))
|
||||||
#define S_ISDIR(m) (((m)&0170000) == (0040000))
|
#define S_ISDIR(m) (((m) & 0170000) == (0040000))
|
||||||
#endif
|
#endif
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
@ -88,7 +88,7 @@ void WebSocketConnectionImpl::sendWsData(const char *msg,
|
|||||||
{
|
{
|
||||||
bytesFormatted[1] = 126;
|
bytesFormatted[1] = 126;
|
||||||
bytesFormatted[2] = ((len >> 8) & 255);
|
bytesFormatted[2] = ((len >> 8) & 255);
|
||||||
bytesFormatted[3] = ((len)&255);
|
bytesFormatted[3] = ((len) & 255);
|
||||||
LOG_TRACE << "bytes[2]=" << (size_t)bytesFormatted[2];
|
LOG_TRACE << "bytes[2]=" << (size_t)bytesFormatted[2];
|
||||||
LOG_TRACE << "bytes[3]=" << (size_t)bytesFormatted[3];
|
LOG_TRACE << "bytes[3]=" << (size_t)bytesFormatted[3];
|
||||||
indexStartRawData = 4;
|
indexStartRawData = 4;
|
||||||
@ -103,7 +103,7 @@ void WebSocketConnectionImpl::sendWsData(const char *msg,
|
|||||||
bytesFormatted[6] = ((len >> 24) & 255);
|
bytesFormatted[6] = ((len >> 24) & 255);
|
||||||
bytesFormatted[7] = ((len >> 16) & 255);
|
bytesFormatted[7] = ((len >> 16) & 255);
|
||||||
bytesFormatted[8] = ((len >> 8) & 255);
|
bytesFormatted[8] = ((len >> 8) & 255);
|
||||||
bytesFormatted[9] = ((len)&255);
|
bytesFormatted[9] = ((len) & 255);
|
||||||
|
|
||||||
indexStartRawData = 10;
|
indexStartRawData = 10;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user