From 510d41ff7d12c8a8ba230d3b3f732b19a20f15e3 Mon Sep 17 00:00:00 2001 From: gcontini <1121667+gcontini@users.noreply.github.com> Date: 周六, 31 10月 2020 10:28:34 +0800 Subject: [PATCH] doc & miscellaneous changes --- doc/api/hardware_identifiers.rst | 19 ++++++++++++++++--- doc/api/extend.rst | 2 +- src/library/os/windows/execution_environment.cpp | 3 ++- src/library/base/file_utils.cpp | 11 +++++++---- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/doc/api/extend.rst b/doc/api/extend.rst index ed77174..2521a92 100644 --- a/doc/api/extend.rst +++ b/doc/api/extend.rst @@ -43,4 +43,4 @@ .. TODO:: - this section need to be completed \ No newline at end of file + this section need to be completed diff --git a/doc/api/hardware_identifiers.rst b/doc/api/hardware_identifiers.rst index 4c41395..840c520 100644 --- a/doc/api/hardware_identifiers.rst +++ b/doc/api/hardware_identifiers.rst @@ -2,10 +2,23 @@ Customize hardware signature generators ############################################### -Customize how default strategy behaves -***************************************** +Change the hardware identification strategy +************************************************* + +Included with the library there are three hardware identification strategies: `IP_ADDRESS`, `STRATEGY_ETHERNET` (mac address) and +`STRATEGY_DISK` (partition serial number). If you want to change the strategy that is used to generate the default identifier: + + - locate the file `licensecc_properties.h`` (usually in ``projects/<$project_name>/include/licensecc/<$project_name>`` + - you can change the order of the strategies in the following code block (the strategies will be tried in sequence until the first one succeeds): + +.. code-block:: c +#define LCC_BARE_TO_METAL_STRATEGIES { STRATEGY_DISK, STRATEGY_ETHERNET, STRATEGY_NONE } +#define LCC_VM_STRATEGIES { STRATEGY_ETHERNET, STRATEGY_NONE } +#define LCC_LXC_STRATEGIES { STRATEGY_ETHERNET, STRATEGY_NONE } +#define LCC_DOCKER_STRATEGIES { STRATEGY_NONE } +#define LCC_CLOUD_STRATEGIES { STRATEGY_NONE } Implement your own hardware signature generator ************************************************* -.. doxygenclass:: license::hw_identifier::IdentificationStrategy \ No newline at end of file +.. doxygenclass:: license::hw_identifier::IdentificationStrategy diff --git a/src/library/base/file_utils.cpp b/src/library/base/file_utils.cpp index 9d46b90..836f78d 100644 --- a/src/library/base/file_utils.cpp +++ b/src/library/base/file_utils.cpp @@ -10,7 +10,8 @@ #include <cerrno> #include <iostream> #include <algorithm> - +#include <errno.h> +#include <cstring> #include "file_utils.hpp" namespace license { @@ -34,17 +35,19 @@ } string get_file_contents(const char *filename, size_t max_size) { + string contents; ifstream in(filename, std::ios::binary); if (in) { - string contents; size_t index = (size_t)in.seekg(0, ios::end).tellg(); size_t limited_size = min(index, max_size); contents.resize(limited_size); in.seekg(0, ios::beg); in.read(&contents[0], limited_size); - return contents; + in.close(); + } else { + throw(std::strerror(errno)); } - throw(errno); + return contents; } string remove_extension(const string& path) { diff --git a/src/library/os/windows/execution_environment.cpp b/src/library/os/windows/execution_environment.cpp index 50a255e..d080931 100644 --- a/src/library/os/windows/execution_environment.cpp +++ b/src/library/os/windows/execution_environment.cpp @@ -20,7 +20,8 @@ namespace os { using namespace std; -ExecutionEnvironment::ExecutionEnvironment() : m_container_type(CONTAINER_TYPE::NONE) {} +ExecutionEnvironment::ExecutionEnvironment() : + m_container_type(CONTAINER_TYPE::NONE) {} #define MAX_UNITS 20 CONTAINER_TYPE wine_container() { -- Gitblit v1.9.1