diff --git a/.gitignore b/.gitignore index daecc2e..5d541da 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ .idea/**/dynamic.xml .idea/**/uiDesigner.xml .idea/**/dbnavigator.xml +.idea/**/*.xml # Gradle .idea/**/gradle.xml diff --git a/src/Logger.cpp b/src/Logger.cpp index e909569..ec592c5 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -11,7 +11,7 @@ void Logger::safeip(std::string ip) { std::ofstream out; - out.open("ip.txt",std::ios::out); + out.open("ip.txt", std::ios::out); out << ip; @@ -20,7 +20,7 @@ void Logger::safeip(std::string ip) { std::string Logger::readip() { std::ifstream in; - in.open("ip.txt",std::ios::in); + in.open("ip.txt", std::ios::in); std::string ip; @@ -31,16 +31,16 @@ std::string Logger::readip() { void Logger::logToLogfile(std::string text) { std::ofstream out; - out.open("dynurefresher.log",std::ios::out | std::ios::app); + out.open("dynurefresher.log", std::ios::out | std::ios::app); std::time_t t = std::time(0); // get time now - std::tm* now = std::localtime(&t); + std::tm *now = std::localtime(&t); std::stringstream logline; - logline << "[ "<< (now->tm_year + 1900) << '-' << (now->tm_mon + 1) << '-' << now->tm_mday - << "_" << now->tm_hour << ":" << now->tm_min << ":" << now->tm_sec << " ] " << '\t' << text << std::endl; + logline << "[ " << (now->tm_year + 1900) << '-' << (now->tm_mon + 1) << '-' << now->tm_mday + << "_" << now->tm_hour << ":" << now->tm_min << ":" << now->tm_sec << " ] " << '\t' << text << std::endl; out << logline.str(); diff --git a/src/Logger.h b/src/Logger.h index efcb2b1..67cb87a 100644 --- a/src/Logger.h +++ b/src/Logger.h @@ -9,7 +9,9 @@ class Logger { public: void logToLogfile(std::string text); + void safeip(std::string ip); + std::string readip(); }; diff --git a/src/api/API.cpp b/src/api/API.cpp index 915b947..720ee6e 100644 --- a/src/api/API.cpp +++ b/src/api/API.cpp @@ -12,13 +12,14 @@ std::string API::request(std::string myurl) { - Hashmap map; + Hashmap map; std::vector str; - return request(std::move(myurl),false,map,str); + return request(std::move(myurl), false, map, str); } -std::string API::request(std::string myurl, bool post, Hashmap &map, std::vector &headers) { +std::string +API::request(std::string myurl, bool post, Hashmap &map, std::vector &headers) { CURL *curl; CURLcode res; @@ -40,12 +41,12 @@ std::string API::request(std::string myurl, bool post, Hashmapappend((char*)contents, size * nmemb); + ((std::string *) stream)->append((char *) contents, size * nmemb); return size * nmemb; } diff --git a/src/api/API.h b/src/api/API.h index d07a272..202a7e4 100644 --- a/src/api/API.h +++ b/src/api/API.h @@ -12,7 +12,8 @@ class API { public: std::string request(std::string myurl); - std::string request(std::string myurl, bool post, Hashmap &map,std::vector &headers); + + 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/Hashmap.h b/src/api/Hashmap.h index 4eb550a..4fc90d5 100644 --- a/src/api/Hashmap.h +++ b/src/api/Hashmap.h @@ -9,10 +9,13 @@ #include #include -template class Hashmap { +template +class Hashmap { public: - void add(keytype key,keytype value); + void add(keytype key, keytype value); + keytype getKey(int position); + valuetype getValue(int position); int size(); diff --git a/src/api/TelegramAPI.cpp b/src/api/TelegramAPI.cpp index 1b9b8ba..985d144 100644 --- a/src/api/TelegramAPI.cpp +++ b/src/api/TelegramAPI.cpp @@ -5,6 +5,6 @@ #include "TelegramAPI.h" void TelegramAPI::sendMessage(std::string text) { - std::string reply = request("https://api.telegram.org/bot"+ apikey + "/sendmessage?chat_id="+chatid+"&text="+text); - std::cout << "[DEBUG] " < #include "API.h" -class TelegramAPI : API{ +class TelegramAPI : API { public: void sendMessage(std::string text); diff --git a/src/main.cpp b/src/main.cpp index 65a6859..8797dab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) { if (dynurepl != "{\"statusCode\":200}") { logger.logToLogfile(" [ERROR] failed to write ip to dynu api!"); - } else{ + } else { TelegramAPI tele; tele.sendMessage(oldip + " moved to " + ip); }