created misc.c
This commit is contained in:
parent
5a67ceafa7
commit
a9afb05768
6
include/misc.h
Normal file
6
include/misc.h
Normal file
@ -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
|
56
src/misc.c
Normal file
56
src/misc.c
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#include "../include/misc.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <curl/curl.h>
|
||||||
|
#include <json-c/json.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user