AmendHub

Download:

jcs

/

wifi_da

/

amendments

/

25

window+Rez: Use an off-screen static text field for password storage

For some reason on Mac OS 8+, PasswordDialogFieldFilter doesn't work
properly. The filter proc runs, but it doesn't seem to write to the
already-setup password field storage properly, and it can't see the
DITL id stored to compare to the edited field so we don't get bullets
in place of characters.
 
By using a field in the dialog for storage, we don't need to access
any of the program's variable memory. Seems to work on OS 8 and
still on 6.
 
Bump version to 1.1 for this fix.

jcs made amendment 25 2 months ago
--- wi-fi.h Tue Oct 24 23:23:38 2023 +++ wi-fi.h Sat Jan 27 23:43:26 2024 @@ -31,6 +31,7 @@ #define PASSWORD_DIALOG_ID 1 #define PASSWORD_DIALOG_PASSWORD_FIELD_ID 3 +#define PASSWORD_DIALOG_PASSWORD_STORAGE_ID 4 #define ABOUT_DIALOG_ID 2 --- Wi-Fi DA.π.r Tue Oct 24 23:26:43 2023 +++ Wi-Fi DA.π.r Sat Jan 27 23:58:38 2024 @@ -9,15 +9,16 @@ data 'DITL' (-16000) { }; data 'DITL' (-15999, "CONNECT") { - $"0004 0000 0000 0050 0136 0064 017F 0407" /* .......P.6.d.... */ + $"0005 0000 0000 0050 0136 0064 017F 0407" /* .......P.6.d.... */ $"436F 6E6E 6563 745B 0000 0000 0050 00E6" /* Connect[.....P.. */ $"0064 012F 0406 4361 6E63 656C 0000 0000" /* .d./..Cancel.... */ - $"0032 005A 0042 017D 1000 0000 0000 0032" /* .2.Z.B.}.......2 */ - $"000A 0042 0055 8809 5061 7373 776F 7264" /* ...B.Uà∆Password */ - $"3A72 0000 0000 000A 000A 0029 0182 882B" /* :r.........).Çà+ */ - $"5468 6520 5769 2D46 6920 6E65 7477 6F72" /* The Wi-Fi networ */ - $"6B20 225E 3022 2072 6571 7569 7265 7320" /* k "^0" requires */ - $"6120 7061 7373 776F 7264 2E00" /* a password.. */ + $"0032 005A 0042 017D 1000 0000 0000 0078" /* .2.Z.B.}.......x */ + $"005A 008E 0180 8803 2E2E 2E73 0000 0000" /* .Z.é.Äà....s.... */ + $"0032 000A 0042 0055 8809 5061 7373 776F" /* .2...B.Uà∆Passwo */ + $"7264 3A20 0000 0000 000A 000A 0029 0182" /* rd: .........).Ç */ + $"882B 5468 6520 5769 2D46 6920 6E65 7477" /* à+The Wi-Fi netw */ + $"6F72 6B20 225E 3022 2072 6571 7569 7265" /* ork "^0" require */ + $"7320 6120 7061 7373 776F 7264 2E00" /* s a password.. */ }; data 'DITL' (-15998, "ABOUT", purgeable, preload) { @@ -34,7 +35,7 @@ data 'MENU' (-15999) { }; data 'DLOG' (-15999) { - $"0066 0036 00D6 01C4 0010 0000 0100 0000" /* .f.6.÷.ƒ........ */ + $"0066 0036 00D6 01C3 0010 0000 0100 0000" /* .f.6.÷.√........ */ $"0000 C181 0E57 692D 4669 2050 6173 7377" /* ..¡Å.Wi-Fi Passw */ $"6F72 641C 680A" /* ord.h. */ }; @@ -91,10 +92,10 @@ data 'BNDL' (-16000) { }; data 'vers' (1) { - $"0100 8000 0000 0331 2E30 2631 2E30 20A9" /* ..Ä....1.0&1.0 © */ - $"2032 3032 332C 206A 6F73 6875 6120 7374" /* 2023, joshua st */ - $"6569 6E20 3C6A 6373 406A 6373 2E6F 7267" /* ein <jcs@jcs.org */ - $"3E" /* > */ + $"0110 8000 0000 0331 2E31 2B31 2E31 20A9" /* ..Ä....1.1+1.1 © */ + $"2032 3032 332D 3230 3234 2C20 6A6F 7368" /* 2023-2024, josh */ + $"7561 2073 7465 696E 203C 6A63 7340 6A63" /* ua stein <jcs@jc */ + $"732E 6F72 673E" /* s.org> */ }; data 'ics#' (-16000) { --- window.c Thu Oct 26 09:23:30 2023 +++ window.c Sat Jan 27 23:53:39 2024 @@ -33,6 +33,9 @@ short nwifi_scan_networks = 0; struct wifi_network_entry wifi_menu_networks[nitems(wifi_scan_networks)] = { 0 }; short nwifi_menu_networks = 0; +pascal Boolean WiFiPasswordDialogFieldFilter(DialogPtr dlg, + EventRecord *event, short *hit); + WindowPtr create_window(short ctlrefnum) { @@ -322,7 +325,7 @@ destroy_window(void) void window_mousedown(Point p) { - char pass_storage[256]; + Str255 password; char ssid[64]; Rect r, irect; GrafPtr savePort; @@ -384,13 +387,13 @@ window_mousedown(Point p) ((DialogPeek)dg)->window.port.portRect.bottom, false, &r); MoveWindow(dg, r.left, r.top, false); - memset(pass_storage, 0, sizeof(pass_storage)); - PasswordDialogFieldFilterSetup(PASSWORD_DIALOG_PASSWORD_FIELD_ID, - pass_storage, sizeof(pass_storage)); - ShowWindow(dg); SetPort(dg); + GetDItem(dg, PASSWORD_DIALOG_PASSWORD_STORAGE_ID, &itype, + &ihandle, &irect); + SetIText(ihandle, "\p"); + /* outline ok button */ GetDItem(dg, ok, &itype, &ihandle, &irect); PenSize(3, 3); @@ -399,21 +402,23 @@ window_mousedown(Point p) PenNormal(); for (;;) { - ModalDialog(PasswordDialogFieldFilter, &hit); + ModalDialog(WiFiPasswordDialogFieldFilter, &hit); if (hit == ok || hit == cancel) break; } if (hit != ok) { - PasswordDialogFieldFinish(); DisposDialog(dg); goto menu_done; } - //DEBUG_LOG(("pass is \"%s\"", pass_storage)); - strlcpy(wjr.key, pass_storage, sizeof(wjr.key)); + GetDItem(dg, PASSWORD_DIALOG_PASSWORD_STORAGE_ID, &itype, + &ihandle, &irect); + GetIText(ihandle, &password); + PtoCstr(password); + //DEBUG_LOG(("pass is \"%s\"", password)); + strlcpy(wjr.key, (char *)password, sizeof(wjr.key)); - PasswordDialogFieldFinish(); DisposDialog(dg); } @@ -425,4 +430,67 @@ window_mousedown(Point p) menu_done: SetPort(savePort); -} +} + +pascal Boolean +WiFiPasswordDialogFieldFilter(DialogPtr dlg, EventRecord *event, + short *hit) +{ + Str255 password; + DialogPeek dlgp; + ControlHandle ihandle; + Rect irect; + short sel_start, sel_end, itype; + char key; + + dlgp = (DialogPeek)dlg; + + switch (event->what) { + case keyDown: + case autoKey: + sel_start = (*(dlgp->textH))->selStart; + sel_end = (*(dlgp->textH))->selEnd; + + key = event->message & charCodeMask; + if (event->modifiers & cmdKey) { + /* TODO: implement DlgPaste for cmd+v? */ + event->what = nullEvent; + return FALSE; + } + + GetDItem(dlg, PASSWORD_DIALOG_PASSWORD_STORAGE_ID, &itype, + &ihandle, &irect); + GetIText(ihandle, &password); + PtoCstr(password); + + if (key == 8) { + /* backspace */ + if (sel_start == sel_end && sel_start > 0) + memmove(password + sel_start - 1, password + sel_start, + sizeof(password) - sel_start - 1); + else if (sel_start != sel_end) + memmove(password + sel_start, password + sel_end, + sizeof(password) - sel_end - 1); + } else if (sel_start >= sizeof(password)) { + event->what = nullEvent; + return FALSE; + } else if (key >= ' ' && key <= '~') { + if (sel_start != sel_end) + /* delete selection before making space for new char */ + memmove(password + sel_start, password + sel_end, + sizeof(password) - sel_end - 1); + memmove(password + sel_start + 1, password + sel_start, + sizeof(password) - sel_start - 1); + password[sel_start] = key; + event->message = '•'; + } + password[(*(dlgp->textH))->teLength + 1] = '\0'; + CtoPstr(password); + + SetIText(ihandle, password); + sel_start = 0; + break; + } + + return ModalDialogFilter(dlg, event, hit); +}