From a9afb05768065910fa2e9bdbc2d1c30f07df9ade Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 22 Apr 2022 18:39:48 +0200 Subject: [PATCH] created misc.c --- include/misc.h | 6 ++++++ src/misc.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 include/misc.h create mode 100644 src/misc.c diff --git a/include/misc.h b/include/misc.h new file mode 100644 index 0000000..b7c035e --- /dev/null +++ b/include/misc.h @@ -0,0 +1,6 @@ +#ifndef WHY2_MISC_H +#define WHY2_MISC_H + +void checkVersion(); //THIS FUNCTION CHECKS IF LATEST VERSION OF WHY2 IS USED + +#endif diff --git a/src/misc.c b/src/misc.c new file mode 100644 index 0000000..3f2ea15 --- /dev/null +++ b/src/misc.c @@ -0,0 +1,56 @@ +#include "../include/misc.h" + +#include +#include + +#include +#include + +#include "../include/flags.h" + +void +checkVersion() +{ + //CURL VARIABLES + CURL *curl = curl_easy_init(); + FILE *fileBuffer = fopen(VERSIONS_NAME, "w"); + + //GET versions.json + curl_easy_setopt(curl, CURLOPT_URL, VERSIONS_URL); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, fileBuffer); + + //DOWNLOAD versions.json + curl_easy_perform(curl); + + //CLEANUP + curl_easy_cleanup(curl); + fclose(fileBuffer); + + //JSON VARIABLES + fileBuffer = fopen(VERSIONS_NAME, "r"); + char buffer[256]; + char lineBuffer[64]; + struct json_object *parsedJson; + struct json_object *active; + + //LOAD jsonFile + while (fgets(lineBuffer, sizeof(lineBuffer), fileBuffer) != NULL) + { + strcat(buffer, lineBuffer); + } + + //CLEANUP + fclose(fileBuffer); + + //GET + parsedJson = json_tokener_parse(buffer); + json_object_object_get_ex(parsedJson, "active", &active); + + if (strcmp(VERSION, json_object_get_string(active)) != 0) + { + fprintf(stderr, "Your version isn't latest! This release could be unsafe!\n"); + + //WAIT FOR 5 SECONDS + sleep(5); + } +}