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