Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #32 from datasift/feature/compiler-warnings
Browse files Browse the repository at this point in the history
Feature/compiler warnings
  • Loading branch information
Jeffail authored Mar 23, 2018
2 parents 6288e52 + d976e73 commit 02c33e7
Show file tree
Hide file tree
Showing 24 changed files with 298 additions and 261 deletions.
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ SET (CMAKE_MODULE_PATH "${MAINFOLDER}/cmake")
INCLUDE_DIRECTORIES ("${MAINFOLDER}/src")

#
# Locate Project Prerequisites
# Locate Project Prerequisites
#
FIND_PACKAGE (Boost 1.53 COMPONENTS "system" REQUIRED)
INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIRS})
Expand All @@ -84,6 +84,11 @@ FIND_PACKAGE (Threads)
INCLUDE (EnableStdCXX11)
ENABLE_STDCXX11 ()

#
# Enable warnings
#
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wno-missing-field-initializers")

#
# Configure Files
#
Expand Down Expand Up @@ -123,5 +128,5 @@ ENDIF (SERVED_BUILD_DEB)
IF (SERVED_BUILD_RPM)
INCLUDE(CPackConfigRPM)
ENDIF (SERVED_BUILD_RPM)

INCLUDE(CPack)
4 changes: 2 additions & 2 deletions src/examples/binary_data/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
* explicitly set the Content-Length header because if this value is omitted then served calculates
* it for you based on the response length.
*/
int main(int argc, char const* argv[])
int main(int, char const**)
{
served::multiplexer mux;
mux.use_after(served::plugin::access_log);

const std::string image_name("served-logo.png");

mux.handle("/picture")
.get([&](served::response & res, const served::request & req) {
.get([&](served::response & res, const served::request &) {
std::ifstream ifs(image_name);
res.set_body(std::string(
(std::istreambuf_iterator<char>(ifs) ),
Expand Down
2 changes: 1 addition & 1 deletion src/examples/form_data/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* This example demonstrates how you might specify and validate a form endpoint.
*/
int main(int argc, char const* argv[])
int main(int, char const**)
{
served::multiplexer mux;
mux.handle("/form_post")
Expand Down
4 changes: 2 additions & 2 deletions src/examples/handlers/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* This is a demonstration of using various handler mechanisms, including REST parameters with rejex
* based value validation.
*/
int main(int argc, char const* argv[])
int main(int, char const**)
{
served::multiplexer mux;

Expand Down Expand Up @@ -63,7 +63,7 @@ int main(int argc, char const* argv[])

// GET /handlers
mux.handle("/handlers")
.get([](served::response & res, const served::request & req) {
.get([](served::response & res, const served::request &) {
res << "You got served";
});

Expand Down
4 changes: 2 additions & 2 deletions src/examples/hello_world/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
*
* This is the most basic example of served in action.
*/
int main(int argc, char const* argv[])
int main(int, char const**)
{
served::multiplexer mux;

mux.handle("/hello")
.get([](served::response & res, const served::request & req) {
.get([](served::response & res, const served::request &) {
res << "Hello world";
});

Expand Down
8 changes: 4 additions & 4 deletions src/examples/list_endpoints/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@
*
* mux.handler("/endpoints").get(mux.get_endpoint_list_handler_YAML());
*/
int main(int argc, char const* argv[])
int main(int, char const**)
{
served::multiplexer mux;

// serve up some big whoop
mux.handle("/big_whoop")
.get([](served::response & res, const served::request & req) {
.get([](served::response & res, const served::request &) {
res << "list big_whoop";
})
.post([](served::response & res, const served::request & req) {
.post([](served::response & res, const served::request &) {
res << "create big_whoop";
});

Expand All @@ -67,7 +67,7 @@ int main(int argc, char const* argv[])

// GET /endpoints
mux.handle("/endpoints")
.get([&mux](served::response & res, const served::request & req) {
.get([&mux](served::response & res, const served::request &) {
const served::served_endpoint_list endpoints = mux.get_endpoint_list();
for (auto& endpoint : endpoints)
{
Expand Down
2 changes: 1 addition & 1 deletion src/examples/query_params/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* This example demonstrates how you can iterate and locate query parameters from the request URL,
* since the query string is already parsed for you.
*/
int main(int argc, char const* argv[])
int main(int, char const**)
{
served::multiplexer mux;
mux.handle("/query")
Expand Down
8 changes: 4 additions & 4 deletions src/examples/request_logger_plugin/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@
*
* mux.use_after(served::plugins::access_log);
*/
int main(int argc, char const* argv[])
int main(int, char const**)
{
served::multiplexer mux;

// register one or more handlers
mux.handle("/served")
.get([](served::response & res, const served::request & req) {
.get([](served::response & res, const served::request &) {
res << "You got served!";
});
mux.handle("/itson")
.get([](served::response & res, const served::request & req) {
.get([](served::response & res, const served::request &) {
res << "Oh, it's on!";
});

// register middleware / plugin
mux.use_before([](served::response & res, const served::request & req) {
mux.use_before([](served::response &, const served::request & req) {
std::cout << "request: " << req.url().URI() << std::endl;
});

Expand Down
12 changes: 11 additions & 1 deletion src/examples/rest_resource/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,36 @@
*
* This example demonstrates how you might use served to create REST resources.
*/
int main(int argc, char const* argv[])
int main(int, char const**)
{
served::multiplexer mux;

mux.handle("/customers")
.get([](served::response & res, const served::request & req) {
(void) res;
(void) req;
// list customers
})
.post([](served::response & res, const served::request & req) {
(void) res;
(void) req;
// create customer
});

mux.handle("/customers/{id}")
.get([](served::response & res, const served::request & req) {
(void) res;
(void) req;
// read customer req.params["id"]
})
.put([](served::response & res, const served::request & req) {
(void) res;
(void) req;
// update customer req.params["id"]
})
.del([](served::response & res, const served::request & req) {
(void) res;
(void) req;
// delete customer req.params["id"]
});

Expand Down
6 changes: 3 additions & 3 deletions src/served/methods_handler.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TEST_CASE("test methods handling", "[methods_handler]")
{
SECTION("create handlers")
{
auto dummy = [](served::response & res, const served::request & req) {};
auto dummy = [](served::response &, const served::request &) {};

served::methods_handler h("/dummy");
h.post(dummy).get(dummy).method(served::method::CONNECT, dummy).put(dummy);
Expand All @@ -57,7 +57,7 @@ TEST_CASE("test methods handling", "[methods_handler]")

SECTION("check endpoint propagation no description")
{
auto dummy = [](served::response & res, const served::request & req) {};
auto dummy = [](served::response &, const served::request &) {};

served::methods_handler h("/this/path/is/great");
h.post(dummy).get(dummy).method(served::method::CONNECT, dummy).put(dummy);
Expand All @@ -81,7 +81,7 @@ TEST_CASE("test methods handling", "[methods_handler]")

SECTION("check endpoint propagation with description")
{
auto dummy = [](served::response & res, const served::request & req) {};
auto dummy = [](served::response &, const served::request &) {};

served::methods_handler h("/this/path/is/great", "This is an endpoint for great stuff");
h.get(dummy).put(dummy).del(dummy);
Expand Down
8 changes: 4 additions & 4 deletions src/served/multiplexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ split_path(const std::string & path)
const char * path_ptr = path.c_str();
const size_t path_len = path.length();

char tmp[path.length()];
char * const tmp = new char[path.length()];
char * end = tmp;

const char * const eol = path_ptr + path_len;
Expand Down Expand Up @@ -101,7 +101,7 @@ split_path(const std::string & path)
// Push back an empty string for paths ending in /
chunks.push_back("");
}

delete[] tmp;
return chunks;
}

Expand Down Expand Up @@ -297,8 +297,8 @@ multiplexer::get_endpoint_list()
served_req_handler
multiplexer::get_endpoint_list_handler_YAML()
{
return [this](served::response & res, const served::request & req) {
res.set_header("Content-Type", "text/yaml");
return [this](served::response & res, const served::request &) {
res.set_header("Content-Type", "text/yaml");

res << "%YAML 1.2\n---";

Expand Down
32 changes: 18 additions & 14 deletions src/served/multiplexer.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class path_collecting_functor

void operator()(served::response & response, const served::request & request)
{
(void) response;
_story_obj.received.push_back(request.url().path());
_story_obj.params = request.params;
}
Expand Down Expand Up @@ -340,8 +341,8 @@ TEST_CASE("multiplexer hierarchy test", "[mux]")
{
bool correct_call = false;

auto dummy_call = [&](served::response & res, const served::request & req) {};
auto expected_call = [&](served::response & res, const served::request & req) {
auto dummy_call = [&](served::response &, const served::request &) {};
auto expected_call = [&](served::response &, const served::request &) {
correct_call = true;
};

Expand All @@ -367,8 +368,8 @@ TEST_CASE("multiplexer hierarchy test", "[mux]")
{
bool correct_call = false;

auto dummy_call = [&](served::response & res, const served::request & req) {};
auto expected_call = [&](served::response & res, const served::request & req) {
auto dummy_call = [&](served::response &, const served::request &) {};
auto expected_call = [&](served::response &, const served::request &) {
correct_call = true;
};

Expand Down Expand Up @@ -421,9 +422,11 @@ TEST_CASE("multiplexer test base path", "[mux]")
{
served::multiplexer mux("/base/path");
mux.handle("/end").get([](served::response & res, const served::request & req){
(void) req;
res.set_status(served::status_2XX::ACCEPTED);
});
mux.handle("/").get([](served::response & res, const served::request & req){
(void) req;
res.set_status(served::status_2XX::NO_CONTENT);
});

Expand Down Expand Up @@ -468,6 +471,7 @@ TEST_CASE("multiplexer test base path", "[mux]")
{
served::multiplexer mux("/base/{TEST}");
mux.handle("/end").get([](served::response & res, const served::request & req) {
(void) req;
res.set_status(served::status_2XX::OK);
});

Expand All @@ -492,19 +496,19 @@ TEST_CASE("multiplexer test plugins", "[mux]")
int touches = 0;
served::multiplexer mux;
mux.handle("/test")
.get([&](served::response & res, const served::request & req) {
.get([&](served::response &, const served::request &) {
if ( touches == 1 )
{
touches++;
}
});
mux.use_before([&](served::response & res, const served::request & req) {
mux.use_before([&](served::response &, const served::request &) {
if ( touches == 0 )
{
touches++;
}
});
mux.use_after([&](served::response & res, const served::request & req) {
mux.use_after([&](served::response &, const served::request &) {
if ( touches == 2 )
{
touches++;
Expand Down Expand Up @@ -534,28 +538,28 @@ TEST_CASE("multiplexer test wrapped plugins", "[mux]")
served::multiplexer mux;

mux.handle("/test")
.get([&](served::response & res, const served::request & req) {
.get([&](served::response &, const served::request &) {
if ( touches == 3 )
{
touches++;
}
});

mux.use_wrapper([&](served::response & res, served::request & req, std::function<void()> func) {
mux.use_wrapper([&](served::response &, served::request &, std::function<void()> func) {
if ( touches == 0 )
{
touches++;
}
func();
});
mux.use_wrapper([&](served::response & res, served::request & req, std::function<void()> func) {
mux.use_wrapper([&](served::response &, served::request &, std::function<void()> func) {
if ( touches == 1 )
{
touches++;
}
func();
});
mux.use_wrapper([&](served::response & res, served::request & req, std::function<void()> func) {
mux.use_wrapper([&](served::response &, served::request &, std::function<void()> func) {
if ( touches == 2 )
{
touches++;
Expand Down Expand Up @@ -595,7 +599,7 @@ TEST_CASE("multiplexer test endpoint list", "[mux]")
{
SECTION("without base path")
{
auto dummy = [](served::response & res, const served::request & req){};
auto dummy = [](served::response &, const served::request &){};

served::multiplexer mux;
mux.handle("/first/test", "This is first").get(dummy).post(dummy).del(dummy);
Expand Down Expand Up @@ -647,7 +651,7 @@ TEST_CASE("multiplexer test endpoint list", "[mux]")

SECTION("with base path")
{
auto dummy = [](served::response & res, const served::request & req){};
auto dummy = [](served::response &, const served::request &){};

served::multiplexer mux("/base/path");
mux.handle("/first/test", "This is first").get(dummy).post(dummy).del(dummy);
Expand Down Expand Up @@ -702,7 +706,7 @@ TEST_CASE("multiplexer endpoint list YAML", "[mux]")
{
SECTION("request router stories")
{
auto dummy = [](served::response & res, const served::request & req){};
auto dummy = [](served::response &, const served::request &){};

served::multiplexer mux;
mux.handle("/first/test", "This is first").get(dummy).post(dummy).del(dummy);
Expand Down
Loading

0 comments on commit 02c33e7

Please sign in to comment.