added c++ doc and replaced ifndef with pragma once

This commit is contained in:
max mustermann 2019-08-01 21:19:02 +02:00
parent 904cd2e96a
commit 52cc5f204b
13 changed files with 104 additions and 77 deletions

View File

@ -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)

26
inc/Logger.h Normal file
View File

@ -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();
};

32
inc/api/API.h Normal file
View File

@ -0,0 +1,32 @@
//
// Created by lukas on 06.04.19.
//
#pragma once
#include <string>
#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<std::string, std::string> &map, std::vector<std::string> &headers);
private:
static size_t write_data(void *buffer, size_t size, size_t buffersize, FILE *stream);
};

View File

@ -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

View File

@ -2,8 +2,7 @@
// Created by lukas on 07.04.19.
//
#ifndef QT5PROJECT_HASHMAP_H
#define QT5PROJECT_HASHMAP_H
#pragma once
#include <iostream>
@ -12,12 +11,31 @@
template<class keytype, class valuetype>
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<class keytype, class valuetype>
int Hashmap<keytype, valuetype>::size() {
return (int) (keys.size());
}
#endif //QT5PROJECT_HASHMAP_H

View File

@ -2,17 +2,16 @@
// Created by lukas on 18.06.19.
//
#ifndef IPREFRESHER_IPAPI_H
#define IPREFRESHER_IPAPI_H
#pragma once
#include <string>
#include "API.h"
class IPAPI : API{
public:
/**
* get global ip of current internet connection
* @return global ip
*/
std::string getGlobalIp();
};
#endif //IPREFRESHER_IPAPI_H

View File

@ -2,8 +2,7 @@
// Created by lukas on 08.05.19.
//
#ifndef IPREFRESHER_TELEGRAMAPI_H
#define IPREFRESHER_TELEGRAMAPI_H
#pragma once
#include <string>
@ -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

View File

@ -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

View File

@ -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 <string>
#include <iostream>

View File

@ -1,23 +0,0 @@
//
// Created by lukas on 06.04.19.
//
#ifndef IPREFRESHER_API_H
#define IPREFRESHER_API_H
#include <string>
#include "Hashmap.h"
class API {
public:
std::string request(std::string myurl);
std::string request(std::string myurl, bool post, Hashmap<std::string, std::string> &map, std::vector<std::string> &headers);
private:
static size_t write_data(void *buffer, size_t size, size_t buffersize, FILE *stream);
};
#endif //IPREFRESHER_API_H

View File

@ -2,7 +2,7 @@
// Created by lukas on 18.06.19.
//
#include "DynuAPI.h"
#include "api/DynuAPI.h"
int DynuAPI::refreshIp(std:: string ip) {

View File

@ -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");

View File

@ -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<std::string, std::string> args;