X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/f6f450e2b1db4ae729c6df593dbbbff842bd6f3b..12bff6dc1d8d9d0eb9a20570216f87387cac59e9:/window.c diff --git a/window.c b/window.c index 40d9ae10..c9d8df55 100644 --- a/window.c +++ b/window.c @@ -55,6 +55,7 @@ #define WM_IGNORE_CLIP (WM_XUSER + 2) #define WM_FULLSCR_ON_MAX (WM_XUSER + 3) +#define WM_AGENT_CALLBACK (WM_XUSER + 4) /* Needed for Chinese support and apparently not always defined. */ #ifndef VK_PROCESSKEY @@ -122,6 +123,13 @@ Config cfg; /* exported to windlg.c */ extern struct sesslist sesslist; /* imported from windlg.c */ +struct agent_callback { + void (*callback)(void *, void *, int); + void *callback_ctx; + void *data; + int len; +}; + #define FONT_NORMAL 0 #define FONT_BOLD 1 #define FONT_UNDERLINE 2 @@ -628,11 +636,11 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) * Start up the telnet connection. */ { - char *error; + const char *error; char msg[1024], *title; char *realhost; - error = back->init((void *)term, &backhandle, &cfg, + error = back->init(NULL, &backhandle, &cfg, cfg.host, cfg.port, &realhost, cfg.tcp_nodelay); back->provide_logctx(backhandle, logctx); if (error) { @@ -922,13 +930,15 @@ void set_raw_mouse_mode(void *frontend, int activate) void connection_fatal(void *frontend, char *fmt, ...) { va_list ap; - char stuff[200], morestuff[100]; + char *stuff, morestuff[100]; va_start(ap, fmt); - vsprintf(stuff, fmt, ap); + stuff = dupvprintf(fmt, ap); va_end(ap); sprintf(morestuff, "%.70s Fatal Error", appname); MessageBox(hwnd, stuff, morestuff, MB_ICONERROR | MB_OK); + sfree(stuff); + if (cfg.close_on_exit == FORCE_ON) PostQuitMessage(1); else { @@ -945,13 +955,14 @@ void connection_fatal(void *frontend, char *fmt, ...) void cmdline_error(char *fmt, ...) { va_list ap; - char stuff[200], morestuff[100]; + char *stuff, morestuff[100]; va_start(ap, fmt); - vsprintf(stuff, fmt, ap); + stuff = dupvprintf(fmt, ap); va_end(ap); sprintf(morestuff, "%.70s Command Line Error", appname); MessageBox(hwnd, stuff, morestuff, MB_ICONERROR | MB_OK); + sfree(stuff); exit(1); } @@ -2575,6 +2586,14 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, SetCursor(LoadCursor(NULL, IDC_ARROW)); return TRUE; } + break; + case WM_AGENT_CALLBACK: + { + struct agent_callback *c = (struct agent_callback *)lParam; + c->callback(c->callback_ctx, c->data, c->len); + sfree(c); + } + return 0; default: if (message == wm_mousewheel || message == WM_MOUSEWHEEL) { int shift_pressed=0, control_pressed=0; @@ -4286,13 +4305,14 @@ void optimised_move(void *frontend, int to, int from, int lines) void fatalbox(char *fmt, ...) { va_list ap; - char stuff[200], morestuff[100]; + char *stuff, morestuff[100]; va_start(ap, fmt); - vsprintf(stuff, fmt, ap); + stuff = dupvprintf(fmt, ap); va_end(ap); sprintf(morestuff, "%.70s Fatal Error", appname); MessageBox(hwnd, stuff, morestuff, MB_ICONERROR | MB_OK); + sfree(stuff); cleanup_exit(1); } @@ -4302,14 +4322,15 @@ void fatalbox(char *fmt, ...) void modalfatalbox(char *fmt, ...) { va_list ap; - char stuff[200], morestuff[100]; + char *stuff, morestuff[100]; va_start(ap, fmt); - vsprintf(stuff, fmt, ap); + stuff = dupvprintf(fmt, ap); va_end(ap); sprintf(morestuff, "%.70s Fatal Error", appname); MessageBox(hwnd, stuff, morestuff, MB_SYSTEMMODAL | MB_ICONERROR | MB_OK); + sfree(stuff); cleanup_exit(1); } @@ -4621,3 +4642,19 @@ void frontend_keypress(void *handle) */ return; } + +int from_backend(void *frontend, int is_stderr, const char *data, int len) +{ + return term_data(term, is_stderr, data, len); +} + +void agent_schedule_callback(void (*callback)(void *, void *, int), + void *callback_ctx, void *data, int len) +{ + struct agent_callback *c = snew(struct agent_callback); + c->callback = callback; + c->callback_ctx = callback_ctx; + c->data = data; + c->len = len; + PostMessage(hwnd, WM_AGENT_CALLBACK, 0, (LPARAM)c); +}