From 29f99dbb6620df28181b41bddafbbd5152f7a23d Mon Sep 17 00:00:00 2001 From: jcorporation Date: Fri, 11 Oct 2024 19:31:18 +0200 Subject: [PATCH] Upd: Do not ignore invalid requests, respond with error --- docs/_includes/translating_status.md | 28 ++++++++++++++-------------- src/i18n/json/de-DE.json | 3 ++- src/i18n/json/i18n.json | 18 +++++++++--------- src/i18n/json/phrases.json | 1 + src/web_server/web_server.c | 10 ++++++++++ 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/docs/_includes/translating_status.md b/docs/_includes/translating_status.md index 6b439b22c..a30ff4910 100644 --- a/docs/_includes/translating_status.md +++ b/docs/_includes/translating_status.md @@ -1,14 +1,14 @@ -- bg-BG: 1087 missing phrases -- es-AR: 4 missing phrases -- es-ES: 954 missing phrases -- es-VE: 942 missing phrases -- fi-FI: 939 missing phrases -- fr-FR: 4 missing phrases -- it-IT: 4 missing phrases -- ja-JP: 4 missing phrases -- ko-KR: 4 missing phrases -- nl-NL: 4 missing phrases -- pl-PL: 87 missing phrases -- ru-RU: 35 missing phrases -- zh-Hans: 4 missing phrases -- zh-Hant: 121 missing phrases +- bg-BG: 1088 missing phrases +- es-AR: 5 missing phrases +- es-ES: 955 missing phrases +- es-VE: 943 missing phrases +- fi-FI: 940 missing phrases +- fr-FR: 5 missing phrases +- it-IT: 5 missing phrases +- ja-JP: 5 missing phrases +- ko-KR: 5 missing phrases +- nl-NL: 5 missing phrases +- pl-PL: 88 missing phrases +- ru-RU: 36 missing phrases +- zh-Hans: 5 missing phrases +- zh-Hant: 122 missing phrases diff --git a/src/i18n/json/de-DE.json b/src/i18n/json/de-DE.json index 0faf7c93d..6f7797aea 100644 --- a/src/i18n/json/de-DE.json +++ b/src/i18n/json/de-DE.json @@ -1233,5 +1233,6 @@ "Split a multiline string in lines.": "Teilt einen mehrzeiligen String in einzelne Zeilen.", "Trims a string.": "Trimt einen String.", "Sleeps number of milliseconds.": "Wartet die Spanne von Millisekunden.", - "Read an ascii file.": "Liest eine Textdatei ein." + "Read an ascii file.": "Liest eine Textdatei ein.", + "Invalid API uri, partition not found": "Ungültige API URI, Partition nicht gefunden." } \ No newline at end of file diff --git a/src/i18n/json/i18n.json b/src/i18n/json/i18n.json index 54c66cbb8..0d48ab070 100644 --- a/src/i18n/json/i18n.json +++ b/src/i18n/json/i18n.json @@ -2,13 +2,13 @@ "default": {"desc":"Browser default", "missingPhrases": 0}, "de-DE": {"desc":"Deutsch (de-DE)", "missingPhrases": 0}, "en-US": {"desc":"English (en-US)", "missingPhrases": 0}, - "es-AR": {"desc":"Español (es-AR)", "missingPhrases": 4}, - "fr-FR": {"desc":"Français (fr-FR)", "missingPhrases": 4}, - "it-IT": {"desc":"Italiano (it-IT)", "missingPhrases": 4}, - "ja-JP": {"desc":"日本語 (ja-JP)", "missingPhrases": 4}, - "ko-KR": {"desc":"한국어 (ko-KR)", "missingPhrases": 4}, - "nl-NL": {"desc":"Nederlands (nl-NL)", "missingPhrases": 4}, - "pl-PL": {"desc":"Polish (pl-PL)", "missingPhrases": 87}, - "ru-RU": {"desc":"Russian (ru-RU)", "missingPhrases": 35}, - "zh-Hans": {"desc":"简体中文 (zh-Hans)", "missingPhrases": 4} + "es-AR": {"desc":"Español (es-AR)", "missingPhrases": 5}, + "fr-FR": {"desc":"Français (fr-FR)", "missingPhrases": 5}, + "it-IT": {"desc":"Italiano (it-IT)", "missingPhrases": 5}, + "ja-JP": {"desc":"日本語 (ja-JP)", "missingPhrases": 5}, + "ko-KR": {"desc":"한국어 (ko-KR)", "missingPhrases": 5}, + "nl-NL": {"desc":"Nederlands (nl-NL)", "missingPhrases": 5}, + "pl-PL": {"desc":"Polish (pl-PL)", "missingPhrases": 88}, + "ru-RU": {"desc":"Russian (ru-RU)", "missingPhrases": 36}, + "zh-Hans": {"desc":"简体中文 (zh-Hans)", "missingPhrases": 5} } diff --git a/src/i18n/json/phrases.json b/src/i18n/json/phrases.json index f3e81bef4..7072911b9 100644 --- a/src/i18n/json/phrases.json +++ b/src/i18n/json/phrases.json @@ -394,6 +394,7 @@ {"term":"Insert mode"}, {"term":"Interval"}, {"term":"Invalid API request"}, +{"term":"Invalid API uri, partition not found"}, {"term":"Invalid MPD search expression"}, {"term":"Invalid URI"}, {"term":"Invalid backend uri"}, diff --git a/src/web_server/web_server.c b/src/web_server/web_server.c index 429e0522e..f94fc0862 100644 --- a/src/web_server/web_server.c +++ b/src/web_server/web_server.c @@ -727,6 +727,10 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { //check partition if (get_partition_from_uri(nc, hm, frontend_nc_data) == false) { MYMPD_LOG_ERROR(NULL, "API request without partition"); + sds response = jsonrpc_respond_message(sdsempty(), GENERAL_API_UNKNOWN, 0, + JSONRPC_FACILITY_GENERAL, JSONRPC_SEVERITY_ERROR, "Invalid API uri, partition not found"); + webserver_send_data(nc, response, sdslen(response), EXTRA_HEADERS_JSON_CONTENT); + FREE_SDS(response); break; } //body @@ -777,6 +781,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { //check partition if (get_partition_from_uri(nc, hm, frontend_nc_data) == false) { MYMPD_LOG_ERROR(NULL, "Websocket request without partition"); + webserver_send_error(nc, 404, "Invalid websocket uri, partition not found"); break; } mg_ws_upgrade(nc, hm, NULL); @@ -789,6 +794,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { //check partition if (get_partition_from_uri(nc, hm, frontend_nc_data) == false) { MYMPD_LOG_ERROR(NULL, "Stream request without partition"); + webserver_send_error(nc, 404, "Invalid stream uri, partition not found"); break; } struct t_list_node *node = list_get_node(&mg_user_data->stream_uris, frontend_nc_data->partition); @@ -819,6 +825,10 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { //check partition if (get_partition_from_uri(nc, hm, frontend_nc_data) == false) { MYMPD_LOG_ERROR(NULL, "script-api request without partition"); + sds response = jsonrpc_respond_message(sdsempty(), GENERAL_API_UNKNOWN, 0, + JSONRPC_FACILITY_GENERAL, JSONRPC_SEVERITY_ERROR, "Invalid API uri, partition not found"); + webserver_send_data(nc, response, sdslen(response), EXTRA_HEADERS_JSON_CONTENT); + FREE_SDS(response); break; } sds body = sdsnewlen(hm->body.buf, hm->body.len);