From 4b481d71cab00e7aa9ac854f53854fcb60cc3fd1 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 31 Mar 2023 17:47:05 +0200 Subject: [PATCH] removing invalid json syntax on send --- src/chat/misc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/chat/misc.c b/src/chat/misc.c index bea7293..b9c281b 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -234,6 +234,17 @@ char *read_socket_from_raw(char *raw) return final_message; } +void remove_json_syntax_characters(char *text) +{ + for (size_t i = 0; i < strlen(text); i++) //TODO: DO SOMETHING MORE + { + if (text[i] == '\"') + { + text[i] = '\''; + } + } +} + //GLOBAL void why2_send_socket(char *text, char *username, int socket) { @@ -243,9 +254,12 @@ void why2_send_socket(char *text, char *username, int socket) struct json_object *json = json_tokener_parse("{}"); //COPY text INTO text_copy (WITHOUT LAST CHARACTER WHEN NEWLINE IS AT THE END) - if (text[length_buffer - 1] == '\n') length_buffer--; //TODO: Remove json syntax + if (text[length_buffer - 1] == '\n') length_buffer--; strncpy(text_copy, text, length_buffer); + //UNFUCK QUOTES FROM text_copy + remove_json_syntax_characters(text_copy); + //ADD OBJECTS json_object_object_add(json, "message", json_object_new_string(text_copy)); json_object_object_add(json, "username", json_object_new_string(username));