From 52cc5f204b29ebaa7058493cf5134412226211f9 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Thu, 1 Aug 2019 21:19:02 +0200 Subject: [PATCH] added c++ doc and replaced ifndef with pragma once --- CMakeLists.txt | 13 +++++-------- inc/Logger.h | 26 ++++++++++++++++++++++++++ inc/api/API.h | 32 ++++++++++++++++++++++++++++++++ {src => inc}/api/DynuAPI.h | 11 ++++++----- {src => inc}/api/Hashmap.h | 25 ++++++++++++++++++++----- {src => inc}/api/IPAPI.h | 11 +++++------ {src => inc}/api/TelegramAPI.h | 10 +++++----- src/Logger.h | 20 -------------------- src/api/API.cpp | 4 ++-- src/api/API.h | 23 ----------------------- src/api/DynuAPI.cpp | 2 +- src/api/IPAPI.cpp | 2 +- src/api/TelegramAPI.cpp | 2 +- 13 files changed, 104 insertions(+), 77 deletions(-) create mode 100644 inc/Logger.h create mode 100644 inc/api/API.h rename {src => inc}/api/DynuAPI.h (71%) rename {src => inc}/api/Hashmap.h (66%) rename {src => inc}/api/IPAPI.h (56%) rename {src => inc}/api/TelegramAPI.h (72%) delete mode 100644 src/Logger.h delete mode 100644 src/api/API.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a507f0..847a1d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,30 +1,24 @@ cmake_minimum_required(VERSION 3.7) -project(iprefresher VERSION 1.0.1 DESCRIPTION "mylib description") +project(iprefresher VERSION 1.0.1 DESCRIPTION "Dynu ip refresher") set(CMAKE_CXX_STANDARD 17) find_package(CURL REQUIRED) -include_directories(${CURL_INCLUDE_DIR}) +include_directories(${CURL_INCLUDE_DIR} inc) add_library(api - src/api/API.h src/api/API.cpp - src/api/Hashmap.h src/api/TelegramAPI.cpp - src/api/TelegramAPI.h src/api/DynuAPI.cpp - src/api/DynuAPI.h src/api/IPAPI.cpp - src/api/IPAPI.h ) add_library(logger src/Logger.cpp - src/Logger.h ) @@ -33,6 +27,9 @@ set(SOURCE ) add_executable(iprefresher ${SOURCE}) + +# LINK generated LIBS # target_link_libraries(iprefresher api logger ${CURL_LIBRARIES} ) +# INSTALL to SYSTEM # install (TARGETS iprefresher DESTINATION bin) diff --git a/inc/Logger.h b/inc/Logger.h new file mode 100644 index 0000000..32ab87f --- /dev/null +++ b/inc/Logger.h @@ -0,0 +1,26 @@ +// +// Created by lukas on 05.05.19. +// +#pragma once + +class Logger { +public: + /** + * log messages to logfile + * @param text message + */ + void logToLogfile(std::string text); + + /** + * safe ip to temp file + * @param ip ip address to save + */ + void safeip(std::string ip); + + /** + * read ip from file + * @return read ip + */ + std::string readip(); + +}; diff --git a/inc/api/API.h b/inc/api/API.h new file mode 100644 index 0000000..5c3e3c2 --- /dev/null +++ b/inc/api/API.h @@ -0,0 +1,32 @@ +// +// Created by lukas on 06.04.19. +// + +#pragma once + + +#include +#include "Hashmap.h" + +class API { +public: + /** + * Simple API get request + * @param myurl api url + * @return return string of server + */ + std::string request(std::string myurl); + + /** + * complex request with post/get and header information support + * @param myurl base request url + * @param post boolean (false=get) + * @param map post/get fields + * @param headers header fields + * @return return string of server + */ + std::string request(std::string myurl, bool post, Hashmap &map, std::vector &headers); + +private: + static size_t write_data(void *buffer, size_t size, size_t buffersize, FILE *stream); +}; diff --git a/src/api/DynuAPI.h b/inc/api/DynuAPI.h similarity index 71% rename from src/api/DynuAPI.h rename to inc/api/DynuAPI.h index fad52a9..ac2df2d 100644 --- a/src/api/DynuAPI.h +++ b/inc/api/DynuAPI.h @@ -2,14 +2,18 @@ // Created by lukas on 18.06.19. // -#ifndef IPREFRESHER_DYNUAPI_H -#define IPREFRESHER_DYNUAPI_H +#pragma once #include "API.h" class DynuAPI : API{ public: + /** + * refresh the ip of domain on Dynu server + * @param ip new ip + * @return request status + */ int refreshIp(std::string ip); private: const std::string dynuapikey = "88vNpMfDhMM2YYDNfWR1DNYfRX9W6fYg"; @@ -17,6 +21,3 @@ private: const std::string domainid = "8506047"; //id of the dynu domain const std::string domainname = "luki.dynu.net"; }; - - -#endif //IPREFRESHER_DYNUAPI_H diff --git a/src/api/Hashmap.h b/inc/api/Hashmap.h similarity index 66% rename from src/api/Hashmap.h rename to inc/api/Hashmap.h index 443bc6b..e55db89 100644 --- a/src/api/Hashmap.h +++ b/inc/api/Hashmap.h @@ -2,8 +2,7 @@ // Created by lukas on 07.04.19. // -#ifndef QT5PROJECT_HASHMAP_H -#define QT5PROJECT_HASHMAP_H +#pragma once #include @@ -12,12 +11,31 @@ template class Hashmap { public: + /** + * add key-value pair to hashmap + * @param key keyvalue + * @param value valuevalue + */ void add(keytype key, keytype value); + /** + * get key of specific position + * @param position int position + * @return responding key object + */ keytype getKey(int position); + /** + * get value of specific position + * @param position int position + * @return responding value object + */ valuetype getValue(int position); + /** + * get size of Hashmap + * @return size of Hashmap + */ int size(); private: @@ -45,6 +63,3 @@ template int Hashmap::size() { return (int) (keys.size()); } - - -#endif //QT5PROJECT_HASHMAP_H diff --git a/src/api/IPAPI.h b/inc/api/IPAPI.h similarity index 56% rename from src/api/IPAPI.h rename to inc/api/IPAPI.h index a8836c4..fbcfd48 100644 --- a/src/api/IPAPI.h +++ b/inc/api/IPAPI.h @@ -2,17 +2,16 @@ // Created by lukas on 18.06.19. // -#ifndef IPREFRESHER_IPAPI_H -#define IPREFRESHER_IPAPI_H - +#pragma once #include #include "API.h" class IPAPI : API{ public: + /** + * get global ip of current internet connection + * @return global ip + */ std::string getGlobalIp(); }; - - -#endif //IPREFRESHER_IPAPI_H diff --git a/src/api/TelegramAPI.h b/inc/api/TelegramAPI.h similarity index 72% rename from src/api/TelegramAPI.h rename to inc/api/TelegramAPI.h index bd8be49..921ed93 100644 --- a/src/api/TelegramAPI.h +++ b/inc/api/TelegramAPI.h @@ -2,8 +2,7 @@ // Created by lukas on 08.05.19. // -#ifndef IPREFRESHER_TELEGRAMAPI_H -#define IPREFRESHER_TELEGRAMAPI_H +#pragma once #include @@ -11,12 +10,13 @@ class TelegramAPI : API { public: + /** + * send telegram Message to predefined destination + * @param text message + */ void sendMessage(std::string text); private: const std::string apikey = "717213769:AAHan1nSXhUsxLJAN1Dv8Oc0z8wqwDdYPn4"; const std::string chatid = "618154204"; }; - - -#endif //IPREFRESHER_TELEGRAMAPI_H diff --git a/src/Logger.h b/src/Logger.h deleted file mode 100644 index 67cb87a..0000000 --- a/src/Logger.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// Created by lukas on 05.05.19. -// - -#ifndef IPREFRESHER_LOGGER_H -#define IPREFRESHER_LOGGER_H - - -class Logger { -public: - void logToLogfile(std::string text); - - void safeip(std::string ip); - - std::string readip(); - -}; - - -#endif //IPREFRESHER_LOGGER_H diff --git a/src/api/API.cpp b/src/api/API.cpp index f934fd7..768345b 100644 --- a/src/api/API.cpp +++ b/src/api/API.cpp @@ -2,8 +2,8 @@ // Created by lukas on 06.04.19. // -#include "API.h" -#include "Hashmap.h" +#include "api/API.h" +#include "api/Hashmap.h" #include #include diff --git a/src/api/API.h b/src/api/API.h deleted file mode 100644 index 202a7e4..0000000 --- a/src/api/API.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// Created by lukas on 06.04.19. -// - -#ifndef IPREFRESHER_API_H -#define IPREFRESHER_API_H - - -#include -#include "Hashmap.h" - -class API { -public: - std::string request(std::string myurl); - - std::string request(std::string myurl, bool post, Hashmap &map, std::vector &headers); - -private: - static size_t write_data(void *buffer, size_t size, size_t buffersize, FILE *stream); -}; - - -#endif //IPREFRESHER_API_H diff --git a/src/api/DynuAPI.cpp b/src/api/DynuAPI.cpp index c5f05e0..b21a450 100644 --- a/src/api/DynuAPI.cpp +++ b/src/api/DynuAPI.cpp @@ -2,7 +2,7 @@ // Created by lukas on 18.06.19. // -#include "DynuAPI.h" +#include "api/DynuAPI.h" int DynuAPI::refreshIp(std:: string ip) { diff --git a/src/api/IPAPI.cpp b/src/api/IPAPI.cpp index d2005b9..f2c9ca5 100644 --- a/src/api/IPAPI.cpp +++ b/src/api/IPAPI.cpp @@ -2,7 +2,7 @@ // Created by lukas on 18.06.19. // -#include "IPAPI.h" +#include "api/IPAPI.h" std::string IPAPI::getGlobalIp() { return request("https://api.ipify.org"); diff --git a/src/api/TelegramAPI.cpp b/src/api/TelegramAPI.cpp index c2dd2f8..d70f9d1 100644 --- a/src/api/TelegramAPI.cpp +++ b/src/api/TelegramAPI.cpp @@ -2,7 +2,7 @@ // Created by lukas on 08.05.19. // -#include "TelegramAPI.h" +#include "api/TelegramAPI.h" void TelegramAPI::sendMessage(std::string text) { Hashmap args;