Revamp SSH authentication code so that user interaction is more
[u/mdw/putty] / macosx / osxwin.m
index 0b0c3ff..ba3a08e 100644 (file)
      */
     [self center];                    /* :-) */
 
+    exited = FALSE;
+
     return self;
 }
 
      * Do so.
      */
     sfree(alert_ctx);
+    if (back)
+       back->free(backhandle);
+    if (ldisc)
+       ldisc_free(ldisc);
+    /* ldisc must be freed before term, since ldisc_free expects term
+     * still to be around. */
+    if (logctx)
+       log_free(logctx);
+    if (term)
+       term_free(term);
     [super dealloc];
 }
 
     char coutput[32];
     int use_coutput = FALSE, special = FALSE, start, end;
 
-printf("n=%d c=U+%04x cm=U+%04x m=%08x\n", n, c, cm, m);
+//printf("n=%d c=U+%04x cm=U+%04x m=%08x\n", n, c, cm, m);
 
     /*
      * FIXME: Alt+numberpad codes.
@@ -846,6 +858,33 @@ printf("n=%d c=U+%04x cm=U+%04x m=%08x\n", n, c, cm, m);
     }
 }
 
+- (void)notifyRemoteExit
+{
+    int exitcode;
+
+    if (!exited && (exitcode = back->exitcode(backhandle)) >= 0)
+       [self endSession:(exitcode == 0)];
+}
+
+- (void)endSession:(int)clean
+{
+    exited = TRUE;
+    if (ldisc) {
+       ldisc_free(ldisc);
+       ldisc = NULL;
+    }
+    if (back) {
+       back->free(backhandle);
+       backhandle = NULL;
+       back = NULL;
+       //FIXME: update specials menu;
+    }
+    if (cfg.close_on_exit == FORCE_ON ||
+       (cfg.close_on_exit == AUTO && clean))
+       [self close];
+    // FIXME: else show restart menu item
+}
+
 @end
 
 int from_backend(void *frontend, int is_stderr, const char *data, int len)
@@ -854,28 +893,23 @@ int from_backend(void *frontend, int is_stderr, const char *data, int len)
     return [win fromBackend:data len:len isStderr:is_stderr];
 }
 
-void frontend_keypress(void *handle)
+int get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
 {
-    /* FIXME */
+    SessionWindow *win = (SessionWindow *)p->frontend;
+    Terminal *term = [win term];
+    return term_get_userpass_input(term, p, in, inlen);
 }
 
-void connection_fatal(void *frontend, char *p, ...)
+void frontend_keypress(void *handle)
 {
-    //SessionWindow *win = (SessionWindow *)frontend;
-    /* FIXME: proper OS X GUI stuff */
-    va_list ap;
-    fprintf(stderr, "FATAL ERROR: ");
-    va_start(ap, p);
-    vfprintf(stderr, p, ap);
-    va_end(ap);
-    fputc('\n', stderr);
-    exit(1);
+    /* FIXME */
 }
 
 void notify_remote_exit(void *frontend)
 {
-    //SessionWindow *win = (SessionWindow *)frontend;
-    /* FIXME */
+    SessionWindow *win = (SessionWindow *)frontend;
+
+    [win notifyRemoteExit];
 }
 
 void ldisc_update(void *frontend, int echo, int edit)
@@ -886,6 +920,13 @@ void ldisc_update(void *frontend, int echo, int edit)
      */
 }
 
+char *get_ttymode(void *frontend, const char *mode)
+{
+    SessionWindow *win = (SessionWindow *)ctx;
+    Terminal *term = [win term];
+    return term_get_ttymode(term, mode);
+}
+
 void update_specials_menu(void *frontend)
 {
     //SessionWindow *win = (SessionWindow *)frontend;
@@ -952,10 +993,11 @@ void palette_reset(void *frontend)
     for (i = 0; i < NEXTCOLOURS; i++) {
        if (i < 216) {
            int r = i / 36, g = (i / 6) % 6, b = i % 6;
-           [win setColour:i+16 r:r/5.0 g:g/5.0 b:b/5.0];
+           r = r ? r*40+55 : 0; g = g ? b*40+55 : 0; b = b ? b*40+55 : 0;
+           [win setColour:i+16 r:r/255.0 g:g/255.0 b:b/255.0];
        } else {
            int shade = i - 216;
-           float fshade = (shade + 1) / (float)(NEXTCOLOURS - 216 + 1);
+           float fshade = (shade * 10 + 8) / 255.0;
            [win setColour:i+16 r:fshade g:fshade b:fshade];
        }
     }