From 00f2e04d9e5ea0af7862a336136b3d77881a8760 Mon Sep 17 00:00:00 2001 From: Michael Heilmann Date: Tue, 7 Jun 2016 10:28:29 -0400 Subject: [PATCH 1/2] fixup for linux compilation. TCHAR was removed without investigation, may present problems later. --- CMakeLists.txt | 5 +- aperture/AppLog.cpp | 4 +- aperture/Asset.cpp | 10 ++-- aperture/AssetServer.cpp | 2 +- aperture/AssetServer.h | 10 ++-- aperture/AuthChallengeMsg.cpp | 2 +- aperture/AuthResponseMsg.cpp | 15 +++--- aperture/AuthResponseMsg.h | 4 +- aperture/AuthStatusMsg.cpp | 7 +-- aperture/ClientRequestMsg.cpp | 8 ++-- aperture/SHA1.cpp | 4 +- aperture/ServerResponseMsg.cpp | 6 +-- aperture/Settings.cpp | 2 +- aperture/Validator.cpp | 2 +- aperture/WhipURI.cpp | 8 ++-- aperture/nix_main.cpp | 84 ++++++++++++++++++++++++++++++++++ aperture/stdafx.h | 6 +-- 17 files changed, 133 insertions(+), 46 deletions(-) create mode 100644 aperture/nix_main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bce6bb..3b5fd40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ set(LIBS ${LIBS} ${Boost_THREAD_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_CHRONO_LIBRARY}) -find_package( Curl REQUIRED) +find_package( CURL REQUIRED) set(INCLUDES ${INCLUDES} ${CURL_INCLUDE_DIRS}) set(LIBS ${LIBS} ${CURL_LIBRARIES}) @@ -48,7 +48,7 @@ set ( Aperture_srcs aperture/request_parser.cpp aperture/server.cpp aperture/ServerResponseMsg.cpp aperture/Settings.cpp aperture/SHA1.cpp aperture/stdafx.cpp aperture/TokenBucket.cpp - aperture/Validator.cpp aperture/WhipURI.cpp aperture/win_main.cpp + aperture/Validator.cpp aperture/WhipURI.cpp aperture/win_main.cpp aperture/nix_main.cpp ${PROTO_SRCS} ) @@ -59,3 +59,4 @@ add_definitions(${DEFS}) include_directories(${INCLUDES}) add_executable( aperture ${Aperture_srcs}) target_link_libraries(aperture ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS} ${LIBS} ) +target_compile_features(aperture PRIVATE cxx_range_for ) diff --git a/aperture/AppLog.cpp b/aperture/AppLog.cpp index ce5f7c4..a2f592d 100644 --- a/aperture/AppLog.cpp +++ b/aperture/AppLog.cpp @@ -1,4 +1,4 @@ -#include "StdAfx.h" +#include "stdafx.h" #include "AppLog.h" #include @@ -25,4 +25,4 @@ namespace aperture (*AppLog::_logStream) << "[" << now << "] "; return *AppLog::_logStream; } -} \ No newline at end of file +} diff --git a/aperture/Asset.cpp b/aperture/Asset.cpp index 0da3466..7371303 100644 --- a/aperture/Asset.cpp +++ b/aperture/Asset.cpp @@ -1,6 +1,6 @@ -#include "StdAfx.h" +#include "stdafx.h" #include "Asset.h" -#include "Winsock2.h" +//#include "Winsock2.h" #include #include @@ -63,7 +63,7 @@ boost::tuple Asset::findDataLocationAndSize() const aperture::byte nameFieldSz = (*_data)[currLoc]; //skip those bytes currLoc += nameFieldSz + 1; - + //next up is the sz of the description field, skip those bytes aperture::byte descFieldSz = (*_data)[currLoc]; currLoc += descFieldSz + 1; @@ -75,7 +75,7 @@ boost::tuple Asset::findDataLocationAndSize() const return boost::tuple(currLoc + sizeof(unsigned int), dataSz); } -unsigned int Asset::copyAssetData(std::string& storage) const +unsigned int Asset::copyAssetData(std::string& storage) const { unsigned int dataLoc; unsigned int dataSz; @@ -129,4 +129,4 @@ unsigned int Asset::copyAssetData(std::string& storage, unsigned int rngStart, u return dataSz; } -} \ No newline at end of file +} diff --git a/aperture/AssetServer.cpp b/aperture/AssetServer.cpp index d4daac2..2b181f5 100644 --- a/aperture/AssetServer.cpp +++ b/aperture/AssetServer.cpp @@ -1,4 +1,4 @@ -#include "StdAfx.h" +#include "stdafx.h" #include "AssetServer.h" #include "AppLog.h" #include "ClientRequestMsg.h" diff --git a/aperture/AssetServer.h b/aperture/AssetServer.h index f236ece..05ef5b1 100644 --- a/aperture/AssetServer.h +++ b/aperture/AssetServer.h @@ -40,7 +40,7 @@ namespace whip typedef boost::function ConnectCallback; typedef boost::function SafeKillCallback; - enum ConnectionState + enum ConnectionState { CSTATE_DISCONNECTED, CSTATE_CONNECTING, @@ -100,9 +100,9 @@ namespace whip void onConnect(const boost::system::error_code& error); - + void onRecvChallenge(const boost::system::error_code& error, size_t bytesRcvd, AuthChallengeMsg::ptr challenge); - + void onChallengeResponseWrite(const boost::system::error_code& error, size_t bytesSent, AuthResponseMsg::ptr authResponse); @@ -169,11 +169,11 @@ namespace whip /** * Retrieves the given asset from this server */ - virtual void AssetServer::getAsset(const std::string& uuid, boost::function callBack); + virtual void getAsset(const std::string& uuid, boost::function callBack); /** * Shuts down the connections and marks this server as shut down */ virtual void shutdown(); }; -} \ No newline at end of file +} diff --git a/aperture/AuthChallengeMsg.cpp b/aperture/AuthChallengeMsg.cpp index 9f88dfd..f15f849 100644 --- a/aperture/AuthChallengeMsg.cpp +++ b/aperture/AuthChallengeMsg.cpp @@ -1,4 +1,4 @@ -#include "StdAfx.h" +#include "stdafx.h" #include "AuthChallengeMsg.h" namespace whip diff --git a/aperture/AuthResponseMsg.cpp b/aperture/AuthResponseMsg.cpp index b9a9aaf..d443ebe 100644 --- a/aperture/AuthResponseMsg.cpp +++ b/aperture/AuthResponseMsg.cpp @@ -1,4 +1,4 @@ -#include "StdAfx.h" +#include "stdafx.h" #include #include @@ -21,7 +21,8 @@ AuthResponseMsg::AuthResponseMsg() AuthResponseMsg::AuthResponseMsg(const std::string& challenge, const std::string& password) { - _data.push_back(PACKET_IDENTIFIER); + aperture::byte val = PACKET_IDENTIFIER; + _data.push_back(val); //calculate our response string correctHash = this->calculateChallengeResponse(challenge, password); @@ -50,15 +51,15 @@ bool AuthResponseMsg::isServerResponse() const bool AuthResponseMsg::isValid(AuthChallengeMsg::ptr authChallenge) { //check the header - if (_data[0] != PACKET_IDENTIFIER && - _data[0] != SERVER_IDENTIFIER) + if (_data[0] != AuthResponseMsg::PACKET_IDENTIFIER && + _data[0] != AuthResponseMsg::SERVER_IDENTIFIER) { return false; } string correctHash = this->calculateChallengeResponse(authChallenge->getPhrase(), Settings::instance().config()["password"].as()); - + if (correctHash == this->getChallengeResponse()) { return true; } @@ -69,7 +70,7 @@ bool AuthResponseMsg::isValid(AuthChallengeMsg::ptr authChallenge) std::string AuthResponseMsg::calculateChallengeResponse(const std::string& phrase, const std::string& password) { CSHA1 sha; - + //calculate the correct hash based on password and the challenge that was sent string correctHash(password + phrase); sha.Update((unsigned char*) correctHash.data(), boost::numeric_cast(correctHash.size())); @@ -79,4 +80,4 @@ std::string AuthResponseMsg::calculateChallengeResponse(const std::string& phras return correctHash; } -} \ No newline at end of file +} diff --git a/aperture/AuthResponseMsg.h b/aperture/AuthResponseMsg.h index 66ad7f4..98931a4 100644 --- a/aperture/AuthResponseMsg.h +++ b/aperture/AuthResponseMsg.h @@ -18,7 +18,7 @@ class AuthResponseMsg const static aperture::byte SERVER_IDENTIFIER = 100; const static short RESPONSE_SIZE = 40; - + aperture::byte_array _data; public: @@ -56,4 +56,4 @@ class AuthResponseMsg */ bool isServerResponse() const; }; -} \ No newline at end of file +} diff --git a/aperture/AuthStatusMsg.cpp b/aperture/AuthStatusMsg.cpp index d46d517..eb29baf 100644 --- a/aperture/AuthStatusMsg.cpp +++ b/aperture/AuthStatusMsg.cpp @@ -1,4 +1,4 @@ -#include "StdAfx.h" +#include "stdafx.h" #include "AuthStatusMsg.h" namespace whip @@ -10,7 +10,8 @@ AuthStatusMsg::AuthStatusMsg() AuthStatusMsg::AuthStatusMsg(AuthStatus authStatus) { - _messageData.push_back(AuthStatusMsg::PACKET_IDENTIFIER); + aperture::byte val = PACKET_IDENTIFIER; + _messageData.push_back(val); _messageData.push_back(static_cast(authStatus)); } @@ -51,4 +52,4 @@ bool AuthStatusMsg::validate() const return true; } -} \ No newline at end of file +} diff --git a/aperture/ClientRequestMsg.cpp b/aperture/ClientRequestMsg.cpp index 246e3e8..45741a4 100644 --- a/aperture/ClientRequestMsg.cpp +++ b/aperture/ClientRequestMsg.cpp @@ -1,12 +1,12 @@ -#include "StdAfx.h" +#include "stdafx.h" #include "ClientRequestMsg.h" -#include "Winsock2.h" +//#include "Winsock2.h" ClientRequestMsg::ClientRequestMsg() : _header(HEADER_SIZE) { - + } ClientRequestMsg::ClientRequestMsg(RequestType type, const std::string& uuid) { @@ -56,4 +56,4 @@ aperture::byte_array_ptr ClientRequestMsg::getData() unsigned int ClientRequestMsg::getDataSize() const { return ntohl(*((unsigned int*)&_header[DATA_SIZE_MARKER_LOC])); -} \ No newline at end of file +} diff --git a/aperture/SHA1.cpp b/aperture/SHA1.cpp index 4b80d78..6f2bc20 100644 --- a/aperture/SHA1.cpp +++ b/aperture/SHA1.cpp @@ -6,8 +6,8 @@ See header file for version history. */ -// If compiling with MFC, you might want to add #include "StdAfx.h" -#include "StdAfx.h" +// If compiling with MFC, you might want to add #include "stdafx.h" +#include "stdafx.h" #include diff --git a/aperture/ServerResponseMsg.cpp b/aperture/ServerResponseMsg.cpp index bdff688..b657332 100644 --- a/aperture/ServerResponseMsg.cpp +++ b/aperture/ServerResponseMsg.cpp @@ -1,6 +1,6 @@ -#include "StdAfx.h" +#include "stdafx.h" #include "ServerResponseMsg.h" -#include "Winsock2.h" +//#include "Winsock2.h" #include @@ -87,4 +87,4 @@ std::string ServerResponseMsg::getAssetUUID() const return std::string((const char*)&_header[UUID_LOC], 32); } -} \ No newline at end of file +} diff --git a/aperture/Settings.cpp b/aperture/Settings.cpp index 92f8a86..eb5f77b 100644 --- a/aperture/Settings.cpp +++ b/aperture/Settings.cpp @@ -1,4 +1,4 @@ -#include "StdAfx.h" +#include "stdafx.h" #include "Settings.h" diff --git a/aperture/Validator.cpp b/aperture/Validator.cpp index 4da1f99..73b10ca 100644 --- a/aperture/Validator.cpp +++ b/aperture/Validator.cpp @@ -1,4 +1,4 @@ -#include "StdAfx.h" +#include "stdafx.h" #include "Validator.h" #include diff --git a/aperture/WhipURI.cpp b/aperture/WhipURI.cpp index 7576a75..87f6e2d 100644 --- a/aperture/WhipURI.cpp +++ b/aperture/WhipURI.cpp @@ -1,4 +1,4 @@ -#include "StdAfx.h" +#include "stdafx.h" #include "WhipURI.h" #include @@ -14,7 +14,7 @@ namespace whip string uri(url); //parse the uri //url must start with whip - if (uri.substr(0, 7) != "whip://") throw std::runtime_error("Invaid whip URL. Must start with whip://"); + if (uri.substr(0, 7) != "whip://") throw std::runtime_error("Invalid whip URL. Must start with whip://"); //strip the Resource ID portion uri = uri.substr(7); @@ -26,7 +26,7 @@ namespace whip //get the user and pass string pass = userAndHost[0]; - + //get the host and port vector hostAndPort; boost::split(hostAndPort, userAndHost[1], boost::is_any_of(":")); @@ -55,4 +55,4 @@ namespace whip { return _password; } -} \ No newline at end of file +} diff --git a/aperture/nix_main.cpp b/aperture/nix_main.cpp new file mode 100644 index 0000000..7bc6746 --- /dev/null +++ b/aperture/nix_main.cpp @@ -0,0 +1,84 @@ +#include "stdafx.h" + +#include +#include +#include +#include +#include +#include + +#include "server.hpp" +#include "AppLog.h" +#include "Settings.h" +#include "AssetServer.h" +#include "WhipURI.h" +#include "CloudFilesConnector.h" + +#if !defined(_WIN32) + +boost::function0 console_ctrl_function; + +void console_ctrl_handler(int sig) +{ + aperture::AppLog::instance().out() << "Clean shutdown initiated" << std::endl; + console_ctrl_function(); +} + +const std::string& VERSION = "2.53"; + +int main(int argc, char* argv[]) +{ + using namespace aperture; + + try + { + boost::asio::io_service ioService; + + AppLog::SetLogStream(&std::cout); + + AppLog::instance().out() << "InWorldz Aperture Server " << VERSION << std::endl; + AppLog::instance().out() << "Build: " << __DATE__ " " __TIME__ << std::endl; + + auto config = Settings::instance().config(); + if (config["debug"].as()) { + AppLog::instance().out() << "DEBUGGING ENABLED" << std::endl; + } + + // Start connection to whip server + whip::AssetServer::ptr assetServer; + if (config["enable_whip"].as()) { + whip::WhipURI uri = Settings::instance().getWhipURL(); + AppLog::instance().out() << "Starting connection to WHIP server: " << uri.getHostName() << ":" << uri.getPort() << std::endl; + assetServer.reset(new whip::AssetServer(uri, ioService)); + assetServer->connect(); + } + + // Start connection to cloudfiles + cloudfiles::CloudFilesConnector::ptr cfConnector; + if (config["enable_cloudfiles"].as()) { + cfConnector.reset(new cloudfiles::CloudFilesConnector(ioService)); + } + + // Initialize server + std::string capsToken = config["caps_token"].as(); + http::server::server s(config["http_listen_port"].as(), + ioService, assetServer, cfConnector, capsToken); + + // Set console control handler to allow server to be stopped. + console_ctrl_function = boost::bind(&http::server::server::stop, &s); + //SetConsoleCtrlHandler(console_ctrl_handler, TRUE); + signal(SIGINT, console_ctrl_handler); + + // Run the server until stopped. + s.run(); + } + catch (std::exception& e) + { + AppLog::instance().out() << "EXCEPTION: " << e.what() << std::endl; + AppLog::instance().out() << "Application is terminating" << std::endl; + } + + return 0; +} + +#endif // defined(_WIN32) diff --git a/aperture/stdafx.h b/aperture/stdafx.h index f726793..10c0271 100644 --- a/aperture/stdafx.h +++ b/aperture/stdafx.h @@ -8,14 +8,14 @@ #include "targetver.h" #include -#include +//#include #include #include #include #include #include -#include +#include #include "AppLog.h" -#include "Settings.h" \ No newline at end of file +#include "Settings.h" From f1d22452b236d6ed224fee90e6355abe2e334852 Mon Sep 17 00:00:00 2001 From: Michael Heilmann Date: Tue, 7 Jun 2016 15:07:27 -0400 Subject: [PATCH 2/2] updated readme to reflect changes. Re-enabled tchar for windows-based builds. --- README.md | 23 +++++++++++++++++++++++ aperture/stdafx.h | 5 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a826426..0f7c90b 100644 --- a/README.md +++ b/README.md @@ -5,5 +5,28 @@ mesh data to viewer software connected to the InWorldz grid ### Sample cmake build command for windows +This fork of aperture has been modified for compilation on linux. Building on windows has likely been affected. + cmake .. -DCMAKE_BUILD_TYPE=Debug -DCURL_LIBRARY=C:\lib\curl-7.44.0\builds\libcurl-vc-x64-debug-dll-ipv6-sspi-winssl\lib\libcurl_debug.lib -DCURL_INCLUDE_DIR=C:\lib\curl-7.44.0\include -DPROTOBUF_LIBRARY=C:\lib\protobuf-2.6.1\vsprojects\x64\Debug\libprotobuf.lib -DPROTOBUF_INCLUDE_DIR=C:\lib\protobuf-2.6.1\src -DPROTOBUF_PROTOC_EXECUTABLE=C:\lib\protobuf-2.6.1\vsprojects\x64\Debug\protoc.exe -G "Visual Studio 14 2015 Win64" + +### Directions for Ubuntu 16.04 LTS + +These are the basic commands in order based off of my terminal history, they may not be precise. + +1. Install cmake, protobuf-compiler, libboost1.58-all-dev +1. clone aperture +1. cd aperture +1. mkdir build +1. cd build +1. cmake .. +1. make +1. Create the configuration file + +A bare-bones aperture.cfg file is: +
+http_listen_port = 
+caps_token = 2960079
+whip_url = whip://@:32700
+
+ diff --git a/aperture/stdafx.h b/aperture/stdafx.h index 10c0271..565b269 100644 --- a/aperture/stdafx.h +++ b/aperture/stdafx.h @@ -8,7 +8,10 @@ #include "targetver.h" #include -//#include + +#if defined(_WIN32) +#include +#endif #include #include