moved why2_get_version string extraction to get_version

This commit is contained in:
Václav Šmejkal 2024-08-28 12:21:59 +02:00
parent ef235e48f7
commit 1735da3807
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -447,6 +447,24 @@ unsigned long get_latest_id()
return returning; return returning;
} }
char *get_version(void)
{
//GET VERSION STRING FROM THE VERSIONS JSON
struct json_object *version_object;
char *version_file = why2_get_version();
struct json_object *version_json = json_tokener_parse(version_file);
json_object_object_get_ex(version_json, "active", &version_object);
//DUPLICATE version_object STRING (THE ORIGINAL WILL BE REMOVED BY json_object_put)
char *version = why2_strdup((char*) json_object_get_string(version_object));
//DEALLOCATION
why2_deallocate(version_file);
json_object_put(version_json);
return version;
}
//GLOBAL //GLOBAL
void why2_send_socket(char *text, char *username, int socket) void why2_send_socket(char *text, char *username, int socket)
{ {
@ -651,12 +669,7 @@ void *why2_communicate_thread(void *arg)
} else if (strcmp(decoded_buffer, WHY2_CHAT_CODE_VERSION) == 0) } else if (strcmp(decoded_buffer, WHY2_CHAT_CODE_VERSION) == 0)
{ {
//GET VERSION STRING FROM THE VERSIONS JSON //GET VERSION STRING FROM THE VERSIONS JSON
struct json_object *version_object; char *version = get_version();
char *version_file = why2_get_version();
struct json_object *version_json = json_tokener_parse(version_file);
json_object_object_get_ex(version_json, "active", &version_object);
char *version = (char*) json_object_get_string(version_object);
char *message = why2_malloc(strlen(WHY2_CHAT_CODE_VERSION_SERVER) + strlen(version) + 2); //ALLOCATE MESSAGE FOR CLIENT char *message = why2_malloc(strlen(WHY2_CHAT_CODE_VERSION_SERVER) + strlen(version) + 2); //ALLOCATE MESSAGE FOR CLIENT
sprintf(message, WHY2_CHAT_CODE_VERSION_SERVER ";%s%c", version, '\0'); //CREATE THE MESSAGE sprintf(message, WHY2_CHAT_CODE_VERSION_SERVER ";%s%c", version, '\0'); //CREATE THE MESSAGE
@ -666,8 +679,7 @@ void *why2_communicate_thread(void *arg)
//DEALLOCATION //DEALLOCATION
why2_deallocate(message); why2_deallocate(message);
json_object_put(version_json); why2_deallocate(version);
why2_deallocate(version_file);
} }
//IGNORE INVALID CODES, THE USER JUST GOT THEIR LOBOTOMY DONE //IGNORE INVALID CODES, THE USER JUST GOT THEIR LOBOTOMY DONE