kim_ui_environment kim_os_library_get_ui_environment (void) { #ifdef KIM_BUILTIN_UI kim_boolean has_gui_access = 0; SessionAttributeBits sattrs = 0L; has_gui_access = ((SessionGetInfo (callerSecuritySession, NULL, &sattrs) == noErr) && (sattrs & sessionHasGraphicAccess)); if (has_gui_access && kim_os_library_caller_uses_gui ()) { return KIM_UI_ENVIRONMENT_GUI; } { int fd_stdin = fileno (stdin); int fd_stdout = fileno (stdout); char *fd_stdin_name = ttyname (fd_stdin); /* Session info isn't reliable for remote sessions. * Check manually for terminal access with file descriptors */ if (isatty (fd_stdin) && isatty (fd_stdout) && fd_stdin_name) { return KIM_UI_ENVIRONMENT_CLI; } } /* If we don't have a CLI but can talk to the GUI, use that */ if (has_gui_access) { return KIM_UI_ENVIRONMENT_GUI; } kim_debug_printf ("kim_os_library_get_ui_environment(): no way to talk to the user."); #endif return KIM_UI_ENVIRONMENT_NONE; }
/*********************************************************************** * process_attach */ static BOOL process_attach(void) { SessionAttributeBits attributes; OSStatus status; status = SessionGetInfo(callerSecuritySession, NULL, &attributes); if (status != noErr || !(attributes & sessionHasGraphicAccess)) return FALSE; setup_options(); if ((thread_data_tls_index = TlsAlloc()) == TLS_OUT_OF_INDEXES) return FALSE; macdrv_err_on = ERR_ON(macdrv); if (macdrv_start_cocoa_app(GetTickCount64())) { ERR("Failed to start Cocoa app main loop\n"); return FALSE; } set_app_icon(); macdrv_clipboard_process_attach(); return TRUE; }
/* * Determine if there is an OS-specific mechanism for accessing * MIME and extension data. In the general *nix case this is all * done through mailcap and mime.types files. * * Returns: 0 if there is no support (most *nix cases) * 1 if there is support (Mac OS X, Windows) */ int mime_os_specific_access(void) { #ifdef _WINDOWS return 1; #elif OSX_TARGET # ifdef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER { /* * if we don't have the WidowSession then we should avoid using * frameworks unless they call themselves daemon-safe */ SecuritySessionId session_id; SessionAttributeBits session_bits; if((SessionGetInfo(callerSecuritySession, &session_id, &session_bits) == errSessionSuccess) && session_bits & sessionHasGraphicAccess) return 1; else return 0; } # else return 0; # endif #else return 0; #endif }
/*++ Function: MessageBoxA This is a small subset of MessageBox that simply logs a message to the system logging facility and returns. A typical log entry will look like: May 23 15:48:10 rice example1: MessageBox: Caption: Error Text Note: hWnd should always be NULL. See MSDN doc. --*/ int PALAPI MessageBoxA( IN LPVOID hWnd, IN LPCSTR lpText, IN LPCSTR lpCaption, IN UINT uType) { INT rc = 0; PERF_ENTRY(MessageBoxA); ENTRY( "MessageBoxA (hWnd=%p, lpText=%p (%s), lpCaption=%p (%s), uType=%#x)\n", hWnd, lpText?lpText:"NULL", lpText?lpText:"NULL", lpCaption?lpCaption:"NULL", lpCaption?lpCaption:"NULL", uType ); if (hWnd != NULL) { ASSERT("hWnd != NULL"); } if (lpText == NULL) { WARN("No message text\n"); lpText = "(no message text)"; } if (lpCaption == NULL) { lpCaption = "Error"; } if (uType & MB_DEFMASK) { WARN("No support for alternate default buttons.\n"); } /* set default status based on the type of button */ switch(uType & MB_TYPEMASK) { case MB_OK: rc = IDOK; break; case MB_ABORTRETRYIGNORE: rc = IDABORT; break; case MB_YESNO: rc = IDNO; break; case MB_OKCANCEL : rc = IDCANCEL; break; case MB_RETRYCANCEL : rc = IDCANCEL; break; default: ASSERT("Bad uType"); rc = IDOK; break; } PALCEnterCriticalSection( &msgbox_critsec); #ifdef __APPLE__ OSStatus osstatus; SecuritySessionId secSession; SessionAttributeBits secSessionInfo; osstatus = SessionGetInfo(callerSecuritySession, &secSession, &secSessionInfo); if (noErr == osstatus && (secSessionInfo & sessionHasGraphicAccess) != 0) { CFStringRef cfsTitle = CFStringCreateWithCString(kCFAllocatorDefault, lpCaption, kCFStringEncodingUTF8); CFStringRef cfsText = CFStringCreateWithCString(kCFAllocatorDefault, lpText, kCFStringEncodingUTF8); CFStringRef cfsButton1 = NULL; CFStringRef cfsButton2 = NULL; CFStringRef cfsButton3 = NULL; CFOptionFlags alertFlags = 0; CFOptionFlags response; switch (uType & MB_TYPEMASK) { case MB_OK: // Nothing needed; since if all the buttons are null, a stock "OK" is used. break; case MB_ABORTRETRYIGNORE: // Localization? Would be needed if this were used outside of debugging. cfsButton1 = CFSTR("Abort"); cfsButton2 = CFSTR("Retry"); cfsButton3 = CFSTR("Ignore"); alertFlags = kCFUserNotificationCautionAlertLevel; break; case MB_YESNO: cfsButton1 = CFSTR("Yes"); cfsButton2 = CFSTR("No"); break; case MB_OKCANCEL: cfsButton1 = CFSTR("OK"); cfsButton2 = CFSTR("Cancel"); break; case MB_RETRYCANCEL: cfsButton1 = CFSTR("Retry"); cfsButton2 = CFSTR("Cancel"); break; } CFUserNotificationDisplayAlert(0 /* no time out */, alertFlags, NULL /* iconURL */, NULL /* soundURL */, NULL /* localizationURL */, cfsTitle, cfsText, cfsButton1, cfsButton2, cfsButton3, &response); switch (uType & MB_TYPEMASK) { case MB_OK: break; case MB_ABORTRETRYIGNORE: switch (response) { case kCFUserNotificationDefaultResponse: rc = IDABORT; break; case kCFUserNotificationAlternateResponse: rc = IDRETRY; break; case kCFUserNotificationOtherResponse: rc = IDIGNORE; break; } break; case MB_YESNO: switch (response) { case kCFUserNotificationDefaultResponse: rc = IDYES; break; case kCFUserNotificationAlternateResponse: rc = IDNO; break; } break; case MB_OKCANCEL: switch (response) { case kCFUserNotificationDefaultResponse: rc = IDOK; break; case kCFUserNotificationAlternateResponse: rc = IDCANCEL; break; } break; case MB_RETRYCANCEL: switch (response) { case kCFUserNotificationDefaultResponse: rc = IDRETRY; break; case kCFUserNotificationAlternateResponse: rc = IDCANCEL; break; } break; } } else { // We're not in a login session, e.g., running via ssh, and so bringing // up a message box would be bad form. fprintf ( stderr, "MessageBox: %s: %s", lpCaption, lpText ); syslog(LOG_USER|LOG_ERR, "MessageBox: %s: %s", lpCaption, lpText); } #else // __APPLE__ fprintf ( stderr, "MessageBox: %s: %s", lpCaption, lpText ); syslog(LOG_USER|LOG_ERR, "MessageBox: %s: %s", lpCaption, lpText); // Some systems support displaying a GUI dialog. (This will suspend the current thread until they hit the // 'OK' button and allow a debugger to be attached). PAL_DisplayDialog(lpCaption, lpText); #endif // __APPLE__ else PALCLeaveCriticalSection( &msgbox_critsec); LOGEXIT("MessageBoxA returns %d\n", rc); PERF_EXIT(MessageBoxA); return rc; }