diff --git a/CMakeLists.txt b/CMakeLists.txt index 8972ebc300e7712476913d069ca5d9739588163a..5fc8536c23e568232c6907da0cf30e1359dc4d15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required( VERSION 2.6 ) +cmake_minimum_required( VERSION 2.8.7 ) project( simmc-agent ) @@ -47,7 +47,17 @@ endif () # headers include_directories ( "include" ) +include_directories ( "${CMAKE_BINARY_DIR}/include" ) +# src : libre2 - Download, build and install the library + +find_package (Threads) + +include ( "modules/re2.cmake" ) + +link_directories ( ${CMAKE_BINARY_DIR}/lib) + +set(RE2_STATIC_LIBRARIES -L${RE2_LIBRARY_DIR} -l libre2.a ) # test option( PRINT_JSON "Set to ON to print json objects before sending" OFF ) @@ -56,12 +66,14 @@ if ( PRINT_JSON ) add_definitions ( -DPRINT_JSON ) endif () - # compile set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" ) add_executable ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES} ) +target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${CPR_LIBRARIES} ${CURL_LIBRARIES} ${RE2_STATIC_LIBRARIES}) + +add_dependencies ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} RE2) -target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${CPR_LIBRARIES} ) +target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${CMAKE_THREAD_LIBS_INIT} ) if ( WIN32 ) target_link_libraries ( agent-v${VERSION_MAJOR}.${VERSION_MINOR} dtwinver ) diff --git a/README.md b/README.md index ceb72a22bcd0cf509063599367ee57ae96057fc8..bcfae61891a8130751641a324904d893aa509e79 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ requirements ------------ c++ compiler cmake +libre2-dev building and compiling ---------------------- diff --git a/update/agent/conf/datasid-conf.json b/conf/datasid-conf.json similarity index 100% rename from update/agent/conf/datasid-conf.json rename to conf/datasid-conf.json diff --git a/update/agent/include/agent/linux/datasid-agent.h b/include/agent/linux/datasid-agent.h similarity index 100% rename from update/agent/include/agent/linux/datasid-agent.h rename to include/agent/linux/datasid-agent.h diff --git a/update/agent/include/agent/linux/datasid-common.h b/include/agent/linux/datasid-common.h similarity index 100% rename from update/agent/include/agent/linux/datasid-common.h rename to include/agent/linux/datasid-common.h diff --git a/update/agent/include/agent/linux/datasid-conf.h b/include/agent/linux/datasid-conf.h similarity index 100% rename from update/agent/include/agent/linux/datasid-conf.h rename to include/agent/linux/datasid-conf.h diff --git a/update/agent/include/agent/linux/datasid-parse.h b/include/agent/linux/datasid-parse.h similarity index 100% rename from update/agent/include/agent/linux/datasid-parse.h rename to include/agent/linux/datasid-parse.h diff --git a/update/agent/include/agent/linux/datasid-proxy.h b/include/agent/linux/datasid-proxy.h similarity index 100% rename from update/agent/include/agent/linux/datasid-proxy.h rename to include/agent/linux/datasid-proxy.h diff --git a/update/agent/include/agent/main.h b/include/agent/main.h similarity index 100% rename from update/agent/include/agent/main.h rename to include/agent/main.h diff --git a/modules/re2.cmake b/modules/re2.cmake new file mode 100644 index 0000000000000000000000000000000000000000..e51099a0e6812c68b2e552d053d8e84d9c1e6b39 --- /dev/null +++ b/modules/re2.cmake @@ -0,0 +1,47 @@ +cmake_minimum_required ( VERSION 2.8.7 ) + +set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/re2Include" CACHE PATH "default install path" FORCE ) + + if (NOT RE2_NAME) + + include (ExternalProject) + + SET (RE2_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/re2/src/re2/) + SET (RE2_EXTRA_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/re2/src/re2/) + SET (RE2_URL https://github.com/google/re2.git) + SET (RE2_BUILD ${CMAKE_BINARY_DIR}/re2/src/re2) + SET (RE2_LIBRARIES ${RE2_BUILD}/obj/so/libre2.so) + get_filename_component(RE2_STATIC_LIBRARIES ${RE2_BUILD}/libre2.a ABSOLUTE) + SET (RE2_INCLUDES ${RE2_BUILD}) + + if ( WIN32 ) + SET (RE2_STATIC_LIBRARIES ${RE2_BUILD}/${CMAKE_BUILD_TYPE}/re2.lib) + else () + SET (RE2_STATIC_LIBRARIES ${RE2_BUILD}/libre2.a) + endif () + + ExternalProject_Add(RE2 + PREFIX RE2 + GIT_REPOSITORY ${RE2_URL} + # GIT_TAG ${RE2_TAG} + DOWNLOAD_DIR "${DOWNLOAD_LOCATION}" + BUILD_IN_SOURCE 1 + INSTALL_COMMAND make install + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} + CMAKE_CACHE_ARGS + -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_VERBOSE_MAKEFILE:BOOL=OFF -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON + ) + + ## put re2 includes in the directory where they are expected + add_custom_target(re2_create_destination_dir COMMAND ${CMAKE_COMMAND} -E make_directory ${RE2_INCLUDE_DIR}/re2 DEPENDS re2) + + add_custom_target(re2_copy_headers_to_destination DEPENDS re2_create_destination_dir) + + foreach(header_file ${RE2_HEADERS}) + add_custom_command(TARGET re2_copy_headers_to_destination PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${header_file} ${RE2_INCLUDE_DIR}/re2) + endforeach () + + ADD_LIBRARY(RE2_LIB STATIC IMPORTED DEPENDS RE2) + SET_TARGET_PROPERTIES(RE2_LIB PROPERTIES IMPORTED_LOCATION ${RE2_STATIC_LIBRARIES}) + + endif (NOT RE2_NAME) diff --git a/update/agent/src/linux/datasid-agent.cpp b/src/linux/datasid-agent.cpp similarity index 100% rename from update/agent/src/linux/datasid-agent.cpp rename to src/linux/datasid-agent.cpp diff --git a/update/agent/src/linux/datasid-common.cpp b/src/linux/datasid-common.cpp similarity index 90% rename from update/agent/src/linux/datasid-common.cpp rename to src/linux/datasid-common.cpp index bf89b0856e90b11f4f7f312057a3af3468ff7180..0fcf5857e763e340306da22cd9a593e9b7ca3ef2 100644 --- a/update/agent/src/linux/datasid-common.cpp +++ b/src/linux/datasid-common.cpp @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. */ +#include <string> #include "../../include/agent/linux/datasid-common.h" /* @@ -47,15 +48,16 @@ bool datasid_common(Conf* conf, Proxy* proxy, Agent* agent) { /* Read config file and declare only valid variables */ if (!fileExist(agent->getDefaultConf())) { - std::cout << __DATE__ << "- ERROR: Config file not found. " << std::endl; + std::cout << __DATE__ << "ERROR: Config file not found." << std::endl; return false; - } else + } else { datasid_conf(agent, conf); + } /* Read proxy file and declare only valid variables */ if (!fileExist(conf->getProxyConf())) - std::cout << __DATE__ << "- WARNING: Proxy file not found. " << std::endl; + std::cout << __DATE__ << "WARNING: Proxy file not found. " << std::endl; else datasid_proxy(conf, proxy); diff --git a/update/agent/src/linux/datasid-conf.cpp b/src/linux/datasid-conf.cpp similarity index 96% rename from update/agent/src/linux/datasid-conf.cpp rename to src/linux/datasid-conf.cpp index 99f967bc59b9e09ca36020dca7acaadf1b61760f..ab33ecfaf52c1d47be4353b899a060aed1cac690 100644 --- a/update/agent/src/linux/datasid-conf.cpp +++ b/src/linux/datasid-conf.cpp @@ -21,8 +21,10 @@ #include <cstdlib> #include <cstring> #include <iostream> -#include <locale> +#include <locale> +#include <map> #include <sstream> +#include <string> #include "../../include/agent/linux/datasid-conf.h" /* * set Functions @@ -102,7 +104,9 @@ int Conf::getUpdateTimeOut() const { * then set the conf object */ -bool setConf(Conf* conf, Agent* agent, std::map<std::string, std::string>* content) { +bool setConf(Conf* conf, Agent* agent, std::map<std::string, + std::string>* content) { + if (content->count("DATADIR") == 0 || content->count("LOGDIR") == 0 || content->count("PROXYCONF") == 0 || diff --git a/update/agent/src/linux/datasid-parse.cpp b/src/linux/datasid-parse.cpp similarity index 94% rename from update/agent/src/linux/datasid-parse.cpp rename to src/linux/datasid-parse.cpp index 86fd337e00dc8c4ba5e6a46999ae3d1c0873f68c..2bec17c626ab53c45f2320cc3b681592af098b99 100644 --- a/update/agent/src/linux/datasid-parse.cpp +++ b/src/linux/datasid-parse.cpp @@ -18,7 +18,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. */ -#include <regex> +#include <re2/re2.h> +#include <map> +#include <string> #include "../../include/agent/linux/datasid-parse.h" /* @@ -53,11 +55,10 @@ void trim(std::string* str) { void normalize(std::string* str) { size_t i, j; i = j = 0; - + trim(str); while (i < str->length()) { - if ((*str)[i] == ' ' || (*str)[i] == '\t') { j = i + 1; @@ -68,8 +69,9 @@ void normalize(std::string* str) { str->erase(i, 1); else str->erase(i, j - i); - } else + } else { ++i; + } } } @@ -92,28 +94,26 @@ bool spaceOnly(const std::string* line) { */ bool isValid(std::string* line) { - std::string e = *line; + std::string s = *line; int i = 0; normalize(line); /* if the line is a comment */ - if (std::regex_match((*line), std::regex("((\\/\\/)|(\\/\\*)|(\\#))(.*)"))) + if (RE2::FullMatch(s, "((\\/\\/)|(\\/\\*)|(\\#))(.*)")) return false; /* if the line start with a different character than quote */ - if (!std::regex_match((*line), std::regex("(\")(.*)"))) + if (!RE2::FullMatch(s, "(\")(.*)")) return false; - /* * if the line start with quote, * but is not a pattern : "key":"value" */ if ((*line)[i] = '"') { - int n = std::count((*line).begin(), (*line).end(), '"'); /* if the line doesn't has four quotes */ @@ -143,7 +143,6 @@ bool isValid(std::string* line) { if (n == (line->length())-1) return false; - } return true; @@ -182,7 +181,9 @@ void parse(std::string* line, std::map<std::string, std::string>* content) { * a conf or proxy object. */ -bool readFile(const std::string file, std::map<std::string, std::string>* content) { +bool readFile(const std::string file, std::map<std::string, + std::string>* content) { + content->clear(); std::ifstream config(file.c_str(), std::ifstream::in); diff --git a/update/agent/src/linux/datasid-proxy.cpp b/src/linux/datasid-proxy.cpp similarity index 98% rename from update/agent/src/linux/datasid-proxy.cpp rename to src/linux/datasid-proxy.cpp index 1e78cf9fb2e06dbc68b8759ad2ade9fb270a8024..32ac8a7016a713128fdc3b68768539574aba9cae 100644 --- a/update/agent/src/linux/datasid-proxy.cpp +++ b/src/linux/datasid-proxy.cpp @@ -19,6 +19,8 @@ * USA. */ #include <iostream> +#include <map> +#include <string> #include "../../include/agent/linux/datasid-proxy.h" /* @@ -91,6 +93,7 @@ void datasid_proxy(Conf* conf, Proxy* proxy) { " from proxy file." << std::endl; exit(1); } - } else + } else { std::cout << __DATE__ << " WARNING: proxy file not found." << std::endl; + } } diff --git a/src/main.cpp b/src/main.cpp index 3bdd5da8d37a37ef2df4dd149c102be9426cd873..51f0d7afd500b9c7bc8786e041a33fe7cc40a766 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,6 +24,7 @@ #include <iostream> #include <fstream> #include "agent/post.h" +#include "agent/main.h" int main() { @@ -31,5 +32,7 @@ int main() { send_net_bandwidth(); send_user_history(); + datasid_agent(); + return 0; } diff --git a/update/agent/CMakeLists.txt b/update/agent/CMakeLists.txt deleted file mode 100644 index c8f56b350e40808381b3521a679ba2df64b18b3a..0000000000000000000000000000000000000000 --- a/update/agent/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -cmake_minimum_required( VERSION 2.6 ) - -project( datasid-agent ) - -# version number -set ( VERSION_MAJOR 0 ) -set ( VERSION_MINOR 0 ) - -# cpr requires c++11 -set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" ) - -# src : main -file ( GLOB SOURCES src/*.cpp ) - -# src : collect functions - depend on OS -if ( WIN32 ) - file ( GLOB SOURCES ${SOURCES} src/windows/*.cpp ) -else () # if( UNIX ) - file ( GLOB SOURCES ${SOURCES} src/linux/*.cpp ) -endif () - -# compile -set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" ) -add_executable ( datasid-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES} ) - diff --git a/update/agent/src/main.cpp b/update/agent/src/main.cpp deleted file mode 100644 index b0ddb53f60037c83f68585a3314fc2b2be795c97..0000000000000000000000000000000000000000 --- a/update/agent/src/main.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright (C) 2004-2016 Centro de Computacao Cientifica e Software Livre - * Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR - * - * This file is part of datasid - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - */ -#include "../include/agent/main.h" - -int main(){ - datasid_agent(); - return 0; -} \ No newline at end of file