removing invalid json syntax on send

This commit is contained in:
Václav Šmejkal 2023-03-31 17:47:05 +02:00
parent d9fe24b166
commit 4b481d71ca
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -234,6 +234,17 @@ char *read_socket_from_raw(char *raw)
return final_message; 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 //GLOBAL
void why2_send_socket(char *text, char *username, int socket) 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("{}"); struct json_object *json = json_tokener_parse("{}");
//COPY text INTO text_copy (WITHOUT LAST CHARACTER WHEN NEWLINE IS AT THE END) //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); strncpy(text_copy, text, length_buffer);
//UNFUCK QUOTES FROM text_copy
remove_json_syntax_characters(text_copy);
//ADD OBJECTS //ADD OBJECTS
json_object_object_add(json, "message", json_object_new_string(text_copy)); json_object_object_add(json, "message", json_object_new_string(text_copy));
json_object_object_add(json, "username", json_object_new_string(username)); json_object_object_add(json, "username", json_object_new_string(username));