diff --git a/.travis.yml b/.travis.yml index 7d16d0d..05fbc71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,37 +1,24 @@ -sudo: required -dist: trusty +os: linux +dist: bionic language: generic -compiler: - - gcc +services: + - docker env: - global: - - CATKIN_WS=~/catkin_ws - - CATKIN_WS_SRC=${CATKIN_WS}/src matrix: - - CI_ROS_DISTRO="indigo" - - CI_ROS_DISTRO="jade" - -branches: - only: - - master - - develop + - CI_ROS_DISTRO="kinetic" + - CI_ROS_DISTRO="melodic" + - CI_ROS_DISTRO="noetic" install: - - sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu trusty main" > /etc/apt/sources.list.d/ros-latest.list' - - wget http://packages.ros.org/ros.key -O - | sudo apt-key add - - - sudo apt-get update -qq - - sudo apt-get install -qq -y python-rosdep python-catkin-tools - - sudo rosdep init - - rosdep update - - rosdep install --from-paths ./ -i -y --rosdistro $CI_ROS_DISTRO + - docker pull ros:${CI_ROS_DISTRO}-ros-core + - docker run --name ci_runner -i -d --rm -v $(pwd):/catkin_ws/src ros:${CI_ROS_DISTRO}-ros-core + - docker exec ci_runner /bin/bash -c "apt update; apt install -y build-essential" + - if [ "${CI_ROS_DISTRO}" == "noetic" ]; then docker exec ci_runner /bin/bash -c "apt install -y python3-rosdep python3-catkin-tools python3-osrf-pycommon"; fi + - if [ "${CI_ROS_DISTRO}" != "noetic" ]; then docker exec ci_runner /bin/bash -c "apt install -y python-rosdep python-catkin-tools"; fi + - docker exec ci_runner /bin/bash -c "source ./ros_entrypoint.sh; rosdep init; rosdep update; rosdep install --from-paths /catkin_ws/src --ignore-src -y" script: - - source /opt/ros/$CI_ROS_DISTRO/setup.bash - - mkdir -p $CATKIN_WS_SRC - - ln -s $TRAVIS_BUILD_DIR $CATKIN_WS_SRC - - cd $CATKIN_WS - - catkin init - - catkin config --install - - catkin build --limit-status-rate 0.1 --no-notify -DCMAKE_BUILD_TYPE=Release - - catkin build --limit-status-rate 0.1 --no-notify --make-args tests - - catkin run_tests + - docker exec ci_runner /bin/bash -c "source ./ros_entrypoint.sh; cd /catkin_ws; catkin init; catkin config --install" + - docker exec ci_runner /bin/bash -c "source ./ros_entrypoint.sh; cd /catkin_ws; catkin build --limit-status-rate 0.1 --no-notify -DCMAKE_BUILD_TYPE=Release" + - docker exec ci_runner /bin/bash -c "source ./ros_entrypoint.sh; cd /catkin_ws; catkin build --limit-status-rate 0.1 --no-notify --make-args tests" + - docker exec ci_runner /bin/bash -c "source ./ros_entrypoint.sh; cd /catkin_ws; catkin run_tests" diff --git a/CMakeLists.txt b/CMakeLists.txt index 163132c..f433129 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.3) +cmake_minimum_required(VERSION 3.0.2) project(async_web_server_cpp) ## Find catkin macros and libraries diff --git a/package.xml b/package.xml index 882fbca..60c5640 100644 --- a/package.xml +++ b/package.xml @@ -1,4 +1,4 @@ - + async_web_server_cpp 0.0.3 Asynchronous Web/WebSocket Server in C++ @@ -23,5 +23,6 @@ rostest rospy roslib - python-websocket + python-websocket + python3-websocket diff --git a/src/http_connection.cpp b/src/http_connection.cpp index 72e94e1..23e419b 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -134,6 +134,7 @@ void HttpConnection::write_pending() void HttpConnection::handle_write(const boost::system::error_code &e, std::vector resources) { + (void) resources; boost::mutex::scoped_lock lock(write_mutex_); write_in_progress_ = false; if (!e) diff --git a/src/http_reply.cpp b/src/http_reply.cpp index 92b6840..efd1990 100644 --- a/src/http_reply.cpp +++ b/src/http_reply.cpp @@ -279,6 +279,9 @@ static bool serveFromFile(HttpReply::status_type status, const std::string& file } bool FileHttpRequestHandler::operator()(const HttpRequest &request, boost::shared_ptr connection, const char* begin, const char* end) { + (void) request; + (void) begin; + (void) end; return serveFromFile(status_, filename_, headers_, connection); } @@ -349,9 +352,7 @@ bool FilesystemHttpRequestHandler::operator()(const HttpRequest &request, boost: return false; } } - else { - return false; - } + return false; } @@ -383,6 +384,9 @@ StaticHttpRequestHandler::StaticHttpRequestHandler(HttpReply::status_type status bool StaticHttpRequestHandler::operator()(const HttpRequest &request, boost::shared_ptr connection, const char* begin, const char* end) { + (void) request; + (void) begin; + (void) end; reply_builder_.write(connection); connection->write(content_string_); return true; diff --git a/src/http_request.cpp b/src/http_request.cpp index 7fe52e6..ce696e2 100644 --- a/src/http_request.cpp +++ b/src/http_request.cpp @@ -23,7 +23,7 @@ bool HttpRequest::parse_uri() BOOST_FOREACH(const std::string & pair_string, pair_strings) { std::vector pair_data; - const int eq_index = pair_string.find_first_of('='); + const size_t eq_index = pair_string.find_first_of('='); if (eq_index == std::string::npos) { if (pair_string.size() > 0) diff --git a/src/http_request_handler.cpp b/src/http_request_handler.cpp index a949342..35d1e19 100644 --- a/src/http_request_handler.cpp +++ b/src/http_request_handler.cpp @@ -45,7 +45,7 @@ void HttpRequestHandlerGroup::addHandler(HandlerPredicate predicate, HttpServerR bool HttpRequestHandlerGroup::operator()(const HttpRequest &request, boost::shared_ptr connection, const char* begin, const char* end) { - for (int i = 0; i < handlers_.size(); ++i) + for (size_t i = 0; i < handlers_.size(); ++i) { std::pair &handler = handlers_[i]; if (handler.first(request)) @@ -87,7 +87,7 @@ class BodyCollectingConnection : public boost::enable_shared_from_this= length_) { + if(received_length_ >= size_t(length_)) { handler_(request_, connection_, body_stream_.str().substr(0, length_)); } else { diff --git a/src/websocket_message.cpp b/src/websocket_message.cpp index 038deb3..74a2609 100644 --- a/src/websocket_message.cpp +++ b/src/websocket_message.cpp @@ -194,7 +194,7 @@ boost::tribool WebsocketFrameParser::consume(WebsocketFrame& frame, char input) //unmask the frame if (frame.header.mask) { - for (int i = 0; i < frame.length; ++i) + for (uint64_t i = 0; i < frame.length; ++i) { frame.content[i] = frame.content[i] ^ frame.mask[i % 4]; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f42bd54..f127373 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,6 @@ add_executable(test_web_server EXCLUDE_FROM_ALL test_web_server.cpp) target_link_libraries(test_web_server ${PROJECT_NAME} ${catkin_LIBRARIES}) +target_include_directories(test_web_server PRIVATE ${catkin_INCLUDE_DIRS}) if(TARGET tests) add_dependencies(tests diff --git a/test/simple_http_requests_test.py b/test/simple_http_requests_test.py index 4a5e5f3..9d1e738 100755 --- a/test/simple_http_requests_test.py +++ b/test/simple_http_requests_test.py @@ -1,6 +1,10 @@ #! /usr/bin/env python -import httplib +import sys +if sys.version_info > (3,): + import http.client as httplib +else: + import httplib import rospy import unittest import time @@ -48,17 +52,17 @@ def test_default_action(self): self.conn.request("GET", "/a_static_response") response = self.conn.getresponse() self.assertEqual(200, response.status) - self.assertEqual("A RESPONSE", response.read()) + self.assertEqual(b"A RESPONSE", response.read()) def test_http_echo1(self): - test_content = "hello HELLO"*1000 # make sure to exceed MTU + test_content = b"hello HELLO"*1000 # make sure to exceed MTU self.conn.request("GET", "/http_body_echo", test_content) response = self.conn.getresponse() self.assertEqual(200, response.status) self.assertEqual(test_content, response.read()) def test_http_echo2(self): - test_content = "THIS is A test"*1000 # make sure to exceed MTU + test_content = b"THIS is A test"*1000 # make sure to exceed MTU self.conn.request("POST", "/http_body_echo", test_content) response = self.conn.getresponse() self.assertEqual(200, response.status) @@ -68,25 +72,25 @@ def test_http_path_echo(self): self.conn.request("GET", "/http_path_echo/this_is_a_test") response = self.conn.getresponse() self.assertEqual(200, response.status) - self.assertEqual("/http_path_echo/this_is_a_test", response.read()) + self.assertEqual(b"/http_path_echo/this_is_a_test", response.read()) def test_http_query_echo(self): self.conn.request("GET", "/http_query_echo?hello=1&b=test&c=10") response = self.conn.getresponse() self.assertEqual(200, response.status) - self.assertEqual("b=test\nc=10\nhello=1\n", response.read()) + self.assertEqual(b"b=test\nc=10\nhello=1\n", response.read()) def test_file(self): self.conn.request("GET", "/test_file") response = self.conn.getresponse() self.assertEqual(200, response.status) - self.assertEqual("\n", response.read()) + self.assertEqual(b"\n", response.read()) def test_file_from_filesystem(self): self.conn.request("GET", "/test_files/test_dir/test_file.txt") response = self.conn.getresponse() self.assertEqual(200, response.status) - self.assertEqual("test\n", response.read()) + self.assertEqual(b"test\n", response.read()) def test_directory_listing_forbidden_from_filesystem1(self): self.conn.request("GET", "/test_files/test_dir/") diff --git a/test/websocket_test.py b/test/websocket_test.py index 67516d9..71afb7f 100755 --- a/test/websocket_test.py +++ b/test/websocket_test.py @@ -20,15 +20,15 @@ def test_ok(self): self.ws.send("hi") self.assertEqual("hi", self.ws.recv()) - self.ws.ping("test ping") + self.ws.ping(b"test ping") ping_echo = self.ws.recv_frame() self.assertEqual(9, ping_echo.opcode) - self.assertEqual("test ping", ping_echo.data) + self.assertEqual(b"test ping", ping_echo.data) - self.ws.pong("test pong") + self.ws.pong(b"test pong") pong_echo = self.ws.recv_frame() self.assertEqual(10, pong_echo.opcode) - self.assertEqual("test pong", pong_echo.data) + self.assertEqual(b"test pong", pong_echo.data) if __name__ == '__main__': time.sleep(1) # ensure server is up