CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
build/modules/add_boost.cmake | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
build/modules/utilities.cmake | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
build/win64/init.bat | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/os/os.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/os/win/os-win.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/license-generator/CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/license-generator/win/LicenseSigner.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/functional/CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/functional/volid_test.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/library/CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/license-generator/CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
CMakeLists.txt
@@ -17,14 +17,17 @@ SET(CMAKE_DISABLE_IN_SOURCE_BUILD ON) SET(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "CMake verbose" FORCE) project (license++ C CXX) SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/build/modules/") include(utilities) if(CMAKE_BUILD_TYPE) string(TOLOWER ${CMAKE_BUILD_TYPE} _CMAKE_BUILD_TYPE) EVAL_CONDITION(RELEASE_BUILD ${_CMAKE_BUILD_TYPE} STREQUAL "release") else(CMAKE_BUILD_TYPE) set(RELEASE_BUILD 0) endif(CMAKE_BUILD_TYPE) if(WIN32) SET(PLATFORM_LIBS "") @@ -38,8 +41,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -fmessage-length=0 -Wall -Wuninitialized -fPIC") #use static libraries in release to make it easier to distribute it #SET(Boost_USE_STATIC_RUNTIME ${RELEASE_BUILD}) SET(Boost_USE_STATIC_LIBS ${RELEASE_BUILD}) if(${RELEASE_BUILD}) if(RELEASE_BUILD) SET(CMAKE_FIND_LIBRARY_SUFFIXES .a) #.so for dynamic libraries else() SET(CMAKE_FIND_LIBRARY_SUFFIXES .a .so) @@ -51,9 +53,7 @@ SET(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Install path prefix" FORCE) ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) endif(WIN32) #TODO uncomment: source temporarily broken set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:_DEBUG>) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:BOOST_TEST_DYN_LINK>) if(CMAKE_SIZEOF_VOID_P EQUAL 8) @@ -62,15 +62,12 @@ SET(HAVE_64BIT_SIZE_T 0) endif(CMAKE_SIZEOF_VOID_P EQUAL 8) #TODO: determine target arch. SET( TargetArchitecture "X86_64") include(add_boost) # static runtime requires /MT #SET(Boost_USE_MULTITHREADED ON) #SET(Boost_USE_STATIC_RUNTIME OFF) #find_package(Boost COMPONENTS thread date_time program_options filesystem system regex unit_test_framework) #find_package(Boost COMPONENTS date_time program_options filesystem system unit_test_framework) add_boost(STATIC MODULES date_time test program_options system filesystem) #set below in case of dynamic linking in debug. #set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:BOOST_TEST_DYN_LINK>) add_definitions(-DBOOST_ALL_NO_LIB) #Disable Boost Microsoft magic, all dependencies are handled by cmake add_definitions(-DBOOST_LIB_DIAGNOSTIC) #Check it is really disabled if(NOT WIN32) #find a static version of openssl crypto library build/modules/add_boost.cmake
@@ -1,24 +1,29 @@ # Boost_INCLUDE_DIRS - Boost include directories # Boost_LIBRARY_DIRS - Link directories for Boost libraries #usage add_boost( [STATIC] , # [STATIC_RUNTIME], # [USE_BOOST_CACHE], #If user wants to use a cache copy of Boost, get the path to this location. # [BOOST_CACHE_DIR path], # [TARGET_ARCHITECHTURE_32], # [MODULES module1, module2] ) #This module will set the following variables # Boost_INCLUDE_DIR - Boost include directories # Boost_LIBRARY_DIR - Link directories for Boost libraries # Boost_LIBRARIES - Boost component libraries to be linked #FIXME: for boost find compatibility C must be upper case # Boost_<C>_LIBRARY - Libraries to link for component <C> (c is lower-case,may include # target_link_libraries debug/optimized keywords) function(ms_underscores_to_camel_case VarIn VarOut) string(REPLACE "_" ";" Pieces ${VarIn}) foreach(Part ${Pieces}) string(SUBSTRING ${Part} 0 1 Initial) string(SUBSTRING ${Part} 1 -1 Part) string(TOUPPER ${Initial} Initial) set(CamelCase ${CamelCase}${Initial}${Part}) endforeach() set(${VarOut} ${CamelCase} PARENT_SCOPE) endfunction() include (CMakeParseArguments) function(add_boost) set(BoostVersion 1.55.0) set(BoostSHA1 cef9a0cc7084b1d639e06cd3bc34e4251524c840) set(options STATIC STATIC_RUNTIME USE_BOOST_CACHE TARGET_ARCHITECHTURE_32) set(oneValueArgs BOOST_CACHE_DIR) set(multiValueArgs MODULES) cmake_parse_arguments(ADD_BOOST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) # Create build folder name derived from version string(REGEX REPLACE "beta\\.([0-9])$" "beta\\1" BoostFolderName ${BoostVersion}) @@ -26,8 +31,9 @@ set(BoostFolderName boost_${BoostFolderName}) # If user wants to use a cache copy of Boost, get the path to this location. if(USE_BOOST_CACHE) if(BOOST_CACHE_DIR) #ADD_BOOST_USE_BOOST_CACHE is a parsed command line parameter if(ADD_BOOST_USE_BOOST_CACHE) if(ADD_BOOST_BOOST_CACHE_DIR) file(TO_CMAKE_PATH "${BOOST_CACHE_DIR}" BoostCacheDir) elseif(WIN32) ms_get_temp_dir() @@ -41,14 +47,14 @@ # If the cache directory doesn't exist, fall back to use the build root. if(NOT IS_DIRECTORY "${BoostCacheDir}") if(BOOST_CACHE_DIR) set(Message "\nThe directory \"${BOOST_CACHE_DIR}\" provided in BOOST_CACHE_DIR doesn't exist.") if(ADD_BOOST_BOOST_CACHE_DIR) set(Message "\nThe directory \"${ADD_BOOST_BOOST_CACHE_DIR}\" provided in BOOST_CACHE_DIR doesn't exist.") set(Message "${Message} Falling back to default path at \"${CMAKE_BINARY_DIR}/license++\"\n") message(WARNING "${Message}") endif() set(BoostCacheDir ${CMAKE_BINARY_DIR}) else() if(NOT USE_BOOST_CACHE AND NOT BOOST_CACHE_DIR) if(NOT ADD_BOOST_USE_BOOST_CACHE AND NOT ADD_BOOST_BOOST_CACHE_DIR) set(BoostCacheDir "${BoostCacheDir}/license++") endif() file(MAKE_DIRECTORY "${BoostCacheDir}") @@ -66,18 +72,18 @@ set(BoostSourceDir "${BoostSourceDir}_Win64") endif() string(REPLACE "." "_" BoostSourceDir ${BoostSourceDir}) set(BoostSourceDir "${BoostCacheDir}/${BoostSourceDir}") set(BOOST_ROOT "${BoostCacheDir}/${BoostSourceDir}" CACHE PATH "BOOST base dir") # Check the full path to the source directory is not too long for Windows. File paths must be less # than MAX_PATH which is 260. The current longest relative path Boost tries to create is: # Build\boost\bin.v2\libs\program_options\build\fd41f4c7d882e24faa6837508d6e5384\libboost_program_options-vc120-mt-gd-1_55.lib.rsp # which along with a leading separator is 129 chars in length. This gives a maximum path available # for 'BoostSourceDir' as 130 chars. # for 'BOOST_ROOT' as 130 chars. if(WIN32) get_filename_component(BoostSourceDirName "${BoostSourceDir}" NAME) get_filename_component(BoostSourceDirName "${BOOST_ROOT}" NAME) string(LENGTH "/${BoostSourceDirName}" BoostSourceDirNameLengthWithSeparator) math(EXPR AvailableLength 130-${BoostSourceDirNameLengthWithSeparator}) string(LENGTH "${BoostSourceDir}" BoostSourceDirLength) string(LENGTH "${BOOST_ROOT}" BoostSourceDirLength) if(${BoostSourceDirLength} GREATER 130) set(Msg "\n\nThe path to boost's source is too long to handle all the files which will ") set(Msg "${Msg}be created when boost is built. To avoid this, set the CMake variable ") @@ -103,7 +109,7 @@ # Extract boost if required string(FIND "${Status}" "returning early" Found) if(Found LESS 0 OR NOT IS_DIRECTORY "${BoostSourceDir}") if(Found LESS 0 OR NOT IS_DIRECTORY "${BOOST_ROOT}") set(BoostExtractFolder "${BoostCacheDir}/boost_unzip") file(REMOVE_RECURSE ${BoostExtractFolder}) file(MAKE_DIRECTORY ${BoostExtractFolder}) @@ -124,14 +130,13 @@ if(NOT n EQUAL 1 OR NOT IS_DIRECTORY ${ExtractedDir}) message(FATAL_ERROR "Failed extracting boost ${BoostVersion} to ${BoostExtractFolder}") endif() file(RENAME ${ExtractedDir} ${BoostSourceDir}) file(RENAME ${ExtractedDir} ${BOOST_ROOT}) file(REMOVE_RECURSE ${BoostExtractFolder}) endif() # Build b2 (bjam) if required unset(b2Path CACHE) find_program(b2Path NAMES b2 PATHS ${BoostSourceDir} NO_DEFAULT_PATH) find_program(b2Path NAMES b2 PATHS ${BOOST_ROOT} NO_DEFAULT_PATH) if(NOT b2Path) message(STATUS "Building b2 (bjam)") if(MSVC) @@ -144,32 +149,38 @@ list(APPEND b2Bootstrap --with-toolset=gcc) endif() endif() execute_process(COMMAND ${b2Bootstrap} WORKING_DIRECTORY ${BoostSourceDir} execute_process(COMMAND ${b2Bootstrap} WORKING_DIRECTORY ${BOOST_ROOT} RESULT_VARIABLE Result OUTPUT_VARIABLE Output ERROR_VARIABLE Error) if(NOT Result EQUAL 0) message(FATAL_ERROR "Failed running ${b2Bootstrap}:\n${Output}\n${Error}\n") endif() endif() execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${BoostSourceDir}/Build) execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${BOOST_ROOT}/Build) # Expose BoostSourceDir to parent scope #set(BoostSourceDir ${BoostSourceDir} ) #PARENT_SCOPE if(Boost_USE_STATIC_RUNTIME) #ADD_BOOST_STATIC_RUNTIME is a parsed function parameter if(ADD_BOOST_STATIC_RUNTIME) set(RUNTIME_LINK "static") set(BOOST_LIB_SUFFIX "-s") set(Boost_USE_STATIC_RUNTIME ON) else() set(RUNTIME_LINK "shared") set(BOOST_LIB_SUFFIX "") set(Boost_USE_STATIC_RUNTIME OFF) endif() if(Boost_USE_STATIC_LIBS) #ADD_BOOST_STATIC is a parsed function parameter if(ADD_BOOST_STATIC) set(BOOST_LINK "static") set(BOOST_LIB_EXTENSION "a") else() set(LINUX_LIB_EXTENSION "a") set(WINDOWS_LIB_PREFIX "lib") set(Boost_USE_STATIC_LIBS ON) else(ADD_BOOST_STATIC) set(BOOST_LINK "shared") set(BOOST_LIB_EXTENSION "so") endif() set(LINUX_LIB_EXTENSION "so") set(WINDOWS_LIB_PREFIX "") set(Boost_USE_STATIC_LIBS OFF) endif(ADD_BOOST_STATIC) message(STATUS "Boost linking: libs ${BOOST_LINK} , C++ runtime ${RUNTIME_LINK}") # Set up general b2 (bjam) command line arguments set(b2Args ./b2 link=${BOOST_LINK} @@ -199,7 +210,8 @@ define=_BIND_TO_CURRENT_CRT_VERSION=1 --layout=versioned ) if("${TargetArchitecture}" STREQUAL "x86_64") #command line parameter if(NOT ADD_BOOST_TARGET_ARCHITECHTURE_32) list(APPEND b2Args address-model=64) endif() elseif(APPLE) @@ -219,25 +231,19 @@ endif() endif() # Get list of components execute_process(COMMAND ./b2 --show-libraries WORKING_DIRECTORY ${BoostSourceDir} ERROR_QUIET OUTPUT_VARIABLE Output) string(REGEX REPLACE "(^[^:]+:|[- ])" "" BoostComponents "${Output}") string(REGEX REPLACE "\n" ";" BoostComponents "${BoostComponents}") if(NOT ADD_BOOST_MODULES) set (ADD_BOOST_MODULES atomic chrono context coroutine date_time exception filesystem graph iostreams log math program_options python random regex signals system test thread timer wave) endif() # Build each required component include(ExternalProject) foreach(Component ${BoostComponents}) ms_underscores_to_camel_case(${Component} CamelCaseComponent) if(${Boost_USE_STATIC_LIBS}) add_library(boost_${Component} STATIC IMPORTED GLOBAL) else(${Boost_USE_STATIC_LIBS}) add_library(boost_${Component} SHARED IMPORTED GLOBAL) endif(${Boost_USE_STATIC_LIBS}) foreach(Component ${ADD_BOOST_MODULES}) if(${Component} STREQUAL "test") set(LibName "unit_test_framework") set(libName "unit_test_framework") elseif(${Component} STREQUAL "math") set(libName "math_c99l") else() set(LibName ${Component}) set(libName ${Component}) endif() if(MSVC) if(MSVC11) @@ -245,90 +251,42 @@ elseif(MSVC12) set(CompilerName vc120) endif() ExternalProject_Add( Boost${CamelCaseComponent} PREFIX ${CMAKE_BINARY_DIR}/${BoostFolderName} SOURCE_DIR ${BoostSourceDir} BINARY_DIR ${BoostSourceDir} CONFIGURE_COMMAND "" BUILD_COMMAND "${b2Args}" --with-${Component} INSTALL_COMMAND "" LOG_BUILD ON ) string(REGEX MATCH "[0-9]_[0-9][0-9]" Version "${BoostFolderName}") set_target_properties(boost_${Component} PROPERTIES IMPORTED_LOCATION_DEBUG ${BoostSourceDir}/stage/lib/libboost_${Component}-${CompilerName}-mt-gd-${Version}.lib IMPORTED_LOCATION_MINSIZEREL ${BoostSourceDir}/stage/lib/libboost_${Component}-${CompilerName}-mt-${Version}.lib IMPORTED_LOCATION_RELEASE ${BoostSourceDir}/stage/lib/libboost_${Component}-${CompilerName}-mt-${Version}.lib IMPORTED_LOCATION_RELWITHDEBINFO ${BoostSourceDir}/stage/lib/libboost_${Component}-${CompilerName}-mt-${Version}.lib IMPORTED_LOCATION_RELEASENOINLINE ${BoostSourceDir}/stage/lib/libboost_${Component}-${CompilerName}-mt-${Version}.lib LINKER_LANGUAGE CXX) #http://www.boost.org/doc/libs/1_42_0/more/getting_started/windows.html#library-naming set(OUTPUT_FILE ${BOOST_ROOT}/stage/lib/${WINDOWS_LIB_PREFIX}boost_${libName}-${CompilerName}-mt-${Version}.lib) set(OUTPUT_FILE_DEBUG ${BOOST_ROOT}/stage/lib/${WINDOWS_LIB_PREFIX}boost_${libName}-${CompilerName}-mt-gd-${Version}.lib) else(MSVC) set(OUTPUT_FILE ${BoostSourceDir}/stage/lib/libboost_${LibName}-mt${BOOST_LIB_SUFFIX}.${BOOST_LIB_EXTENSION}) add_custom_command(OUTPUT ${OUTPUT_FILE} COMMAND ${b2Args} --with-${Component} WORKING_DIRECTORY ${BoostSourceDir} ) add_custom_target(Boost${CamelCaseComponent} DEPENDS ${OUTPUT_FILE} WORKING_DIRECTORY ${BoostSourceDir}) set_target_properties(boost_${Component} PROPERTIES IMPORTED_LOCATION ${OUTPUT_FILE} #LINK_SEARCH_START_STATIC OFF LINKER_LANGUAGE CXX ) set(OUTPUT_FILE ${BOOST_ROOT}/stage/lib/libboost_${libName}-mt${BOOST_LIB_SUFFIX}.${LINUX_LIB_EXTENSION}) endif(MSVC) set_target_properties(boost_${Component} Boost${CamelCaseComponent} PROPERTIES LABELS Boost FOLDER "Boost" EXCLUDE_FROM_ALL TRUE) add_dependencies(boost_${Component} Boost${CamelCaseComponent}) set(Boost_${Component}_LIBRARY boost_${Component}) if("${Component}" STREQUAL "locale") if(APPLE) find_library(IconvLib iconv) if(NOT IconvLib) message(FATAL_ERROR "libiconv.dylib must be installed to a standard location.") if(NOT EXISTS "${OUTPUT_FILE}") message(STATUS "Building ${Component}") execute_process(COMMAND ${b2Args} --with-${Component} WORKING_DIRECTORY ${BOOST_ROOT}) endif() set(Boost_${Component}_LIBRARY boost_${Component} ${IconvLib}) elseif(UNIX) if(BSD) find_library(IconvLib libiconv.a) if(NOT IconvLib) set(Msg "libiconv.a must be installed to a standard location.") set(Msg " For ${Msg} on FreeBSD 10 or later, run\n pkg install libiconv") message(FATAL_ERROR "${Msg}") endif() set(Boost_${Component}_LIBRARY boost_${Component} ${IconvLib}) else() find_library(Icui18nLib libicui18n.a) find_library(IcuucLib libicuuc.a) find_library(IcudataLib libicudata.a) if(NOT Icui18nLib OR NOT IcuucLib OR NOT IcudataLib) set(Msg "libicui18n.a, libicuuc.a & licudata.a must be installed to a standard location.") set(Msg " For ${Msg} on Ubuntu/Debian, run\n sudo apt-get install libicu-dev") message(FATAL_ERROR "${Msg}") endif() set(Boost_${Component}_LIBRARY boost_${Component} ${Icui18nLib} ${IcuucLib} ${IcudataLib}) endif() else() set(Boost_${Component}_LIBRARY boost_${Component}) endif() endif() #set(Boost${CamelCaseComponent}Libs ${Boost${CamelCaseComponent}Libs}) # PARENT_SCOPE list(APPEND Boost_LIBRARIES Boost_${Component}_LIBRARY) endforeach() #set(AllBoostLibs ${AllBoostLibs}) # PARENT_SCOPE add_dependencies(BoostChrono BoostSystem) add_dependencies(BoostCoroutine BoostContext BoostSystem) add_dependencies(BoostFilesystem BoostSystem) add_dependencies(BoostGraph BoostRegex) add_dependencies(BoostLocale BoostSystem) add_dependencies(BoostLog BoostChrono BoostDateTime BoostFilesystem BoostThread) add_dependencies(BoostThread BoostChrono) add_dependencies(BoostTimer BoostChrono) add_dependencies(BoostWave BoostChrono BoostDateTime BoostFilesystem BoostThread) set(Boost_INCLUDE_DIRS ${BoostSourceDir}) set(Boost_LIBRARY_DIRS ${BoostSourceDir}/stage/lib) LIST_REPLACE(ADD_BOOST_MODULES "test" "unit_test_framework") # BOOST_ROOT - Preferred installation prefix # (or BOOSTROOT) # BOOST_INCLUDEDIR - Preferred include directory e.g. <prefix>/include # BOOST_LIBRARYDIR - Preferred library directory e.g. <prefix>/lib # Boost_NO_SYSTEM_PATHS - Set to ON to disable searching in locations not # specified by these hint variables. Default is OFF. set (BOOST_LIBRARYDIR ${BoostSourceDir}/stage/lib CACHE PATH "BOOST library dir") #set (Boost_NO_SYSTEM_PATHS ON) find_package(Boost 1.55 REQUIRED COMPONENTS ${ADD_BOOST_MODULES}) #clean up variables mark_as_advanced (BOOST_ROOT BOOST_LIBRARYDIR) unset(b2Path CACHE) set(Boost_LIBRARIES ${Boost_LIBRARIES} PARENT_SCOPE) endfunction() macro(LIST_REPLACE LIST OLDVALUE NEWVALUE) list(FIND ADD_BOOST_MODULES ${OLDVALUE} find_idx) if(find_idx GREATER -1) list(INSERT ${LIST} ${find_idx} ${NEWVALUE}) MATH(EXPR __INDEX "${find_idx} + 1") list (REMOVE_AT ${LIST} ${__INDEX}) endif() endmacro(LIST_REPLACE) build/modules/utilities.cmake
@@ -6,3 +6,4 @@ SET(${name} 0) ENDIF(${ARGN}) ENDMACRO(EVAL_CONDITION) build/win64/init.bat
File was deleted src/library/os/os.h
@@ -20,12 +20,17 @@ NONE, VMWARE } VIRTUALIZATION; typedef enum { ETHERNET, WIRELESS } IFACE_TYPE; typedef struct { int id; char description[1024]; unsigned char mac_address[6]; unsigned char ipv4_address[4]; } AdapterInfo; IFACE_TYPE type; } OsAdapterInfo; typedef struct { int id; @@ -35,7 +40,7 @@ bool preferred; } DiskInfo; FUNCTION_RETURN getAdapterInfos(AdapterInfo * adapterInfos, FUNCTION_RETURN getAdapterInfos(OsAdapterInfo * adapterInfos, size_t * adapter_info_size); FUNCTION_RETURN getDiskInfos(DiskInfo * diskInfos, size_t * disk_info_size); FUNCTION_RETURN getUserHomePath(char[MAX_PATH]); src/library/os/win/os-win.c
@@ -1,4 +1,5 @@ #include <Windows.h> #include <iphlpapi.h> #include"../os.h" FUNCTION_RETURN getOsSpecificIdentifier(unsigned char identifier[6]){ @@ -23,6 +24,64 @@ FUNCTION_RETURN getDiskInfos(DiskInfo * diskInfos, size_t * disk_info_size) { } FUNCTION_RETURN getAdapterInfos(AdapterInfo * adapterInfos, size_t * adapter_info_size) { //http://stackoverflow.com/questions/18046063/mac-address-using-c //TODO: count only interfaces with type (MIB_IF_TYPE_ETHERNET IF_TYPE_IEEE80211) FUNCTION_RETURN getAdapterInfos(OsAdapterInfo * adapterInfos, size_t * adapter_info_size) { DWORD dwStatus; unsigned int i; PIP_ADAPTER_INFO pAdapterInfo, pAdapter = NULL; //IP_ADAPTER_INFO AdapterInfo[16]; // Allocate information for up to 16 NICs DWORD dwBufLen = 0; //sizeof(AdapterInfo); // Save the memory size of buffer dwStatus = GetAdaptersInfo( // Call GetAdapterInfo null,// [out] buffer to receive data &dwBufLen // [in] size of receive data buffer ); if (dwStatus != ERROR_BUFFER_OVERFLOW){ return FUNC_RET_ERROR; } if (adapterInfos == null || *adapter_info_size == 0){ *adapter_info_size = dwBufLen; return FUNC_RET_BUFFER_TOO_SMALL; } else { memset(adapterInfos, 0, adapter_info_size); pAdapterInfo = (IP_ADAPTER_INFO*)malloc(dwBufLen*sizeof(IP_ADAPTER_INFO)); dwStatus = GetAdaptersInfo(pAdapterInfo, &dwBufLen); if (dwStatus != NO_ERROR){ free(pAdapterInfo); return FUNC_RET_ERROR; } pAdapter = pAdapterInfo; for (i = 0; i < min(*adapter_info_size, dwBufLen); i++) { strncpy(adapterInfos[i].description, pAdapter->Description, min(sizeof(adapterInfos->description), MAX_ADAPTER_DESCRIPTION_LENGTH)); memcpy(adapterInfos[i].mac_address, pAdapter->Address, 8); memcpy(adapterInfos[i].ipv4_address, pAdapter->IpAddressList.IpAddress, 8); pAdapter = pAdapter->Next; } } #include <ctype.h> #include <stdio.h> int main(void) { char *str = "192.168.0.1", *str2; unsigned char value[4] = { 0 }; size_t index = 0; str2 = str; /* save the pointer */ while (*str) { if (isdigit((unsigned char)*str)) { value[index] *= 10; value[index] += *str - '0'; } else { index++; } str++; } printf("values in \"%s\": %d %d %d %d\n", str2, value[0], value[1], value[2], value[3]); return 0; } } src/license-generator/CMakeLists.txt
@@ -1,4 +1,8 @@ include_directories(${Boost_INCLUDE_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) link_directories ( ${Boost_LIBRARY_DIR} ) if(WIN32) ADD_LIBRARY( license_generator_lib STATIC @@ -13,15 +17,15 @@ ) endif(WIN32) #link_directories ( ${Boost_LIBRARY_DIRS} ) #add_dependencies( license_generator_lib boost_filesystem private_key ) target_link_libraries( license_generator_lib license++_static ${Boost_filesystem_LIBRARY} ${Boost_program_options_LIBRARY} ${Boost_system_LIBRARY} $<$<CONFIG:Debug>:${Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG}> $<$<NOT:$<CONFIG:Debug>>:${Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE}> $<$<CONFIG:Debug>:${Boost_SYSTEM_LIBRARY_DEBUG}> $<$<NOT:$<CONFIG:Debug>>:${Boost_SYSTEM_LIBRARY_RELEASE}> $<$<CONFIG:Debug>:${Boost_DATE_TIME_LIBRARY_DEBUG}> $<$<NOT:$<CONFIG:Debug>>:${Boost_DATE_TIME_LIBRARY_RELEASE}> ${EXTERNAL_LIBS} ) @@ -34,6 +38,7 @@ license_generator license_generator_lib ) add_dependencies( license_generator private_key ) #SET_TARGET_PROPERTIES(license_generator PROPERTIES LINK_SEARCH_START_STATIC ON) #SET_TARGET_PROPERTIES(license_generator PROPERTIES LINK_SEARCH_END_STATIC ON) src/license-generator/win/LicenseSigner.cpp
@@ -1,18 +1,14 @@ /* * LicenseSigner.cpp * LicenseSigner.cpp (Windows) * * Created on: Apr 6, 2014 * Author: devel */ #include "LicenseSigner.h" #include "private-key.h" #include "../LicenseSigner.h" #include "../private-key.h" #include <stdexcept> #include <string.h> #include <openssl/evp.h> #include <openssl/bio.h> #include <openssl/pem.h> #include <openssl/err.h> #include <iostream> #include <cmath> @@ -28,111 +24,12 @@ } string LicenseSigner::Opensslb64Encode(size_t slen, unsigned char* signature) { /* FILE* stream = fmemopen(*buffer, encodedSize+1, "w"); */ //bio = BIO_new_fp(stdout, BIO_NOCLOSE); /*int encodedSize = 4 * ceil(slen / 3); char* buffer = (char*) (malloc(encodedSize + 1)); memset(buffer,0,encodedSize+1);*/ BIO* mem_bio = BIO_new(BIO_s_mem()); BIO* b64 = BIO_new(BIO_f_base64()); BIO* bio1 = BIO_push(b64, mem_bio); BIO_set_flags(bio1, BIO_FLAGS_BASE64_NO_NL); BIO_write(bio1, signature, slen); BIO_flush(bio1); char* charBuf; int sz = BIO_get_mem_data(mem_bio, &charBuf); string signatureStr; signatureStr.assign(charBuf, sz); BIO_free_all(bio1); return signatureStr; return NULL; } string LicenseSigner::signString(const string& license) { size_t slen; unsigned char* signature; signature = NULL; /* Create the Message Digest Context */ EVP_MD_CTX* mdctx = EVP_MD_CTX_create(); if (!mdctx) { throw logic_error("Message digest creation context"); } const char *private_key = PRIVATE_KEY ; BIO* bio = BIO_new_mem_buf((void*) (private_key), strlen(private_key)); EVP_PKEY *pktmp = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL); BIO_free(bio); /*Initialise the DigestSign operation - SHA-256 has been selected * as the message digest function in this example */ if (1 != EVP_DigestSignInit(mdctx, NULL, EVP_sha256(), NULL, pktmp)) { EVP_MD_CTX_destroy(mdctx); } /* Call update with the message */ if (EVP_DigestSignUpdate(mdctx, license.c_str(), license.length()) != 1) { EVP_MD_CTX_destroy(mdctx); throw logic_error("Message signing exception"); } /* Finalise the DigestSign operation */ /* First call EVP_DigestSignFinal with a NULL sig parameter to obtain the length of the * signature. Length is returned in slen */ if (EVP_DigestSignFinal(mdctx, NULL, &slen) != 1) { EVP_MD_CTX_destroy(mdctx); throw logic_error("Message signature finalization exception"); } /* Allocate memory for the signature based on size in slen */ if (!(signature = (unsigned char *) OPENSSL_malloc( sizeof(unsigned char) * slen))) { EVP_MD_CTX_destroy(mdctx); throw logic_error("Message signature memory allocation exception"); } /* Obtain the signature */ if (1 != EVP_DigestSignFinal(mdctx, signature, &slen)) { OPENSSL_free(signature); EVP_MD_CTX_destroy(mdctx); throw logic_error("Message signature exception"); } /* FILE* stream = fmemopen(*buffer, encodedSize+1, "w"); */ //bio = BIO_new_fp(stdout, BIO_NOCLOSE); /*int encodedSize = 4 * ceil(slen / 3); char* buffer = (char*) (malloc(encodedSize + 1)); memset(buffer,0,encodedSize+1);*/ string signatureStr = Opensslb64Encode(slen, signature); /* * BIO *bio, *b64; char message[] = "Hello World \n"; b64 = BIO_new(BIO_f_base64()); bio = BIO_new_fp(stdout, BIO_NOCLOSE); bio = BIO_push(b64, bio); BIO_write(bio, message, strlen(message)); BIO_flush(bio); BIO_free_all(bio); Read Base64 encoded data from standard input and write the decoded data to standard output: BIO *bio, *b64, *bio_out; char inbuf[512]; int inlen; b64 = BIO_new(BIO_f_base64()); bio = BIO_new_fp(stdin, BIO_NOCLOSE); bio_out = BIO_new_fp(stdout, BIO_NOCLOSE); bio = BIO_push(b64, bio); while((inlen = BIO_read(bio, inbuf, 512)) > 0) BIO_write(bio_out, inbuf, inlen); BIO_free_all(bio); */ /* Clean up */ //free(buffer); if (pktmp) EVP_PKEY_free(pktmp); if (signature) OPENSSL_free(signature); if (mdctx) EVP_MD_CTX_destroy(mdctx); return signatureStr; return NULL; } void LicenseSigner::signLicense(FullLicenseInfo& licenseInfo) { test/CMakeLists.txt
@@ -1,7 +1,7 @@ #if we're here boost has been found include_directories(${Boost_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) link_directories ( ${Boost_LIBRARY_DIRS} ) link_directories ( ${Boost_LIBRARY_DIR} ) add_subdirectory(library) add_subdirectory(license-generator) test/functional/CMakeLists.txt
@@ -16,8 +16,7 @@ standard_license_test license++_static license_generator_snippet ${Boost_filesystem_LIBRARY} ${Boost_test_LIBRARY} ${Boost_LIBRARIES} ) #SET_TARGET_PROPERTIES(standard_license_test PROPERTIES LINK_SEARCH_START_STATIC ON) #add_dependencies( standard_license_test boost_test boost_filesystem ) @@ -31,8 +30,7 @@ date_test license++_static license_generator_snippet ${Boost_filesystem_LIBRARY} ${Boost_test_LIBRARY} ${Boost_LIBRARIES} ) #SET_TARGET_PROPERTIES(date_test PROPERTIES LINK_SEARCH_START_STATIC ON) #add_dependencies( date_test boost_test boost_filesystem ) @@ -46,7 +44,7 @@ volid_test license++_static license_generator_snippet ${Boost_test_LIBRARY} ${Boost_LIBRARIES} ) #SET_TARGET_PROPERTIES(volid_test PROPERTIES LINK_SEARCH_START_STATIC ON) test/functional/volid_test.cpp
@@ -1,6 +1,6 @@ #define BOOST_TEST_MODULE standard_license_test //#define BOOST_TEST_MAIN //#define BOOST_TEST_DYN_LINK //#undef BOOST_TEST_DYN_LINK #include <boost/test/unit_test.hpp> #include <fstream> #include <cstring> @@ -11,7 +11,6 @@ #include "../../src/library/ini/SimpleIni.h" #include "generate-license.h" #include "../../src/library/pc-identifiers.h" #include <dbus-1.0/dbus/dbus.h> namespace fs = boost::filesystem; using namespace license; test/library/CMakeLists.txt
@@ -7,8 +7,7 @@ target_link_libraries( license_reader_test license++_static boost_filesystem boost_test ${Boost_LIBRARIES} ) #SET_TARGET_PROPERTIES(license_reader_test PROPERTIES LINK_SEARCH_START_STATIC ON) @@ -26,7 +25,7 @@ target_link_libraries( os_linux_test os ${Boost_test_LIBRARY} ${Boost_LIBRARIES} ) #add_dependencies( os_linux_test ) test/license-generator/CMakeLists.txt
@@ -7,7 +7,7 @@ target_link_libraries( license_generator_test license_generator_lib ${Boost_test_LIBRARY} ${Boost_LIBRARIES} ) #add_dependencies( license_generator_test boost_test boost_filesystem )