From 6bc71b201dafd552a46b8e9ab5ee8f1ee5577c17 Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Tue, 6 Aug 2024 16:18:17 +0200 Subject: rest: use JSON_ENSURE_ASCII in json dumps escape non-ascii characters in json otherwise ogclient len() and Content-Length: report a mismatch when utf-8 representation is used in any of the string fields. For consistency, enable this flag too for json dumps that are consumed by ogcp and ogcli. --- src/rest.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src/rest.c') diff --git a/src/rest.c b/src/rest.c index 6ccb97b..7ffb79c 100644 --- a/src/rest.c +++ b/src/rest.c @@ -316,7 +316,7 @@ int og_send_request(enum og_rest_method method, enum og_cmd_type type, else content_length = json_dumpb(data, content, OG_MSG_REQUEST_MAXLEN - 700, - JSON_COMPACT); + JSON_COMPACT | JSON_ENSURE_ASCII); uri = og_cmd_to_uri[type]; @@ -528,7 +528,7 @@ static int og_cmd_get_clients(json_t *element, struct og_msg_params *params, return -1; } - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } @@ -822,7 +822,7 @@ static int og_cmd_run_get(json_t *element, struct og_msg_params *params, if (!root) return -1; - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } @@ -920,7 +920,7 @@ static int og_cmd_shell_list(char *buffer_reply) json_object_set_new(root, "scripts", script_arr); - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { og_script_list_free(&script_list); json_decref(root); return -1; @@ -1069,7 +1069,7 @@ static int og_cmd_get_session(json_t *element, struct og_msg_params *params, json_object_set_new(root, "sessions", array); - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } @@ -1235,7 +1235,7 @@ static int og_cmd_get_modes(json_t *element, struct og_msg_params *params, og_boot_mode_free(&boot_mode_list); json_object_set_new(root, "modes", modes); - ret = json_dump_callback(root, og_json_dump_clients, &og_buffer, 0); + ret = json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII); json_decref(root); return ret; @@ -1782,7 +1782,7 @@ static int og_cmd_get_client_setup(json_t *element, dbi_result_free(result); og_dbi_close(dbi); - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } @@ -2022,7 +2022,7 @@ static int og_cmd_get_center_info(json_t *element, json_object_set_new(root, "name", json_string(center.name)); - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } @@ -2102,7 +2102,7 @@ static int og_cmd_get_client_info(json_t *element, json_object_set_new(root, "id", json_integer(computer.id)); json_object_set_new(root, "ip", json_string(computer.ip)); - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } @@ -3130,7 +3130,7 @@ static int og_cmd_get_room_info(json_t *element, json_object_set_new(root, "gateway", json_string(room.gateway)); json_object_set_new(root, "netmask", json_string(room.netmask)); - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } @@ -3272,7 +3272,7 @@ static int og_cmd_get_hardware(json_t *element, struct og_msg_params *params, json_object_set_new(root, "hardware", array); - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } @@ -3403,7 +3403,7 @@ static int og_cmd_get_software(json_t *element, struct og_msg_params *params, } json_object_set_new(root, "software", software); - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } @@ -3453,7 +3453,7 @@ static const int og_cmd_get_repositories(char *buffer_reply) root = json_object(); json_object_set_new(root, "repositories", repositories); - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } @@ -3616,7 +3616,7 @@ static int og_cmd_images(char *buffer_reply) json_object_set_new(root, "disk", disk_json); - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } @@ -4141,7 +4141,7 @@ static int og_cmd_image_scope_list(json_t *element, if (!scope_image) return -1; - if (json_dump_callback(scope_image, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(scope_image, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(scope_image); return -1; } @@ -4288,7 +4288,7 @@ static int og_cmd_cache_list(json_t *element, struct og_msg_params *params, json_object_set_new(root, "clients", clients); - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } @@ -5763,7 +5763,7 @@ static int og_cmd_scope_get(json_t *element, struct og_msg_params *params, og_dbi_close(dbi); - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } @@ -6336,7 +6336,7 @@ static int og_cmd_schedule_get(json_t *element, struct og_msg_params *params, if (err >= 0) err = json_dump_callback(schedule_root, og_json_dump_clients, - &og_buffer, 0); + &og_buffer, JSON_ENSURE_ASCII); json_decref(schedule_root); @@ -6360,7 +6360,7 @@ static int og_cmd_oglive_list(char *buffer_reply) return -1; } - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } @@ -7757,7 +7757,7 @@ static int og_cmd_get_servers(char *buffer_reply) dbi_result_free(result); og_dbi_close(dbi); - ret = json_dump_callback(root, og_json_dump_clients, &og_buffer, 0); + ret = json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII); json_decref(root); return ret; @@ -7849,7 +7849,7 @@ static int og_cmd_post_server(json_t *element, } id = dbi_conn_sequence_last(dbi->conn, NULL); json_object_set_new(root, "id", json_integer(id)); - ret = json_dump_callback(root, og_json_dump_clients, &og_buffer, 0); + ret = json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII); json_decref(root); dbi_result_free(result); @@ -8058,7 +8058,7 @@ static int og_cmd_get_server_stats(char *buffer_reply) json_object_set_new(swap, "free", json_integer(stats.freeswap)); json_object_set_new(root, "swap", swap); - if (json_dump_callback(root, og_json_dump_clients, &og_buffer, 0)) { + if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) { json_decref(root); return -1; } -- cgit v1.2.3-18-g5258