CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
build/modules/add_boost.cmake | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
build/win/README.txt | 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/api/datatypes.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/base/base.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/base/logger.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/base/logger.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/os/os.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/os/win/os-win.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/pc-identifiers.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/functional/volid_test.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
CMakeLists.txt
@@ -30,10 +30,17 @@ endif(CMAKE_BUILD_TYPE) if(WIN32) SET(PLATFORM_LIBS "") if(CMAKE_CL_64) SET(CMAKE_EXE_LINKER_FLAGS "/machine:X64 /INCREMENTAL:NO" CACHE STRING "Linker flags") endif(CMAKE_CL_64) include(target_arch) target_architecture( TARGET_ARCHITECTURE ) message(STATUS "architecture detected: ${TARGET_ARCHITECTURE}") #force to patch an error in cmake if(TARGET_ARCHITECTURE STREQUAL "x86_64") SET(CMAKE_EXE_LINKER_FLAGS "/machine:X64" CACHE STRING "Linker flags" FORCE) SET(CMAKE_MODULE_LINKER_FLAGS "/machine:X64" CACHE STRING "Module Linker flags" FORCE) SET(CMAKE_SHARED_LINKER_FLAGS "/machine:X64" CACHE STRING "Shared Linker flags" FORCE) endif() SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib ) #${CMAKE_FIND_LIBRARY_SUFFIXES} add_definitions("/D_CRT_SECURE_NO_WARNINGS") else(WIN32) build/modules/add_boost.cmake
@@ -158,7 +158,6 @@ endif() execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${BOOST_ROOT}/Build) #ADD_BOOST_STATIC_RUNTIME is a parsed function parameter if(ADD_BOOST_STATIC_RUNTIME) set(RUNTIME_LINK "static") @@ -259,10 +258,13 @@ else(MSVC) set(OUTPUT_FILE ${BOOST_ROOT}/stage/lib/libboost_${libName}-mt${BOOST_LIB_SUFFIX}.${LINUX_LIB_EXTENSION}) endif(MSVC) if(NOT EXISTS "${OUTPUT_FILE}") message(STATUS "Building ${Component}") execute_process(COMMAND ${b2Args} --with-${Component} WORKING_DIRECTORY ${BOOST_ROOT}) #if(NOT EXISTS "${OUTPUT_FILE}") message(STATUS "Building ${Component}: ${b2Args}") execute_process(COMMAND ${b2Args} --with-${Component} WORKING_DIRECTORY ${BOOST_ROOT} RESULT_VARIABLE Result OUTPUT_VARIABLE Output ERROR_VARIABLE Error) if(NOT Result EQUAL 0) message(ERROR "Failed running ${b2Args} --with-${Component}:\n${Output}\n${Error}\n") endif() #endif() endforeach() build/win/README.txt
src/library/api/datatypes.h
@@ -11,9 +11,10 @@ extern "C" { #endif #include <stdbool.h> //definition of size_t #include <stdlib.h> #ifdef __unix__ #include <stdbool.h> #define DllExport #else #include <windows.h> @@ -61,7 +62,8 @@ typedef struct { const char *licenseFileLocation; const char *environmentVariableName;bool openFileNearModule; const char *environmentVariableName; bool openFileNearModule; } LicenseLocation; typedef struct { src/library/base/base.h
@@ -7,7 +7,6 @@ #endif #ifdef __unix__ #include <limits.h> #define DllExport #ifndef MAX_PATH @@ -17,8 +16,14 @@ #else //windows #include <windows.h> #define DllExport __declspec( dllexport ) #ifndef __cplusplus typedef int bool; #define false 0 #define true -1 #endif #endif /* #define _DEBUG */ /* #define cmax(a,b) \ src/library/base/logger.c
@@ -4,8 +4,9 @@ #include <string.h> #include <stdarg.h> #include <time.h> #include <unistd.h> #ifdef __unix__ #include <unistd.h> #define MAX_PATH 255 #else #include <windows.h> src/library/base/logger.h
@@ -2,6 +2,9 @@ #define logger_INCLUDED #ifndef LOG_ENABLED #include <errno.h> #define clean_errno() (errno == 0 ? "None" : strerror(errno)) #ifdef NDEBUG #define LOG_DEBUG(M, ...) _log("[INFO] %s (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__) #else src/library/os/os.h
@@ -14,14 +14,18 @@ #include "../base/base.h" #include <stddef.h> //definition of size_t #include <stdlib.h> #ifdef __unix__ #include <stdbool.h> #endif typedef enum { NONE, VMWARE } VIRTUALIZATION; typedef enum { ETHERNET, WIRELESS IFACE_TYPE_ETHERNET, IFACE_TYPE_WIRELESS } IFACE_TYPE; typedef struct { src/library/os/win/os-win.c
@@ -1,22 +1,30 @@ #include <Windows.h> #include <iphlpapi.h> //definition of size_t #include <stdlib.h> #include "../../base/logger.h" #include"../os.h" #pragma comment(lib, "IPHLPAPI.lib") FUNCTION_RETURN getOsSpecificIdentifier(unsigned char identifier[6]){ return FUNC_RET_NOT_AVAIL; } FUNCTION_RETURN getMachineName(unsigned char identifier[6]) { FUNCTION_RETURN result = FUNC_RET_ERROR; char buffer[MAX_COMPUTERNAME_LENGTH + 1]; int bufsize = MAX_COMPUTERNAME_LENGTH + 1; BOOL cmpName = GetComputerName( buffer, &bufsize); if (cmpName){ strncpy(identifier, buffer, 6); result = FUNC_RET_OK; } return result; } FUNCTION_RETURN getCpuId(unsigned char identifier[6]) { return FUNC_RET_NOT_AVAIL; } void os_initialize() { @@ -30,6 +38,7 @@ int ndrives = 0; DWORD FileFlags; char volName[_MAX_FNAME], FileSysName[_MAX_FNAME]; char* szSingleDrive; DWORD volSerial = 0; BOOL success; UINT driveType; @@ -42,7 +51,7 @@ if (dwResult > 0 && dwResult <= MAX_PATH) { return_value = FUNC_RET_OK; char* szSingleDrive = szLogicalDrives; szSingleDrive = szLogicalDrives; while (*szSingleDrive && ndrives < MAX_UNITS) { @@ -140,6 +149,7 @@ strncpy(adapterInfos[i].description, pAdapter->Description, min(sizeof(adapterInfos->description), MAX_ADAPTER_DESCRIPTION_LENGTH)); memcpy(adapterInfos[i].mac_address, pAdapter->Address, 8); translate(pAdapter->IpAddressList.IpAddress.String, adapterInfos[i].ipv4_address); adapterInfos[i].type = IFACE_TYPE_ETHERNET; i++; pAdapter = pAdapter->Next; if (i == *adapter_info_size){ src/library/pc-identifiers.c
@@ -9,17 +9,20 @@ #include "pc-identifiers.h" #include <stdlib.h> #include <string.h> #include <stdbool.h> #include "base/base64.h" #include "base/base.h" #ifdef __linux__ #include <stdbool.h> #include <valgrind/memcheck.h> #else #include <Windows.h> #endif static FUNCTION_RETURN generate_default_pc_id(PcIdentifier * identifiers, unsigned int * num_identifiers) { size_t adapter_num, disk_num; FUNCTION_RETURN result_adapterInfos, result_diskinfos; unsigned int required_id_size, i, j, k; unsigned int required_id_size, defined_identifiers, i, j, k; DiskInfo * diskInfos; OsAdapterInfo *adapterInfos; @@ -34,7 +37,7 @@ } else { required_id_size = disk_num; } int defined_identifiers = *num_identifiers; defined_identifiers = *num_identifiers; *num_identifiers = required_id_size; if (identifiers == NULL) { return FUNC_RET_OK; @@ -60,8 +63,9 @@ } static FUNCTION_RETURN generate_ethernet_pc_id(PcIdentifier * identifiers, unsigned int * num_identifiers, bool use_mac) { unsigned int * num_identifiers, int use_mac) { size_t adapters; int defined_adapters; FUNCTION_RETURN result_adapterInfos; unsigned int i, j, k; OsAdapterInfo *adapterInfos; @@ -71,7 +75,7 @@ return result_adapterInfos; } int defined_adapters = *num_identifiers; defined_adapters = *num_identifiers; *num_identifiers = adapters; if (identifiers == NULL) { return FUNC_RET_OK; @@ -104,6 +108,7 @@ size_t disk_num, available_disk_info=0; FUNCTION_RETURN result_diskinfos; unsigned int i, k, j; int defined_identifiers; char firstChar; DiskInfo * diskInfos; @@ -123,7 +128,7 @@ available_disk_info += firstChar == 0 ? 0 : 1; } int defined_identifiers = *num_identifiers; defined_identifiers = *num_identifiers; *num_identifiers = available_disk_info; if (identifiers == NULL) { free(diskInfos); @@ -167,6 +172,7 @@ * @param * @return */ FUNCTION_RETURN generate_pc_id(PcIdentifier * identifiers, unsigned int * array_size, IDENTIFICATION_STRATEGY strategy) { FUNCTION_RETURN result; @@ -237,12 +243,13 @@ PcSignature pc_identifier_out) { //TODO base62 encoding, now uses base64 PcIdentifier concat_identifiers[2]; char* b64_data; int b64_size = 0; size_t concatIdentifiersSize = sizeof(PcIdentifier) * 2; //concat_identifiers = (PcIdentifier *) malloc(concatIdentifiersSize); memcpy(&concat_identifiers[0], identifier1, sizeof(PcIdentifier)); memcpy(&concat_identifiers[1], identifier2, sizeof(PcIdentifier)); char* b64_data = base64(concat_identifiers, concatIdentifiersSize, b64_data = base64(concat_identifiers, concatIdentifiersSize, &b64_size); if (b64_size > sizeof(PcSignature)) { return FUNC_RET_BUFFER_TOO_SMALL; test/functional/volid_test.cpp
@@ -46,7 +46,7 @@ for (int i = 0; i < num_strategies; i++) { FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out, strategies[i]); BOOST_ASSERT(generate_ok == FUNCTION_RETURN::FUNC_RET_OK); BOOST_ASSERT(generate_ok == FUNC_RET_OK); idfile << identifier_out << endl; } idfile.close(); @@ -55,10 +55,10 @@ BOOST_AUTO_TEST_CASE(generated_identifiers_stability) { const string idfileLocation(PROJECT_TEST_TEMP_DIR "/identifiers_file"); IDENTIFICATION_STRATEGY strategies[] = { IDENTIFICATION_STRATEGY::DEFAULT, IDENTIFICATION_STRATEGY::DISK_LABEL, IDENTIFICATION_STRATEGY::DISK_NUM, IDENTIFICATION_STRATEGY::ETHERNET }; { DEFAULT, DISK_LABEL, DISK_NUM, ETHERNET }; const int num_strategies = sizeof(strategies) / sizeof(strategies[0]); std::ifstream test_idfile_exist(idfileLocation); if (!test_idfile_exist.good()) { @@ -76,7 +76,7 @@ BOOST_ASSERT(generate_ok == FUNCTION_RETURN::FUNC_RET_OK); if (reference_signatures[i] != generated_identifier) { string message = string("pc signature compare fail: strategy:") + to_string(strategies[i]) + " generated: [" + to_string((long double) strategies[i]) + " generated: [" + generated_identifier + "] reference: [" + reference_signatures[i] + "]"; BOOST_FAIL(message);