From 9105d6576924ef5e502df2de7c368dce63bf5eb7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 26 Jul 2023 12:32:17 +0100 Subject: Reformat with new clang-format --- icespider/common/pathparts.cpp | 1 + icespider/common/pathparts.h | 1 + icespider/compile/routeCompiler.cpp | 2 ++ icespider/compile/routeCompiler.h | 2 ++ icespider/core/core.cpp | 1 + icespider/core/core.h | 7 +++++-- icespider/core/flatMap.h | 4 ++++ icespider/core/ihttpRequest.cpp | 5 +++-- icespider/core/ihttpRequest.h | 12 ++++++++++++ icespider/core/irouteHandler.cpp | 1 + icespider/core/irouteHandler.h | 2 ++ icespider/core/xwwwFormUrlEncoded.h | 1 + icespider/fcgi/cgiRequestBase.cpp | 1 + icespider/fcgi/cgiRequestBase.h | 1 + icespider/fileSessions/fileSessions.cpp | 1 + icespider/testing/testRequest.cpp | 1 + icespider/unittests/testAccept.cpp | 2 ++ icespider/unittests/testApp.cpp | 3 +++ icespider/unittests/testCompile.cpp | 2 ++ icespider/unittests/testFcgi.cpp | 4 ++++ icespider/unittests/testFileSessions.cpp | 1 + icespider/unittests/testPerf.cpp | 5 +++-- icespider/xslt/exslt-init.cpp | 3 +++ 23 files changed, 57 insertions(+), 6 deletions(-) diff --git a/icespider/common/pathparts.cpp b/icespider/common/pathparts.cpp index 654081a..6c11dec 100644 --- a/icespider/common/pathparts.cpp +++ b/icespider/common/pathparts.cpp @@ -8,6 +8,7 @@ namespace ba = boost::algorithm; namespace IceSpider { const auto slash = ba::first_finder("/", ba::is_equal()); + Path::Path(const std::string_view & p) : path(p) { auto relp = p.substr(1); diff --git a/icespider/common/pathparts.h b/icespider/common/pathparts.h index 077386d..f759730 100644 --- a/icespider/common/pathparts.h +++ b/icespider/common/pathparts.h @@ -17,6 +17,7 @@ namespace IceSpider { [[nodiscard]] virtual bool matches(const std::string_view &) const = 0; }; + using PathPartPtr = std::unique_ptr; class DLL_PUBLIC PathLiteral : public PathPart { diff --git a/icespider/compile/routeCompiler.cpp b/icespider/compile/routeCompiler.cpp index 3828d46..3d3913d 100644 --- a/icespider/compile/routeCompiler.cpp +++ b/icespider/compile/routeCompiler.cpp @@ -28,6 +28,7 @@ namespace IceSpider { using namespace AdHoc::literals; + namespace Compile { RouteCompiler::RouteCompiler() { @@ -280,6 +281,7 @@ namespace IceSpider { } AdHocFormatter(MimePair, R"C({ "%?", "%?" })C"); + static std::string outputSerializerMime(const IceSpider::OutputSerializers::value_type & os) { diff --git a/icespider/compile/routeCompiler.h b/icespider/compile/routeCompiler.h index ee388ad..2a09187 100644 --- a/icespider/compile/routeCompiler.h +++ b/icespider/compile/routeCompiler.h @@ -47,12 +47,14 @@ namespace IceSpider::Compile { static Slice::OperationPtr findOperation(const std::string &, const Units &); static Slice::OperationPtr findOperation( const std::string &, const Slice::ContainerPtr &, const Ice::StringSeq & = Ice::StringSeq()); + // using Type = std::pair; struct Type { std::string type; std::optional scoped; Slice::DataMemberList members; }; + static Type findType(const std::string &, const Units &); static std::optional findType( const std::string &, const Slice::ContainerPtr &, const Ice::StringSeq & = Ice::StringSeq()); diff --git a/icespider/core/core.cpp b/icespider/core/core.cpp index 448c7ec..7aa1317 100644 --- a/icespider/core/core.cpp +++ b/icespider/core/core.cpp @@ -126,6 +126,7 @@ namespace IceSpider { } AdHocFormatter(LogExp, "Exception type: %?\nDetail: %?\n"); + void Core::defaultErrorReport(IHttpRequest * request, const std::exception & exception) const { diff --git a/icespider/core/core.h b/icespider/core/core.h index b2150f8..7fa66a7 100644 --- a/icespider/core/core.h +++ b/icespider/core/core.h @@ -19,6 +19,7 @@ #include #include #include + // IWYU pragma: no_include "factory.impl.h" namespace IceSpider { @@ -67,8 +68,8 @@ namespace IceSpider { Routes routes; }; - class DLL_PUBLIC Plugin : public virtual Ice::Object { - }; + class DLL_PUBLIC Plugin : public virtual Ice::Object { }; + using PluginFactory = AdHoc::Factory; enum ErrorHandlerResult { @@ -76,10 +77,12 @@ namespace IceSpider { ErrorHandlerResult_Handled, ErrorHandlerResult_Modified, }; + class DLL_PUBLIC ErrorHandler : public AdHoc::AbstractPluginImplementation { public: virtual ErrorHandlerResult handleError(IHttpRequest * IHttpRequest, const std::exception &) const = 0; }; + using ErrorHandlerPlugin = AdHoc::PluginOf; } diff --git a/icespider/core/flatMap.h b/icespider/core/flatMap.h index 8a8cc20..a0ed57d 100644 --- a/icespider/core/flatMap.h +++ b/icespider/core/flatMap.h @@ -23,16 +23,19 @@ namespace IceSpider { { return c(v.first, n); } + bool operator()(const N & n, const V & v) const { return c(n, v.first); } + Comp c; }; public: flatmap() = default; + explicit flatmap(std::size_t n) { reserve(n); @@ -93,6 +96,7 @@ namespace IceSpider { { return cbegin(); } + [[nodiscard]] auto end() const { diff --git a/icespider/core/ihttpRequest.cpp b/icespider/core/ihttpRequest.cpp index c575c82..ed7fce6 100644 --- a/icespider/core/ihttpRequest.cpp +++ b/icespider/core/ihttpRequest.cpp @@ -167,8 +167,9 @@ namespace IceSpider { XWwwFormUrlEncoded::urlencodeto(o, value.begin(), value.end()); if (e) { std::string buf(45, 0); - struct tm tm { - }; + + struct tm tm { }; + gmtime_r(&*e, &tm); buf.resize(strftime(buf.data(), buf.length(), "; expires=%a, %d %b %Y %T %Z", &tm)); o << buf; diff --git a/icespider/core/ihttpRequest.h b/icespider/core/ihttpRequest.h index a32509a..e8b1594 100644 --- a/icespider/core/ihttpRequest.h +++ b/icespider/core/ihttpRequest.h @@ -28,6 +28,7 @@ namespace IceSpider { std::optional group, type; float q {1.0F}; }; + using Accepted = std::vector; using PathElements = std::vector; using OptionalString = std::optional; @@ -86,18 +87,21 @@ namespace IceSpider { return std::nullopt; } } + template [[nodiscard]] T getURLParam(unsigned int n) const { return *getFrom(n, &IHttpRequest::getURLParam); } + template [[nodiscard]] std::optional getBody() const { return Slicer::DeserializeAnyWith(getDeserializer()); } + template [[nodiscard]] std::optional getBodyParam(const std::optional & map, const std::string_view & key) const @@ -113,9 +117,11 @@ namespace IceSpider { return boost::lexical_cast(i->second); } } + void responseRedirect(const std::string_view & url, const OptionalString & = {}) const; void setCookie(const std::string_view &, const std::string_view &, const OptionalString & = {}, const OptionalString & = {}, bool = false, std::optional = {}); + template void setCookie(const std::string_view & n, const T & v, const OptionalString & d, const OptionalString & p, bool s, @@ -129,31 +135,37 @@ namespace IceSpider { setCookie(n, std::string_view(vs), d, p, s, e); } } + template [[nodiscard]] std::optional getQueryStringParam(const std::string_view & key) const { return getFrom(key, &IHttpRequest::getQueryStringParam); } + template [[nodiscard]] std::optional getHeaderParam(const std::string_view & key) const { return getFrom(key, &IHttpRequest::getHeaderParam); } + template [[nodiscard]] std::optional getCookieParam(const std::string_view & key) const { return getFrom(key, &IHttpRequest::getCookieParam); } + virtual void response(short, const std::string_view &) const = 0; + template void response(const IRouteHandler * route, const T & t) const { modelPartResponse(route, Slicer::ModelPart::CreateRootFor(t)); } + void modelPartResponse(const IRouteHandler * route, const Slicer::ModelPartForRootPtr &) const; const Core * core; diff --git a/icespider/core/irouteHandler.cpp b/icespider/core/irouteHandler.cpp index 85b49f6..3219e17 100644 --- a/icespider/core/irouteHandler.cpp +++ b/icespider/core/irouteHandler.cpp @@ -18,6 +18,7 @@ namespace IceSpider { static const std::string APPLICATION_JSON = MimeTypeFmt::get(APPLICATION, JSON); const RouteOptions IRouteHandler::defaultRouteOptions {}; + IRouteHandler::IRouteHandler(HttpMethod m, const std::string_view & p) : IRouteHandler(m, p, defaultRouteOptions) { } diff --git a/icespider/core/irouteHandler.h b/icespider/core/irouteHandler.h index c9c09e2..2b13b22 100644 --- a/icespider/core/irouteHandler.h +++ b/icespider/core/irouteHandler.h @@ -12,6 +12,7 @@ #include #include #include + // IWYU pragma: no_include "factory.impl.h" // IWYU pragma: no_include // IWYU pragma: no_include @@ -51,6 +52,7 @@ namespace IceSpider { void addRouteSerializer(const MimeType &, const StreamSerializerFactoryPtr &); }; + using IRouteHandlerPtr = std::shared_ptr; using IRouteHandlerCPtr = std::shared_ptr; using RouteHandlerFactory = AdHoc::Factory; diff --git a/icespider/core/xwwwFormUrlEncoded.h b/icespider/core/xwwwFormUrlEncoded.h index d4b11f3..a296864 100644 --- a/icespider/core/xwwwFormUrlEncoded.h +++ b/icespider/core/xwwwFormUrlEncoded.h @@ -10,6 +10,7 @@ #include #include #include + // IWYU pragma: no_forward_declare boost::algorithm::split_iterator namespace IceSpider { diff --git a/icespider/fcgi/cgiRequestBase.cpp b/icespider/fcgi/cgiRequestBase.cpp index 108f2ce..5cefc4e 100644 --- a/icespider/fcgi/cgiRequestBase.cpp +++ b/icespider/fcgi/cgiRequestBase.cpp @@ -95,6 +95,7 @@ namespace IceSpider { AdHocFormatter(VarFmt, "\t%?: [%?]\n"); AdHocFormatter(PathFmt, "\t[%?]\n"); + template void dumpMap(std::ostream & s, const std::string_view & n, const Map & map) diff --git a/icespider/fcgi/cgiRequestBase.h b/icespider/fcgi/cgiRequestBase.h index 32cdca3..a576db1 100644 --- a/icespider/fcgi/cgiRequestBase.h +++ b/icespider/fcgi/cgiRequestBase.h @@ -8,6 +8,7 @@ #include #include #include + // IWYU pragma: no_forward_declare AdHoc::case_less namespace IceSpider { diff --git a/icespider/fileSessions/fileSessions.cpp b/icespider/fileSessions/fileSessions.cpp index 6818410..9a23898 100644 --- a/icespider/fileSessions/fileSessions.cpp +++ b/icespider/fileSessions/fileSessions.cpp @@ -170,4 +170,5 @@ namespace IceSpider { const Ice::Short duration; }; } + NAMEDFACTORY("IceSpider-FileSessions", IceSpider::FileSessions, IceSpider::PluginFactory); diff --git a/icespider/testing/testRequest.cpp b/icespider/testing/testRequest.cpp index e522bc1..552987c 100644 --- a/icespider/testing/testRequest.cpp +++ b/icespider/testing/testRequest.cpp @@ -13,6 +13,7 @@ namespace IceSpider { constexpr std::string_view slash("/"); + TestRequest::TestRequest(const Core * c, HttpMethod m, const std::string_view & p) : IHttpRequest(c), method(m) { namespace ba = boost::algorithm; diff --git a/icespider/unittests/testAccept.cpp b/icespider/unittests/testAccept.cpp index 67b1411..410147f 100644 --- a/icespider/unittests/testAccept.cpp +++ b/icespider/unittests/testAccept.cpp @@ -7,6 +7,7 @@ #include #include #include + namespace IceSpider { class Http400_BadRequest; } @@ -24,6 +25,7 @@ namespace std { } BOOST_TEST_DECORATOR(*boost::unit_test::timeout(1)) + BOOST_DATA_TEST_CASE(bad_requests, make({ "", // Can't specify nothing diff --git a/icespider/unittests/testApp.cpp b/icespider/unittests/testApp.cpp index 9f84999..8f13793 100644 --- a/icespider/unittests/testApp.cpp +++ b/icespider/unittests/testApp.cpp @@ -32,6 +32,7 @@ #include #include #include + namespace Ice { struct Current; } @@ -44,6 +45,7 @@ struct forceEarlyChangeDir { std::filesystem::current_path(rootDir); } }; + BOOST_TEST_GLOBAL_FIXTURE(forceEarlyChangeDir); BOOST_AUTO_TEST_CASE(testLoadConfiguration) @@ -214,6 +216,7 @@ class Dummy : public IceSpider::Plugin, TestIceSpider::DummyPlugin { public: Dummy(const Ice::CommunicatorPtr &, const Ice::PropertiesPtr &) { } }; + NAMEDFACTORY("DummyPlugin", Dummy, IceSpider::PluginFactory); BOOST_FIXTURE_TEST_SUITE(ta, TestApp); diff --git a/icespider/unittests/testCompile.cpp b/icespider/unittests/testCompile.cpp index 8d01113..19395ac 100644 --- a/icespider/unittests/testCompile.cpp +++ b/icespider/unittests/testCompile.cpp @@ -25,11 +25,13 @@ struct forceEarlyChangeDir { std::filesystem::current_path(rootDir); } }; + BOOST_TEST_GLOBAL_FIXTURE(forceEarlyChangeDir); class CoreFixture { protected: CoreFixture() : modeDir(binDir.lexically_relative(rootDir / "bin" / "testCompile.test")) { } + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) const std::filesystem::path modeDir; }; diff --git a/icespider/unittests/testFcgi.cpp b/icespider/unittests/testFcgi.cpp index 5b1ac5b..e77e954 100644 --- a/icespider/unittests/testFcgi.cpp +++ b/icespider/unittests/testFcgi.cpp @@ -23,11 +23,13 @@ namespace IceSpider { class Http400_BadRequest; } + namespace IceSpider { class Http405_MethodNotAllowed; } using namespace std::literals; + namespace std { template ostream & @@ -68,6 +70,7 @@ public: { return std::cin; } + // LCOV_EXCL_STOP // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) @@ -132,6 +135,7 @@ namespace std { } return s; } + // LCOV_EXCL_STOP } diff --git a/icespider/unittests/testFileSessions.cpp b/icespider/unittests/testFileSessions.cpp index 2470363..9f73d43 100644 --- a/icespider/unittests/testFileSessions.cpp +++ b/icespider/unittests/testFileSessions.cpp @@ -26,6 +26,7 @@ public: root(communicator->getProperties()->getProperty("IceSpider.FileSessions.Path")) { } + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) const std::filesystem::path root; }; diff --git a/icespider/unittests/testPerf.cpp b/icespider/unittests/testPerf.cpp index 85abc92..7a24faf 100644 --- a/icespider/unittests/testPerf.cpp +++ b/icespider/unittests/testPerf.cpp @@ -25,6 +25,7 @@ public: { return std::cin; } + // LCOV_EXCL_STOP // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) @@ -55,8 +56,7 @@ public: } }; -class CoreFixture : public IceSpider::CoreWithDefaultRouter, public benchmark::Fixture { -}; +class CoreFixture : public IceSpider::CoreWithDefaultRouter, public benchmark::Fixture { }; BENCHMARK_F(CoreFixture, script_name_root)(benchmark::State & state) { @@ -118,6 +118,7 @@ AcceptParse(benchmark::State & state, const std::string_view accept) benchmark::DoNotOptimize(IceSpider::IHttpRequest::parseAccept(accept)); } } + BENCHMARK_CAPTURE_LITERAL(AcceptParse, "*/*"); BENCHMARK_CAPTURE_LITERAL(AcceptParse, "any/html"); BENCHMARK_CAPTURE_LITERAL(AcceptParse, "image/png, */*"); diff --git a/icespider/xslt/exslt-init.cpp b/icespider/xslt/exslt-init.cpp index d4489e7..110a999 100644 --- a/icespider/xslt/exslt-init.cpp +++ b/icespider/xslt/exslt-init.cpp @@ -3,6 +3,7 @@ #include static void initLibXml() __attribute__((constructor(102))); + void initLibXml() { @@ -12,10 +13,12 @@ initLibXml() // LCOV_EXCL_START lcov actually misses destructor functions static void cleanupLibXml() __attribute__((destructor(102))); + void cleanupLibXml() { xsltCleanupGlobals(); xmlCleanupParser(); } + // LCOV_EXCL_STOP -- cgit v1.2.3