From bc2f4ec5813f40980f619185e69594712995979a Mon Sep 17 00:00:00 2001 From: Dylan G <1565516+Helloman892@users.noreply.github.com> Date: Thu, 24 Dec 2020 17:12:24 +0000 Subject: [PATCH] Finished up software keyboard input for filenames in http_get. Closes #220. Worth noting that the callback may be shared between this whatever @astronautlevel2 is working on (theme dumping, I think). --- source/remote.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/source/remote.c b/source/remote.c index 71c0597..a82f4e2 100644 --- a/source/remote.c +++ b/source/remote.c @@ -849,6 +849,20 @@ static ParseResult parse_header(struct header * out, httpcContext * context, boo return SUCCESS; } +static SwkbdCallbackResult fat32filter(void *user, const char **ppMessage, const char *text, size_t textlen) +{ + (void)textlen; + (void)user; + *ppMessage = "Input must not contain:\n><\"?;:/\\+,.|[=]"; + if(strpbrk(text, "><\"?;:/\\+,.|[=]")) + { + DEBUG("illegal filename: %s\n", text); + return SWKBD_CALLBACK_CONTINUE; + } + + return SWKBD_CALLBACK_OK; +} + #define ZIP_NOT_AVAILABLE "ZIP not found at this URL\nIf you believe this is an error, please\ncontact the site administrator" /* @@ -990,10 +1004,27 @@ redirect: // goto here if we need to redirect *filename = _header.filename; else { - // TODO: swkbd stuff + const int max_chars = 250; // needs to be heap allocated only because the call site is expected to free it - *filename = malloc(0x20); - sprintf(*filename, "tobesupplied.zip"); + *filename = malloc(max_chars + 5); // + .zip and the null term + + SwkbdState swkbd; + + swkbdInit(&swkbd, SWKBD_TYPE_NORMAL, 2, max_chars / 2); + swkbdSetHintText(&swkbd, "Choose a filename."); + swkbdSetFeatures(&swkbd, SWKBD_PREDICTIVE_INPUT | SWKBD_DARKEN_TOP_SCREEN); + + swkbdSetButton(&swkbd, SWKBD_BUTTON_LEFT, "Cancel", false); + swkbdSetButton(&swkbd, SWKBD_BUTTON_RIGHT, "Download", true); + swkbdSetValidation(&swkbd, SWKBD_NOTEMPTY_NOTBLANK, SWKBD_FILTER_CALLBACK, -1); + swkbdSetFilterCallback(&swkbd, &fat32filter, NULL); + + SwkbdButton button = swkbdInputText(&swkbd, *filename, max_chars); + + if (button != SWKBD_BUTTON_CONFIRM) + return httpcCloseContext(&context); + + strcat(*filename, ".zip"); } }