Skip to content

Commit

Permalink
Added Dependency management and new C++ Server code
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderoster committed Feb 15, 2022
1 parent cf24428 commit 88d6419
Show file tree
Hide file tree
Showing 421 changed files with 73,487 additions and 50,239 deletions.
42 changes: 42 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[submodule "submodules/cppcodec"]
path = submodules/cppcodec
url = https://github.com/tplgy/cppcodec.git
[submodule "submodules/crossguid"]
path = submodules/crossguid
url = https://github.com/graeme-hill/crossguid.git
[submodule "submodules/libzip"]
path = submodules/libzip
url = https://github.com/nih-at/libzip.git
[submodule "submodules/lodepng"]
path = submodules/lodepng
url = https://github.com/lvandeve/lodepng.git
[submodule "submodules/PicoSHA2"]
path = submodules/PicoSHA2
url = https://github.com/okdshin/PicoSHA2.git
[submodule "submodules/pugixml"]
path = submodules/pugixml
url = https://github.com/zeux/pugixml.git
[submodule "submodules/rapidjson"]
path = submodules/rapidjson
url = https://github.com/Tencent/rapidjson.git
[submodule "submodules/sqlite"]
path = submodules/sqlite
url = https://github.com/sqlite/sqlite.git
[submodule "submodules/zlib"]
path = submodules/zlib
url = https://github.com/madler/zlib.git
[submodule "submodules/AutomaticComponentToolkit"]
path = submodules/AutomaticComponentToolkit
url = https://github.com/Autodesk/AutomaticComponentToolkit.git
[submodule "submodules/lib3mf"]
path = submodules/lib3mf
url = https://github.com/3MFConsortium/lib3mf.git
[submodule "submodules/uWebSockets"]
path = submodules/uWebSockets
url = https://github.com/uNetworking/uWebSockets.git
[submodule "submodules/curl"]
path = submodules/curl
url = https://github.com/curl/curl.git
[submodule "submodules/libuv"]
path = submodules/libuv
url = https://github.com/libuv/libuv.git
8 changes: 4 additions & 4 deletions ACT/LibMC.xml
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,11 @@

<error name="DUPLICATEBUTTONNAME" code="405" description="Duplicate button name" />

<error name="SERVERCONFIGURATIONNOTLOADED" code="406" description="Server configuration not loaded" />
<error name="COULDNOTPARSESERVERCONFIGURATION" code="407" description="Could not pars server configuration" />
<error name="MISSINGSERVERCONFIGURATIONNODE" code="408" description="Missing server configuration node" />
<error name="COULDNOTFINDLIBRARYENTRY" code="409" description="Could not find library entry" />





</errors>


Expand Down
67 changes: 66 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ project(LibMC)
add_subdirectory(Drivers)
add_subdirectory(Plugins)

set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD 17)

# The location of autogenerated interfaces
set(CMAKE_CURRENT_AUTOGENERATED_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Framework/InterfacesCore)
Expand Down Expand Up @@ -245,6 +245,8 @@ set_target_properties(libmcdata PROPERTIES PREFIX "" IMPORT_PREFIX "" )
set_target_properties(libmcdata PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties(libmcdata PROPERTIES VISIBILITY_INLINES_HIDDEN ON)



if(WIN32)

if (MSVC)
Expand Down Expand Up @@ -304,6 +306,7 @@ set_target_properties(libmcdata
)



add_custom_target(configuration_xml ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Plugins/config.xml)

set_property(TARGET configuration_xml APPEND PROPERTY SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Plugins/config.xml)
Expand Down Expand Up @@ -387,3 +390,65 @@ if(UNIX)
endif()
endif()


#[[++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++ AMC Server Project Definition
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
]]


file(GLOB SERVER_SRC
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Server/amc_server.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Server/amc_server_console.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Server/amc_server_io.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Server/amc_server_configuration.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Libraries/PugiXML/pugixml.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Libraries/uWebSockets/uSockets/*.c
${CMAKE_CURRENT_SOURCE_DIR}/Libraries/uWebSockets/uSockets/eventing/*.c
${CMAKE_CURRENT_SOURCE_DIR}/Libraries/uWebSockets/uSockets/crypto/*.c
${CMAKE_CURRENT_SOURCE_DIR}/Libraries/uWebSockets/uSockets/crypto/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Libraries/zlib/*.c
${CMAKE_CURRENT_SOURCE_DIR}/Libraries/libuv/src/*.c
${CMAKE_CURRENT_SOURCE_DIR}/Libraries/libuv/src/*.c
${CMAKE_CURRENT_SOURCE_DIR}/Libraries/libuv/src/win/*.c
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Common/common_utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Common/common_importstream_native.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Common/common_exportstream_native.cpp
)

add_executable(server ${SERVER_SRC})
target_include_directories(server PRIVATE ${CMAKE_CURRENT_HEADERS_CORE_DIR})
target_include_directories(server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/PugiXML)
target_include_directories(server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/)
target_include_directories(server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/zlib)
target_include_directories(server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/libuv)
target_include_directories(server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/libuv/src)
target_include_directories(server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/uWebSockets/uSockets)
target_include_directories(server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Common)
target_include_directories(server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/)
target_compile_options(server PRIVATE "-D__GITHASH=${GLOBALGITHASH}")
target_compile_options(server PRIVATE "-DLIBUS_NO_SSL")

if(WIN32)
target_link_libraries(server Shlwapi.lib)
target_link_libraries(server ws2_32.lib)
target_link_libraries(server Userenv.lib)
target_link_libraries(server psapi.lib)
target_link_libraries(server Iphlpapi.lib)
endif(WIN32)

set_target_properties(server
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Output"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}/Output"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}/Output"
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Output"

OUTPUT_NAME "amc_server_next"

VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/Output"

)
8 changes: 8 additions & 0 deletions Framework/HeadersCore/CppDynamic/libmc_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ typedef void * LibMC_pvoid;
#define LIBMC_ERROR_MACHINEINSTANCENOTFOUND 403
#define LIBMC_ERROR_COULDNOTGETTEMPPATHFROMWINDOWS 404
#define LIBMC_ERROR_DUPLICATEBUTTONNAME 405
#define LIBMC_ERROR_SERVERCONFIGURATIONNOTLOADED 406
#define LIBMC_ERROR_COULDNOTPARSESERVERCONFIGURATION 407
#define LIBMC_ERROR_MISSINGSERVERCONFIGURATIONNODE 408
#define LIBMC_ERROR_COULDNOTFINDLIBRARYENTRY 409

/*************************************************************************************************************************
Error strings for LibMC
Expand Down Expand Up @@ -772,6 +776,10 @@ inline const char * LIBMC_GETERRORSTRING (LibMCResult nErrorCode) {
case LIBMC_ERROR_MACHINEINSTANCENOTFOUND: return "Machine instance not found";
case LIBMC_ERROR_COULDNOTGETTEMPPATHFROMWINDOWS: return "Could not get temp path from Windows";
case LIBMC_ERROR_DUPLICATEBUTTONNAME: return "Duplicate button name";
case LIBMC_ERROR_SERVERCONFIGURATIONNOTLOADED: return "Server configuration not loaded";
case LIBMC_ERROR_COULDNOTPARSESERVERCONFIGURATION: return "Could not pars server configuration";
case LIBMC_ERROR_MISSINGSERVERCONFIGURATIONNODE: return "Missing server configuration node";
case LIBMC_ERROR_COULDNOTFINDLIBRARYENTRY: return "Could not find library entry";
default: return "unknown error";
}
}
Expand Down
8 changes: 8 additions & 0 deletions Framework/InterfacesCore/libmc_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ typedef void * LibMC_pvoid;
#define LIBMC_ERROR_MACHINEINSTANCENOTFOUND 403
#define LIBMC_ERROR_COULDNOTGETTEMPPATHFROMWINDOWS 404
#define LIBMC_ERROR_DUPLICATEBUTTONNAME 405
#define LIBMC_ERROR_SERVERCONFIGURATIONNOTLOADED 406
#define LIBMC_ERROR_COULDNOTPARSESERVERCONFIGURATION 407
#define LIBMC_ERROR_MISSINGSERVERCONFIGURATIONNODE 408
#define LIBMC_ERROR_COULDNOTFINDLIBRARYENTRY 409

/*************************************************************************************************************************
Error strings for LibMC
Expand Down Expand Up @@ -772,6 +776,10 @@ inline const char * LIBMC_GETERRORSTRING (LibMCResult nErrorCode) {
case LIBMC_ERROR_MACHINEINSTANCENOTFOUND: return "Machine instance not found";
case LIBMC_ERROR_COULDNOTGETTEMPPATHFROMWINDOWS: return "Could not get temp path from Windows";
case LIBMC_ERROR_DUPLICATEBUTTONNAME: return "Duplicate button name";
case LIBMC_ERROR_SERVERCONFIGURATIONNOTLOADED: return "Server configuration not loaded";
case LIBMC_ERROR_COULDNOTPARSESERVERCONFIGURATION: return "Could not pars server configuration";
case LIBMC_ERROR_MISSINGSERVERCONFIGURATIONNODE: return "Missing server configuration node";
case LIBMC_ERROR_COULDNOTFINDLIBRARYENTRY: return "Could not find library entry";
default: return "unknown error";
}
}
Expand Down
117 changes: 117 additions & 0 deletions Implementation/Common/common_guid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*++
Copyright (C) 2020 Autodesk Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Autodesk Inc. nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL AUTODESK INC. BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#include <string>

#include "crossguid/guid.hpp"
#include "PicoSHA2/picosha2.h"
#include "common_utils.hpp"

#define LIBMC_MAXRANDOMSTRINGITERATIONS 1024

namespace AMCCommon {


#ifdef _WASM
xg::Guid xg::newGuid()
{
std::array<unsigned char, 16> bytes;
for (int index = 0; index < 16; index++) {
bytes[index] = rand() % 256;
}
return xg::Guid{ std::move(bytes) };

}
#endif //_WASM

std::string CUtils::createUUID()
{
auto guid = xg::newGuid();
return normalizeUUIDString(guid.str());
}



std::string CUtils::calculateRandomSHA256String(const uint32_t nIterations)
{
if ((nIterations == 0) || (nIterations > LIBMC_MAXRANDOMSTRINGITERATIONS))
throw std::runtime_error("invalid random string iterations");

std::string sRandomString;

uint32_t nCount = nIterations + (((uint32_t)rand()) % nIterations);
for (uint32_t nIndex = 0; nIndex < nCount; nIndex++)
sRandomString += createUUID();

return calculateSHA256FromString(sRandomString);
}


// Returns a UUID, such that sBasePath/sPrefixUUID.extension does not exist.
// Tries out maximum nMaxIterations different random uuids.
std::string CUtils::findTemporaryFileName(const std::string& sBasePath, const std::string& sPrefix, const std::string& sExtension, const uint32_t nMaxIterations)
{
if (sBasePath.empty())
throw std::runtime_error("empty temporary file base path");

std::string sBasePathWithDelimiter = sBasePath;
std::string sExtensionWithPoint;

if (!sExtension.empty()) {
if (sExtension.at(0) != '.') {
sExtensionWithPoint = "." + sExtension;
}
else {
sExtensionWithPoint = sExtension;
}

}

char lastChar = sBasePathWithDelimiter.at(sBasePathWithDelimiter.length() - 1);
if ((lastChar != '/') && (lastChar != '\\'))
sBasePathWithDelimiter += "/";

for (uint32_t nIndex = 0; nIndex < nMaxIterations; nIndex++) {
std::string sUUID = createUUID();
std::string sFullPath = sBasePathWithDelimiter + sPrefix + sUUID + sExtensionWithPoint;

if (!fileOrPathExistsOnDisk(sFullPath))
return sFullPath;

}

throw std::runtime_error("could not create temporary file path");

}



}
16 changes: 16 additions & 0 deletions Implementation/Common/common_importstream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define __AMCCOMMON_IMPORTSTREAM

#include <vector>
#include <string>
#include <memory>

namespace AMCCommon {
Expand Down Expand Up @@ -67,6 +68,21 @@ namespace AMCCommon {
readBuffer (Buffer.data(), nSize, true);
}
}

virtual std::string readAsString()
{
std::vector<uint8_t> Buffer;
uint64_t nSize = retrieveSize();
Buffer.resize(nSize + 1);
if (nSize > 0) {
seekPosition(0, true);
readBuffer(Buffer.data(), nSize, true);
}

Buffer[nSize] = 0;
return (char*) Buffer.data();
}

};

}
Expand Down
Loading

0 comments on commit 88d6419

Please sign in to comment.