+ case IDC_PFWDADD:
+ if (HIWORD(wParam) == BN_CLICKED ||
+ HIWORD(wParam) == BN_DOUBLECLICKED) {
+ char str[sizeof(cfg.portfwd)];
+ char *p;
+ if (IsDlgButtonChecked(hwnd, IDC_PFWDLOCAL))
+ str[0] = 'L';
+ else
+ str[0] = 'R';
+ GetDlgItemText(hwnd, IDC_SPORTEDIT, str+1,
+ sizeof(str) - 2);
+ if (!str[1]) {
+ MessageBox(hwnd,
+ "You need to specify a source port number",
+ "PuTTY Error", MB_OK | MB_ICONERROR);
+ break;
+ }
+ p = str + strlen(str);
+ *p++ = '\t';
+ GetDlgItemText(hwnd, IDC_DPORTEDIT, p,
+ sizeof(str) - 1 - (p - str));
+ if (!*p || !strchr(p, ':')) {
+ MessageBox(hwnd,
+ "You need to specify a destination address\n"
+ "in the form \"host.name:port\"",
+ "PuTTY Error", MB_OK | MB_ICONERROR);
+ break;
+ }
+ p = cfg.portfwd;
+ while (*p) {
+ while (*p)
+ p++;
+ p++;
+ }
+ if ((p - cfg.portfwd) + strlen(str) + 2 <
+ sizeof(cfg.portfwd)) {
+ strcpy(p, str);
+ p[strlen(str) + 1] = '\0';
+ SendDlgItemMessage(hwnd, IDC_PFWDLIST, LB_ADDSTRING,
+ 0, (LPARAM) str);
+ SetDlgItemText(hwnd, IDC_SPORTEDIT, "");
+ SetDlgItemText(hwnd, IDC_DPORTEDIT, "");
+ } else {
+ MessageBox(hwnd, "Too many forwardings",
+ "PuTTY Error", MB_OK | MB_ICONERROR);
+ }
+ }
+ break;
+ case IDC_PFWDREMOVE:
+ if (HIWORD(wParam) != BN_CLICKED &&
+ HIWORD(wParam) != BN_DOUBLECLICKED) break;
+ i = SendDlgItemMessage(hwnd, IDC_PFWDLIST,
+ LB_GETCURSEL, 0, 0);
+ if (i == LB_ERR)
+ MessageBeep(0);
+ else {
+ char *p, *q;
+
+ SendDlgItemMessage(hwnd, IDC_PFWDLIST, LB_DELETESTRING,
+ i, 0);
+ p = cfg.portfwd;
+ while (i > 0) {
+ if (!*p)
+ goto disaster2;
+ while (*p)
+ p++;
+ p++;
+ i--;
+ }
+ q = p;
+ if (!*p)
+ goto disaster2;
+ while (*p)
+ p++;
+ p++;
+ while (*p) {
+ while (*p)
+ *q++ = *p++;
+ *q++ = *p++;
+ }
+ *q = '\0';
+ disaster2:;
+ }
+ break;