Slightly better than null verify_ssh_host_key(). It's broken in more ways
[u/mdw/putty] / mac / mac.c
CommitLineData
538bfd1d 1/* $Id: mac.c,v 1.54 2003/03/06 23:44:47 ben Exp $ */
d082ac49 2/*
f854b482 3 * Copyright (c) 1999, 2003 Ben Harris
d082ac49 4 * All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27/*
28 * mac.c -- miscellaneous Mac-specific routines
29 */
30
31#include <MacTypes.h>
97cfddb2 32#include <AEDataModel.h>
33#include <AppleEvents.h>
d082ac49 34#include <Quickdraw.h>
35#include <Fonts.h>
36#include <MacWindows.h>
37#include <Menus.h>
38#include <TextEdit.h>
39#include <Appearance.h>
40#include <CodeFragments.h>
41#include <Dialogs.h>
42#include <Devices.h>
43#include <DiskInit.h>
44#include <Gestalt.h>
bf873e8e 45#include <LowMem.h>
9ef3c1ca 46#include <Navigation.h>
d082ac49 47#include <Resources.h>
36577dc9 48#include <Script.h>
8768ce31 49#include <TextCommon.h>
d082ac49 50#include <ToolUtils.h>
8768ce31 51#include <UnicodeConverter.h>
d082ac49 52
53#include <assert.h>
54#include <limits.h>
55#include <stdarg.h>
56#include <stdlib.h> /* putty.h needs size_t */
57#include <stdio.h> /* for vsprintf */
58
59#define PUTTY_DO_GLOBALS
60
61#include "macresid.h"
62#include "putty.h"
0c4b7799 63#include "ssh.h"
538bfd1d 64#include "terminal.h"
d082ac49 65#include "mac.h"
66
0c4b7799 67Session *sesslist;
68
d082ac49 69static int cold = 1;
97cfddb2 70static int borednow = FALSE;
d082ac49 71struct mac_gestalts mac_gestalts;
0ec4b50f 72UInt32 sleeptime;
d082ac49 73
74static void mac_startup(void);
75static void mac_eventloop(void);
76#pragma noreturn (mac_eventloop)
77static void mac_event(EventRecord *);
78static void mac_contentclick(WindowPtr, EventRecord *);
79static void mac_growwindow(WindowPtr, EventRecord *);
80static void mac_activatewindow(WindowPtr, EventRecord *);
0c5c7f5c 81static void mac_suspendresume(EventRecord *);
d082ac49 82static void mac_activateabout(WindowPtr, EventRecord *);
83static void mac_updatewindow(WindowPtr);
ebd78b62 84static void mac_updatelicence(WindowPtr);
d082ac49 85static void mac_keypress(EventRecord *);
86static int mac_windowtype(WindowPtr);
87static void mac_menucommand(long);
ebd78b62 88static void mac_openlicence(void);
d082ac49 89static void mac_adjustcursor(RgnHandle);
90static void mac_adjustmenus(void);
91static void mac_closewindow(WindowPtr);
92static void mac_zoomwindow(WindowPtr, short);
0c4b7799 93#pragma noreturn (cleanup_exit)
d082ac49 94
95struct mac_windows {
96 WindowPtr about;
97 WindowPtr licence;
98};
99
100struct mac_windows windows;
101
102int main (int argc, char **argv) {
103
104 mac_startup();
105 mac_eventloop();
106}
107
108#pragma noreturn (main)
109
110static void mac_startup(void) {
111 Handle menuBar;
8768ce31 112 TECInfoHandle ti;
d082ac49 113
fc34fbaf 114#if !TARGET_API_MAC_CARBON
d082ac49 115 /* Init Memory Manager */
116 MaxApplZone();
117 /* Init QuickDraw */
118 InitGraf(&qd.thePort);
119 /* Init Font Manager */
120 InitFonts();
121 /* Init Window Manager */
122 InitWindows();
123 /* Init Menu Manager */
124 InitMenus();
125 /* Init TextEdit */
126 TEInit();
127 /* Init Dialog Manager */
f3ab148c 128 InitDialogs(NULL);
fc34fbaf 129#endif
d082ac49 130 cold = 0;
131
56ed4cf7 132 /* Get base system version (only used if there's no better selector) */
133 if (Gestalt(gestaltSystemVersion, &mac_gestalts.sysvers) != noErr ||
6e1063b1 134 (mac_gestalts.sysvers &= 0xffff) < 0x700)
56ed4cf7 135 fatalbox("PuTTY requires System 7 or newer");
d082ac49 136 /* Find out if we've got Color Quickdraw */
137 if (Gestalt(gestaltQuickdrawVersion, &mac_gestalts.qdvers) != noErr)
138 mac_gestalts.qdvers = gestaltOriginalQD;
139 /* ... and the Appearance Manager? */
140 if (Gestalt(gestaltAppearanceVersion, &mac_gestalts.apprvers) != noErr)
141 if (Gestalt(gestaltAppearanceAttr, NULL) == noErr)
142 mac_gestalts.apprvers = 0x0100;
143 else
144 mac_gestalts.apprvers = 0;
145#if TARGET_RT_MAC_CFM
146 /* Paranoia: Did we manage to pull in AppearanceLib? */
147 if (&RegisterAppearanceClient == kUnresolvedCFragSymbolAddress)
148 mac_gestalts.apprvers = 0;
149#endif
1fc898ea 150#if TARGET_CPU_68K
151 mac_gestalts.cntlattr = 0;
152 mac_gestalts.windattr = 0;
153#else
d082ac49 154 /* Mac OS 8.5 Control Manager (proportional scrollbars)? */
1fc898ea 155 if (Gestalt(gestaltControlMgrAttr, &mac_gestalts.cntlattr) != noErr ||
156 &SetControlViewSize == kUnresolvedCFragSymbolAddress)
d082ac49 157 mac_gestalts.cntlattr = 0;
158 /* Mac OS 8.5 Window Manager? */
1fc898ea 159 if (Gestalt(gestaltWindowMgrAttr, &mac_gestalts.windattr) != noErr ||
160 &SetWindowContentColor == kUnresolvedCFragSymbolAddress)
d082ac49 161 mac_gestalts.windattr = 0;
d49b7117 162 /* Mac OS 8.5 Menu Manager? */
163 if (Gestalt(gestaltMenuMgrAttr, &mac_gestalts.menuattr) != noErr)
164 mac_gestalts.menuattr = 0;
1fc898ea 165#endif
8768ce31 166 /* Text Encoding Conversion Manager? */
167 if (
168#if TARGET_RT_MAC_CFM
169 &TECGetInfo == kUnresolvedCFragSymbolAddress ||
170#else
171 InitializeUnicodeConverter(NULL) != noErr ||
172#endif
173 TECGetInfo(&ti) != noErr)
174 mac_gestalts.encvvers = 0;
175 else {
176 mac_gestalts.encvvers = (*ti)->tecVersion;
379836ca 177 mac_gestalts.uncvattr = (*ti)->tecUnicodeConverterFeatures;
8768ce31 178 DisposeHandle((Handle)ti);
179 }
9ef3c1ca 180 /* Navigation Services? */
181 if (NavServicesAvailable())
182 mac_gestalts.navsvers = NavLibraryVersion();
183 else
184 mac_gestalts.navsvers = 0;
97cfddb2 185
f6fc0010 186 sk_init();
2beb0fb0 187
d082ac49 188 /* We've been tested with the Appearance Manager */
189 if (mac_gestalts.apprvers != 0)
190 RegisterAppearanceClient();
191
192 menuBar = GetNewMBar(128);
193 if (menuBar == NULL)
194 fatalbox("Unable to create menu bar.");
195 SetMenuBar(menuBar);
196 AppendResMenu(GetMenuHandle(mApple), 'DRVR');
d49b7117 197 if (mac_gestalts.menuattr & gestaltMenuMgrAquaLayoutMask)
198 DeleteMenuItem(GetMenuHandle(mFile), iQuit);
d082ac49 199 mac_adjustmenus();
200 DrawMenuBar();
201 InitCursor();
202 windows.about = NULL;
203 windows.licence = NULL;
204
ffa79828 205 default_protocol = be_default_protocol;
206 /* Find the appropriate default port. */
207 {
ffa79828 208 int i;
1adaeb2e 209 default_port = 0; /* illegal */
ffa79828 210 for (i = 0; backends[i].backend != NULL; i++)
211 if (backends[i].protocol == default_protocol) {
212 default_port = backends[i].backend->default_port;
213 break;
214 }
215 }
0c4b7799 216 flags = FLAG_INTERACTIVE;
217
fc34fbaf 218#if !TARGET_API_MAC_CARBON
bf873e8e 219 {
220 short vol;
221 long dirid;
222
223 /* Set the default directory for loading and saving settings. */
224 /* XXX Should we create it? */
225 if (get_session_dir(FALSE, &vol, &dirid) == noErr) {
226 LMSetSFSaveDisk(-vol);
227 LMSetCurDirStore(dirid);
228 }
229 }
fc34fbaf 230#endif
97cfddb2 231
232 /* Install Apple Event handlers. */
d70e3b83 233 AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
234 NewAEEventHandlerUPP(&mac_aevt_oapp), 0, FALSE);
235 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
236 NewAEEventHandlerUPP(&mac_aevt_odoc), 0, FALSE);
237 AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
238 NewAEEventHandlerUPP(&mac_aevt_pdoc), 0, FALSE);
97cfddb2 239 AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
240 NewAEEventHandlerUPP(&mac_aevt_quit), 0, FALSE);
d082ac49 241}
242
243static void mac_eventloop(void) {
244 Boolean gotevent;
245 EventRecord event;
246 RgnHandle cursrgn;
247
248 cursrgn = NewRgn();
0ec4b50f 249 sleeptime = 0;
d082ac49 250 for (;;) {
251 mac_adjustcursor(cursrgn);
0ec4b50f 252 gotevent = WaitNextEvent(everyEvent, &event, sleeptime, cursrgn);
253 /*
254 * XXX For now, limit sleep time to 1/10 s to work around
255 * wake-before-sleep race in MacTCP code.
256 */
257 sleeptime = 6;
d082ac49 258 mac_adjustcursor(cursrgn);
0ec4b50f 259 if (gotevent) {
260 /* Ensure we get a null event when the real ones run out. */
261 sleeptime = 0;
d082ac49 262 mac_event(&event);
0ec4b50f 263 if (borednow)
264 cleanup_exit(0);
265 }
f6fc0010 266 sk_poll();
0ec4b50f 267 if (!gotevent)
268 mac_pollterm();
d082ac49 269 }
270 DisposeRgn(cursrgn);
271}
272
273static void mac_event(EventRecord *event) {
274 short part;
275 WindowPtr window;
d082ac49 276
277 switch (event->what) {
278 case mouseDown:
279 part = FindWindow(event->where, &window);
280 switch (part) {
281 case inMenuBar:
282 mac_adjustmenus();
283 mac_menucommand(MenuSelect(event->where));
284 break;
fc34fbaf 285#if !TARGET_API_MAC_CARBON
d082ac49 286 case inSysWindow:
287 SystemClick(event, window);
288 break;
fc34fbaf 289#endif
d082ac49 290 case inContent:
291 if (window != FrontWindow())
292 /* XXX: check for movable modal dboxes? */
293 SelectWindow(window);
294 else
295 mac_contentclick(window, event);
296 break;
297 case inGoAway:
298 if (TrackGoAway(window, event->where))
299 mac_closewindow(window);
300 break;
301 case inDrag:
302 /* XXX: moveable modal check? */
fc34fbaf 303#if TARGET_API_MAC_CARBON
304 {
305 BitMap screenBits;
306
307 GetQDGlobalsScreenBits(&screenBits);
308 DragWindow(window, event->where, &screenBits.bounds);
309 }
310#else
d082ac49 311 DragWindow(window, event->where, &qd.screenBits.bounds);
fc34fbaf 312#endif
d082ac49 313 break;
314 case inGrow:
315 mac_growwindow(window, event);
316 break;
317 case inZoomIn:
318 case inZoomOut:
319 if (TrackBox(window, event->where, part))
320 mac_zoomwindow(window, part);
321 break;
322 }
323 break;
324 case keyDown:
325 case autoKey:
326 mac_keypress(event);
327 break;
328 case activateEvt:
329 mac_activatewindow((WindowPtr)event->message, event);
330 break;
331 case updateEvt:
332 mac_updatewindow((WindowPtr)event->message);
333 break;
fc34fbaf 334#if !TARGET_API_MAC_CARBON
d082ac49 335 case diskEvt:
336 if (HiWord(event->message) != noErr) {
fc34fbaf 337 Point pt;
338
d082ac49 339 SetPt(&pt, 120, 120);
340 DIBadMount(pt, event->message);
341 }
342 break;
fc34fbaf 343#endif
0c5c7f5c 344 case osEvt:
345 switch ((event->message & osEvtMessageMask) >> 24) {
346 case suspendResumeMessage:
347 mac_suspendresume(event);
348 break;
349 }
350 break;
97cfddb2 351 case kHighLevelEvent:
352 AEProcessAppleEvent(event); /* errors? */
353 break;
d082ac49 354 }
355}
356
f854b482 357static void mac_contentclick(WindowPtr window, EventRecord *event)
358{
d082ac49 359
f854b482 360 if (mac_wininfo(window)->click != NULL)
361 (*mac_wininfo(window)->click)(window, event);
d082ac49 362}
363
f854b482 364static void mac_growwindow(WindowPtr window, EventRecord *event)
365{
d082ac49 366
f854b482 367 if (mac_wininfo(window)->grow != NULL)
368 (*mac_wininfo(window)->grow)(window, event);
d082ac49 369}
370
f854b482 371static void mac_activatewindow(WindowPtr window, EventRecord *event)
372{
d082ac49 373
d082ac49 374 mac_adjustmenus();
f854b482 375 if (mac_wininfo(window)->activate != NULL)
376 (*mac_wininfo(window)->activate)(window, event);
d082ac49 377}
378
fc34fbaf 379static void mac_updatewindow(WindowPtr window)
380{
d082ac49 381
f854b482 382 if (mac_wininfo(window)->update != NULL)
383 (*mac_wininfo(window)->update)(window);
d082ac49 384}
385
386/*
387 * Work out what kind of window we're dealing with.
d082ac49 388 */
347bfcd7 389static int mac_windowtype(WindowPtr window)
390{
391
392#if !TARGET_API_MAC_CARBON
393 if (GetWindowKind(window) < 0)
d082ac49 394 return wDA;
347bfcd7 395#endif
396 return ((WinInfo *)GetWRefCon(window))->wtype;
d082ac49 397}
398
399/*
400 * Handle a key press
401 */
402static void mac_keypress(EventRecord *event) {
403 WindowPtr window;
404
3fa61577 405 window = mac_frontwindow();
d082ac49 406 /*
407 * Check for a command-key combination, but ignore it if it counts
408 * as a meta-key combination and we're in a terminal window.
409 */
410 if (event->what == keyDown && (event->modifiers & cmdKey) /*&&
411 !((event->modifiers & cfg.meta_modifiers) == cfg.meta_modifiers &&
412 mac_windowtype(window) == wTerminal)*/) {
413 mac_adjustmenus();
414 mac_menucommand(MenuKey(event->message & charCodeMask));
415 } else {
3fa61577 416 if (window != NULL && mac_wininfo(window)->key != NULL)
f854b482 417 (*mac_wininfo(window)->key)(window, event);
d082ac49 418 }
419}
420
421static void mac_menucommand(long result) {
422 short menu, item;
d082ac49 423 WindowPtr window;
fc34fbaf 424#if !TARGET_API_MAC_CARBON
425 Str255 da;
426#endif
d082ac49 427
428 menu = HiWord(result);
429 item = LoWord(result);
3fa61577 430 window = mac_frontwindow();
d082ac49 431 /* Things which do the same whatever window we're in. */
432 switch (menu) {
433 case mApple:
434 switch (item) {
435 case iAbout:
436 mac_openabout();
437 goto done;
cc2be455 438#if !TARGET_API_MAC_CARBON
d082ac49 439 default:
440 GetMenuItemText(GetMenuHandle(mApple), item, da);
441 OpenDeskAcc(da);
442 goto done;
cc2be455 443#endif
d082ac49 444 }
445 break;
446 case mFile:
447 switch (item) {
448 case iNew:
449 mac_newsession();
450 goto done;
ce283213 451 case iOpen:
452 mac_opensession();
453 goto done;
d082ac49 454 case iClose:
455 mac_closewindow(window);
456 goto done;
b537dd42 457 case iSave:
458 mac_savesession();
459 goto done;
460 case iSaveAs:
461 mac_savesessionas();
462 goto done;
5211281f 463 case iDuplicate:
464 mac_dupsession();
465 goto done;
d082ac49 466 case iQuit:
0c4b7799 467 cleanup_exit(0);
d082ac49 468 goto done;
469 }
470 break;
471 }
472 /* If we get here, handling is up to window-specific code. */
3fa61577 473 if (window != NULL && mac_wininfo(window)->menu != NULL)
f854b482 474 (*mac_wininfo(window)->menu)(window, menu, item);
475
d082ac49 476 done:
477 HiliteMenu(0);
478}
479
d082ac49 480static void mac_closewindow(WindowPtr window) {
481
482 switch (mac_windowtype(window)) {
fc34fbaf 483#if !TARGET_API_MAC_CARBON
d082ac49 484 case wDA:
347bfcd7 485 CloseDeskAcc(GetWindowKind(window));
d082ac49 486 break;
fc34fbaf 487#endif
f854b482 488 default:
489 if (mac_wininfo(window)->close != NULL)
490 (*mac_wininfo(window)->close)(window);
d082ac49 491 break;
492 }
493}
494
0c5c7f5c 495static void mac_suspendresume(EventRecord *event)
496{
497 WindowPtr front;
498 EventRecord fakeevent;
499
500 /*
501 * We're called either before we're suspended or after we're
502 * resumed, so we're the front application at this point.
503 */
504 front = FrontWindow();
505 if (front != NULL) {
506 fakeevent.what = activateEvt;
507 fakeevent.message = (UInt32)front;
508 fakeevent.when = event->when;
509 fakeevent.where = event->where;
510 fakeevent.modifiers =
511 (event->message & resumeFlag) ? activeFlag : 0;
512 mac_activatewindow(front, &fakeevent);
513 }
514}
515
d082ac49 516static void mac_zoomwindow(WindowPtr window, short part) {
517
518 /* FIXME: do something */
519}
520
521/*
522 * Make the menus look right before the user gets to see them.
523 */
fc34fbaf 524#if TARGET_API_MAC_CARBON
fc34fbaf 525#define EnableItem EnableMenuItem
526#define DisableItem DisableMenuItem
527#endif
d082ac49 528static void mac_adjustmenus(void) {
529 WindowPtr window;
530 MenuHandle menu;
531
3fa61577 532 window = mac_frontwindow();
d082ac49 533 menu = GetMenuHandle(mApple);
534 EnableItem(menu, 0);
535 EnableItem(menu, iAbout);
536
537 menu = GetMenuHandle(mFile);
538 EnableItem(menu, 0);
539 EnableItem(menu, iNew);
540 if (window != NULL)
541 EnableItem(menu, iClose);
542 else
543 DisableItem(menu, iClose);
544 EnableItem(menu, iQuit);
545
3fa61577 546 if (window != NULL && mac_wininfo(window)->adjustmenus != NULL)
f854b482 547 (*mac_wininfo(window)->adjustmenus)(window);
548 else {
b537dd42 549 DisableItem(menu, iSave);
550 DisableItem(menu, iSaveAs);
5211281f 551 DisableItem(menu, iDuplicate);
d082ac49 552 menu = GetMenuHandle(mEdit);
553 DisableItem(menu, 0);
7dcd1f87 554 menu = GetMenuHandle(mWindow);
555 DisableItem(menu, 0); /* Until we get more than 1 item on it. */
d082ac49 556 }
557 DrawMenuBar();
558}
559
560/*
561 * Make sure the right cursor's being displayed.
562 */
563static void mac_adjustcursor(RgnHandle cursrgn) {
564 Point mouse;
565 WindowPtr window, front;
566 short part;
fc34fbaf 567#if TARGET_API_MAC_CARBON
568 Cursor arrow;
569 RgnHandle visrgn;
570#endif
d082ac49 571
572 GetMouse(&mouse);
573 LocalToGlobal(&mouse);
574 part = FindWindow(mouse, &window);
575 front = FrontWindow();
576 if (part != inContent || window == NULL || window != front) {
577 /* Cursor isn't in the front window, so switch to arrow */
fc34fbaf 578#if TARGET_API_MAC_CARBON
579 GetQDGlobalsArrow(&arrow);
580 SetCursor(&arrow);
581#else
d082ac49 582 SetCursor(&qd.arrow);
fc34fbaf 583#endif
d082ac49 584 SetRectRgn(cursrgn, SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX);
fc34fbaf 585 if (front != NULL) {
586#if TARGET_API_MAC_CARBON
587 visrgn = NewRgn();
588 GetPortVisibleRegion(GetWindowPort(front), visrgn);
589 DiffRgn(cursrgn, visrgn, cursrgn);
590 DisposeRgn(visrgn);
591#else
d082ac49 592 DiffRgn(cursrgn, front->visRgn, cursrgn);
fc34fbaf 593#endif
594 }
d082ac49 595 } else {
f854b482 596 if (mac_wininfo(window)->adjustcursor != NULL)
597 (*mac_wininfo(window)->adjustcursor)(window, mouse, cursrgn);
598 else {
fc34fbaf 599#if TARGET_API_MAC_CARBON
600 GetQDGlobalsArrow(&arrow);
601 SetCursor(&arrow);
602 GetPortVisibleRegion(GetWindowPort(window), cursrgn);
603#else
d082ac49 604 SetCursor(&qd.arrow);
605 CopyRgn(window->visRgn, cursrgn);
fc34fbaf 606#endif
d082ac49 607 }
608 }
609}
610
d70e3b83 611pascal OSErr mac_aevt_quit(const AppleEvent *req, AppleEvent *reply,
97cfddb2 612 long refcon)
613{
d70e3b83 614 DescType type;
615 Size size;
616
617 if (AEGetAttributePtr(req, keyMissedKeywordAttr, typeWildCard,
618 &type, NULL, 0, &size) == noErr)
619 return errAEParamMissed;
97cfddb2 620
621 borednow = 1;
622 return noErr;
623}
624
0c4b7799 625void cleanup_exit(int status)
626{
d082ac49 627
713b8b7a 628#if !TARGET_RT_MAC_CFM
8768ce31 629 if (mac_gestalts.encvvers != 0)
630 TerminateUnicodeConverter();
713b8b7a 631#endif
27a3458f 632 sk_cleanup();
0c4b7799 633 exit(status);
d082ac49 634}
635
2beb0fb0 636/* This should only kill the current session, not the whole application. */
637void connection_fatal(void *fontend, char *fmt, ...) {
638 va_list ap;
639 Str255 stuff;
640
641 va_start(ap, fmt);
642 /* We'd like stuff to be a Pascal string */
643 stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap);
644 va_end(ap);
645 ParamText(stuff, NULL, NULL, NULL);
646 StopAlert(128, NULL);
04b0fa02 647 cleanup_exit(1);
2beb0fb0 648}
649
0c4b7799 650/* Null SSH agent client -- never finds an agent. */
651
652int agent_exists(void)
653{
654
655 return FALSE;
656}
657
658void agent_query(void *in, int inlen, void **out, int *outlen)
659{
660
661 *out = NULL;
662 *outlen = 0;
663}
664
665/* Temporary null routines for testing. */
666
538bfd1d 667/*
668 * FIXME: verify_ssh_host_key() should be passed a frontend handle,
669 * but backends have to have a terminal handle instead, because they
670 * pass it to from_backend(), so we accept a terminal handle here as
671 * well, and hope no-one tries to call us with sensible arguments.
672 */
0c4b7799 673void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
674 char *keystr, char *fingerprint)
675{
538bfd1d 676 Str255 stuff;
677 Terminal *term = frontend;
678 Session *s = term->frontend;
679
680 /*
681 * This function is horribly wrong. For one thing, the alert
682 * shouldn't be modal, it should be movable modal, or a sheet in
683 * Aqua. Also, PuTTY might be in the background, in which case we
684 * should use the Notification Manager to wake up the user. In
685 * any case, we shouldn't hold up processing of other connections'
686 * data just because this one's waiting for the user. It should
687 * also handle a host key cache, of course, and see the note above
688 * about the "frontend" argument and the one below about closing
689 * the connection. All in all, a bit of a mess really.
690 */
0c4b7799 691
538bfd1d 692 stuff[0] = sprintf((char *)(&stuff[1]),
693 "The server's key fingerprint is: %s\n"
694 "Continue connecting?", fingerprint);
695 ParamText(stuff, NULL, NULL, NULL);
696 if (CautionAlert(wQuestion, NULL) == 2) {
697 /*
698 * User chose "Cancel". Unfortunately, if I tear the
699 * connection down here, Bad Things happen when I return. I
700 * think this function should actually return something
701 * telling the SSH code to abandon the connection.
702 */
703 }
0c4b7799 704}
705
706void askcipher(void *frontend, char *ciphername, int cs)
707{
708
709}
710
711void old_keyfile_warning(void)
712{
713
714}
715
e3c5b245 716FontSpec platform_default_fontspec(char const *name)
5a9eb105 717{
9a30e26b 718 FontSpec ret;
a499fbf9 719 long smfs;
a499fbf9 720
721 if (!strcmp(name, "Font")) {
722 smfs = GetScriptVariable(smSystemScript, smScriptMonoFondSize);
723 if (smfs == 0)
724 smfs = GetScriptVariable(smRoman, smScriptMonoFondSize);
725 if (smfs != 0) {
e3c5b245 726 GetFontName(HiWord(smfs), ret.name);
727 if (ret.name[0] == 0)
728 memcpy(ret.name, "\pMonaco", 7);
729 ret.size = LoWord(smfs);
9a30e26b 730 } else {
e3c5b245 731 memcpy(ret.name, "\pMonaco", 7);
732 ret.size = 9;
9a30e26b 733 }
e3c5b245 734 ret.face = 0;
9a30e26b 735 } else {
e3c5b245 736 ret.name[0] = 0;
a499fbf9 737 }
9a30e26b 738
739 return ret;
740}
741
742Filename platform_default_filename(const char *name)
743{
744 Filename ret;
745 if (!strcmp(name, "LogFileName"))
02cf4001 746 FSMakeFSSpec(0, 0, "\pputty.log", &ret.fss);
9a30e26b 747 else
02cf4001 748 memset(&ret, 0, sizeof(ret));
9a30e26b 749 return ret;
750}
751
752char *platform_default_s(char const *name)
753{
5a9eb105 754 return NULL;
755}
756
f5d2d791 757int platform_default_i(char const *name, int def)
5a9eb105 758{
a499fbf9 759
5a9eb105 760 /* Non-raw cut and paste of line-drawing chars works badly on the
761 * current Unix stub implementation of the Unicode functions.
762 * So I'm going to temporarily set the default to raw mode so
763 * that the failure mode isn't quite so drastically horrid.
764 * When Unicode comes in, this can all be put right. */
765 if (!strcmp(name, "RawCNP"))
766 return 1;
767 return def;
768}
769
e0e7dff8 770void platform_get_x11_auth(char *display, int *proto,
771 unsigned char *data, int *datalen)
772{
773 /* SGT: I have no idea whether Mac X servers need anything here. */
774}
775
d082ac49 776/*
777 * Local Variables:
778 * c-file-style: "simon"
779 * End:
780 */