From 708ad83ead9a9f98db6d424e17bcc05694df2875 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Mon, 25 Feb 2019 20:12:36 -0500 Subject: [PATCH] Renamed webShow to webConfigShow. Added webConfigSetWhitelist. --- nx/include/switch/applets/web.h | 10 +++++++++- nx/source/applets/web.c | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/nx/include/switch/applets/web.h b/nx/include/switch/applets/web.h index dbb9a544..6d6eb286 100644 --- a/nx/include/switch/applets/web.h +++ b/nx/include/switch/applets/web.h @@ -90,10 +90,18 @@ Result webWifiShow(WebWifiConfig* config, WebWifiReturnValue *out); */ void webPageCreate(WebCommonConfig* config, const char* url); +/** + * @brief Sets the whitelist, only available with config created by \ref webPageCreate. + * @note If the whitelist isn't formatted properly, the applet will exit briefly after the applet is launched. + * @param config WebCommonConfig object. + * @param whitelist Whitelist string, each line is a regex for each whitelisted URL. + */ +void webConfigSetWhitelist(WebCommonConfig* config, const char* whitelist); + /** * @brief Launches the {web applet} with the specified config and waits for it to exit. * @param config WebCommonConfig object. * @param out Optional output applet reply data, can be NULL. */ -Result webShow(WebCommonConfig* config, WebCommonReturnValue *out); +Result webConfigShow(WebCommonConfig* config, WebCommonReturnValue *out); diff --git a/nx/source/applets/web.c b/nx/source/applets/web.c index b12ba276..4743e543 100644 --- a/nx/source/applets/web.c +++ b/nx/source/applets/web.c @@ -72,6 +72,11 @@ static void _webArgInitialize(WebCommonConfig* config, AppletId appletid, WebShi config->version = 0x20000; // [1.0.0+] version } +WebShimKind _webGetShimKind(WebCommonConfig* config) { + WebArgHeader *hdr = (WebArgHeader*)config->arg.data; + return hdr->shimKind; +} + static void _webTLVWrite(WebCommonTLVStorage *storage, u16 type, const void* argdata, u16 argdata_size, u16 argdata_size_total) { size_t i, count, offset; u8 *dataptr = storage->data; @@ -158,7 +163,12 @@ void webPageCreate(WebCommonConfig* config, const char* url) { _webConfigSetUrl(config, url); } -Result webShow(WebCommonConfig* config, WebCommonReturnValue *out) { +void webConfigSetWhitelist(WebCommonConfig* config, const char* whitelist) { + if (_webGetShimKind(config) != WebShimKind_Web) return; + _webConfigSetString(config, 0xA, whitelist, 0x1000); +} + +Result webConfigShow(WebCommonConfig* config, WebCommonReturnValue *out) { return _webShow(config->appletid, config->version, &config->arg, sizeof(config->arg), out, sizeof(*out)); }