void DoErrorAlert(OSStatus status, CFStringRef errorFormatString) { CFStringRef formatStr = NULL, printErrorMsg = NULL; SInt16 alertItemHit = 0; Str255 stringBuf; if ((status != noErr) && (status != 2)) { formatStr = CFCopyLocalizedString (errorFormatString, NULL); if (formatStr != NULL) { printErrorMsg = CFStringCreateWithFormat( NULL, NULL, formatStr, status); if (printErrorMsg != NULL) { if (CFStringGetPascalString ( printErrorMsg, stringBuf, sizeof(stringBuf), GetApplicationTextEncoding())) { StandardAlert(kAlertStopAlert, stringBuf, NULL, NULL, &alertItemHit); } CFRelease (printErrorMsg); } CFRelease (formatStr); } } }
void pws_os::SendString(const char* str, unsigned delayMS) { //GetApplicationTextEncoding call here certainly seems wrong. We should store the keyboard layout //and string encoding in password db. But this works for now. CFStringRef cfstr = CFStringCreateWithCString(kCFAllocatorDefault, str, GetApplicationTextEncoding()); SendString(cfstr, delayMS); CFRelease(cfstr); }
void gnc_keyring_set_password (const gchar *access_method, const gchar *server, guint32 port, const gchar *service, const gchar *user, const gchar* password) { #ifdef HAVE_GNOME_KEYRING GnomeKeyringResult gkr_result; guint32 item_id = 0; gkr_result = gnome_keyring_set_network_password_sync (NULL, user, NULL, server, service, access_method, NULL, port, password, &item_id); if (gkr_result != GNOME_KEYRING_RESULT_OK) { PWARN ("Gnome-keyring error: %s", gnome_keyring_result_to_message(gkr_result)); PWARN ("The user will be prompted for a password again next time."); } #endif /* HAVE_GNOME_KEYRING */ #ifdef HAVE_OSX_KEYCHAIN OSStatus status; SecKeychainItemRef *itemRef = NULL; /* mysql and postgres aren't valid protocols on Mac OS X. * So we use the security domain parameter to allow us to * distinguish between these two. */ // FIXME I'm not sure this works if a password was already in the keychain // I may have to do a lookup first and if it exists, run some update // update function instead status = SecKeychainAddInternetPassword ( NULL, /* keychain */ strlen(server), server, /* servername */ strlen(access_method), access_method, /* securitydomain */ strlen(user), user, /* acountname */ strlen(service), service, /* path */ port, /* port */ kSecProtocolTypeAny, /* protocol */ kSecAuthenticationTypeDefault, /* auth type */ strlen(password), password, /* passworddata */ itemRef ); if ( status != noErr ) { CFStringRef osx_resultstring = SecCopyErrorMessageString( status, NULL ); const gchar *resultstring = CFStringGetCStringPtr(osx_resultstring, GetApplicationTextEncoding()); PWARN ( "OS X keychain error: %s", resultstring ); PWARN ( "The user will be prompted for a password again next time." ); CFRelease ( osx_resultstring ); } #endif /* HAVE_OSX_KEYCHAIN */ }
void Internat::Init() { // Save decimal point character struct lconv * localeInfo = localeconv(); if (localeInfo) mDecimalSeparator = wxString(localeInfo->decimal_point, wxConvLocal).GetChar(0); // wxLogDebug(wxT("Decimal separator set to '%c'"), mDecimalSeparator); #ifndef __WXMAC__ // Set up character-set conversion for UTF-8 input and output. mConvLocal = new wxCSConv(wxLocale::GetSystemEncodingName()); #else // Set up a special converter to/from the Mac-specific local // encoding (usually MacRoman) OSStatus status = noErr; TECObjectRef ec; TextEncoding MacEncoding = GetApplicationTextEncoding(); TextEncoding UTF8 = CreateTextEncoding(kTextEncodingUnicodeDefault, kUnicodeNoSubset, kUnicodeUTF8Format); status = TECCreateConverter(&ec, MacEncoding, UTF8); if (status == noErr) mTECToUTF = (void *)ec; else mTECToUTF = NULL; status = TECCreateConverter(&ec, UTF8, MacEncoding); if (status == noErr) mTECFromUTF = (void *)ec; else mTECFromUTF = NULL; #endif }
gboolean gnc_keyring_get_password ( GtkWidget *parent, const gchar *access_method, const gchar *server, guint32 port, const gchar *service, gchar **user, gchar **password) { gboolean password_found = FALSE; #ifdef HAVE_GNOME_KEYRING GnomeKeyringResult gkr_result; GList *found_list = NULL; GnomeKeyringNetworkPasswordData *found; #endif #ifdef HAVE_OSX_KEYCHAIN void *password_data; UInt32 password_length; OSStatus status; #endif g_return_val_if_fail (user != NULL, FALSE); g_return_val_if_fail (password != NULL, FALSE); *password = NULL; #ifdef HAVE_GNOME_KEYRING gkr_result = gnome_keyring_find_network_password_sync ( *user, NULL, server, service, access_method, NULL, port, &found_list ); if (gkr_result == GNOME_KEYRING_RESULT_OK) { found = (GnomeKeyringNetworkPasswordData *) found_list->data; if (found->password) *password = g_strdup(found->password); password_found = TRUE; } else PWARN ("Gnome-keyring access failed: %s.", gnome_keyring_result_to_message(gkr_result)); gnome_keyring_network_password_list_free(found_list); #endif /* HAVE_GNOME_KEYRING */ #ifdef HAVE_OSX_KEYCHAIN /* mysql and postgres aren't valid protocols on Mac OS X. * So we use the security domain parameter to allow us to * distinguish between these two. */ if (*user != NULL) { status = SecKeychainFindInternetPassword( NULL, strlen(server), server, strlen(access_method), access_method, strlen(*user), *user, strlen(service), service, port, kSecProtocolTypeAny, kSecAuthenticationTypeDefault, &password_length, &password_data, NULL); if ( status == noErr ) { *password = g_strndup(password_data, password_length); password_found = TRUE; SecKeychainItemFreeContent(NULL, password_data); } else { CFStringRef osx_resultstring = SecCopyErrorMessageString( status, NULL ); const gchar *resultstring = CFStringGetCStringPtr(osx_resultstring, GetApplicationTextEncoding()); PWARN ( "OS X keychain error: %s", resultstring ); CFRelease ( osx_resultstring ); } } #endif /* HAVE_OSX_KEYCHAIN */ if ( !password_found ) { /* If we got here, either no proper password store is * available on this system, or we couldn't retrieve * a password from it. In both cases, just ask the user * to enter one */ gchar *db_path, *heading; if ( port == 0 ) db_path = g_strdup_printf ( "%s://%s/%s", access_method, server, service ); else db_path = g_strdup_printf ( "%s://%s:%d/%s", access_method, server, port, service ); heading = g_strdup_printf ( /* Translators: %s is a path to a database or any other url, like mysql://[email protected]/somedb, http://www.somequotes.com/thequotes */ _("Enter a user name and password to connect to: %s"), db_path ); password_found = gnc_get_username_password ( parent, heading, *user, NULL, user, password ); g_free ( db_path ); g_free ( heading ); if ( password_found ) { /* User entered new user/password information * Let's try to add it to a password store. */ gchar *newuser = g_strdup( *user ); gchar *newpassword = g_strdup( *password ); gnc_keyring_set_password ( access_method, server, port, service, newuser, newpassword ); g_free ( newuser ); g_free ( newpassword ); } } return password_found; }
CFStringRef CFStringFromStr255(ConstStr255Param pascalString) { return CFStringCreateWithPascalString( NULL, pascalString, GetApplicationTextEncoding( ) ); }
// -------------------------------------------------------------------------------------- static void drawIconListCell(ListHandle theList, const Rect *cellRect, IconListCellDataRec *theCellData, Boolean selected) { GrafPtr savedPort; CGrafPtr listPort; ThemeDrawingState savedState; Boolean active; Rect iconRect, textRect; short savedFont, savedSize; Style savedFace; CFStringRef cellName; GetPort(&savedPort); listPort = GetListPort(theList); SetPort((GrafPtr)listPort); GetThemeDrawingState(&savedState); if (selected) // we don't need to change the background { // color if this Cell isn't highlighted Pattern whitePattern; RGBColor highlightColor; GetQDGlobalsWhite(&whitePattern); // set the background pattern so that BackPat(&whitePattern); // the color is properly set as a solid color LMGetHiliteRGB(&highlightColor); RGBBackColor(&highlightColor); // set the background to the highlight color } EraseRect(cellRect); calculateDrawingBounds(cellRect, &iconRect, &textRect); // get the drawing Rects active = GetListActive(theList); // draw the IconRef using Icon Services PlotIconRef(&iconRect, kAlignNone, active ? kTransformNone : kTransformDisabled, kIconServicesNormalUsageFlag, theCellData->icon); #if TARGET_API_MAC_OS8 // draw TextEdit text in Classic #pragma unused (cellName) savedFont = GetPortTextFont(listPort); // Get/SetThemeDrawingState doesn't save or savedFace = GetPortTextFace(listPort); // restore these savedSize = GetPortTextSize(listPort); UseThemeFont(kThemeViewsFont, smCurrentScript); TETextBox(&theCellData->name[1], theCellData->name[0], &textRect, teCenter); TextFont(savedFont); TextFace(savedFace); TextSize(savedSize); #else // draw Appearance text in Carbon #pragma unused (savedFont, savedSize, savedFace) cellName = CFStringCreateWithPascalString(kCFAllocatorDefault, theCellData->name, GetApplicationTextEncoding()); DrawThemeTextBox(cellName, kThemeViewsFont, active ? kThemeStateActive : kThemeStateInactive, true, &textRect, teCenter, NULL); CFRelease(cellName); #endif SetThemeDrawingState(savedState, true); SetPort(savedPort); } // drawIconListCell
OSStatus BeginSave( NavDialogRef inDialog, NavReplyRecord* outReply, FSRef* outFileRef ) { OSStatus status = paramErr; AEDesc dirDesc; AEKeyword keyword; CFIndex len; require( outReply, Return ); require( outFileRef, Return ); status = NavDialogGetReply( inDialog, outReply ); nrequire( status, Return ); status = AEGetNthDesc( &outReply->selection, 1, typeWildCard, &keyword, &dirDesc ); nrequire( status, DisposeReply ); len = CFStringGetLength( outReply->saveFileName ); if ( dirDesc.descriptorType == typeFSRef ) { const UInt32 kMaxNameLen = 255; FSRef dirRef; UniChar name[ kMaxNameLen ]; if ( len > kMaxNameLen ) { len = kMaxNameLen; } status = AEGetDescData( &dirDesc, &dirRef, sizeof( dirRef )); nrequire( status, DisposeDesc ); CFStringGetCharacters( outReply->saveFileName, CFRangeMake( 0, len ), &name[0] ); status = FSMakeFSRefUnicode( &dirRef, len, &name[0], GetApplicationTextEncoding(), outFileRef ); if (status == fnfErr ) { // file is not there yet - create it and return FSRef status = FSCreateFileUnicode( &dirRef, len, &name[0], 0, NULL, outFileRef, NULL ); } else { // looks like file is there. Just make sure there is no error nrequire( status, DisposeDesc ); } } else if ( dirDesc.descriptorType == typeFSS ) { FSSpec theSpec; status = AEGetDescData( &dirDesc, &theSpec, sizeof( FSSpec )); nrequire( status, DisposeDesc ); if ( CFStringGetPascalString( outReply->saveFileName, &(theSpec.name[0]), sizeof( StrFileName ), GetApplicationTextEncoding())) { status = FSpMakeFSRef(&theSpec, outFileRef); nrequire( status, DisposeDesc ); status = FSpCreate( &theSpec, 0, 0, smSystemScript ); nrequire( status, DisposeDesc ); } else { status = bdNamErr; nrequire( status, DisposeDesc ); } } DisposeDesc: AEDisposeDesc( &dirDesc ); DisposeReply: if ( status != noErr ) { NavDisposeReply( outReply ); } Return: return status; }
OSStatus SaveFileDialog( WindowRef parentWindow, CFStringRef documentName, OSType filetype, OSType fileCreator, void *inContextData, NavDialogRef *outDialog ) { NavDialogCreationOptions dialogOptions; OSStatus theErr = noErr; NavGetDefaultDialogCreationOptions( &dialogOptions ); dialogOptions.clientName = CFStringCreateWithPascalString( NULL, LMGetCurApName(), GetApplicationTextEncoding()); dialogOptions.saveFileName = documentName; dialogOptions.modality = ( parentWindow != NULL ) ? kWindowModalityWindowModal : kWindowModalityAppModal; dialogOptions.parentWindow = parentWindow; theErr = NavCreatePutFileDialog( &dialogOptions, filetype, fileCreator, GetEventUPP(), inContextData, outDialog ); if ( theErr == noErr ) { theErr = NavDialogRun( *outDialog ); if ( theErr != noErr ) { NavDialogDispose( *outDialog ); } if ( theErr != noErr || dialogOptions.modality == kWindowModalityAppModal ) { *outDialog = NULL; // The dialog has already been disposed. } } if ( dialogOptions.clientName != NULL ) { CFRelease( dialogOptions.clientName ); } return theErr; }
static OSStatus UniversalConfirmSaveDialog( WindowRef parentWindow, CFStringRef documentName, Boolean quitting, void* inContextData, NavDialogRef *outDialog, NavUserAction *outUserAction ) { OSStatus theErr = noErr; NavAskSaveChangesAction action = 0; NavDialogRef dialog = NULL; NavUserAction userAction = kNavUserActionNone; NavDialogCreationOptions dialogOptions; NavEventUPP eventUPP; Boolean disposeAfterRun; NavGetDefaultDialogCreationOptions( &dialogOptions ); action = quitting ? kNavSaveChangesQuittingApplication : kNavSaveChangesClosingDocument; dialogOptions.modality = ( parentWindow != NULL ) ? kWindowModalityWindowModal : kWindowModalityAppModal; dialogOptions.parentWindow = parentWindow; dialogOptions.clientName = CFStringCreateWithPascalString( NULL, LMGetCurApName(), GetApplicationTextEncoding()); if ( documentName != NULL ) { dialogOptions.saveFileName = documentName; } eventUPP = ( inContextData == NULL ) ? GetPrivateEventUPP() : GetEventUPP(); disposeAfterRun = ( dialogOptions.modality == kWindowModalityAppModal && inContextData == NULL ); theErr = NavCreateAskSaveChangesDialog( &dialogOptions, action, eventUPP, inContextData, &dialog ); if ( theErr == noErr ) { theErr = NavDialogRun( dialog ); if ( theErr != noErr || disposeAfterRun ) { userAction = NavDialogGetUserAction( dialog ); NavDialogDispose( dialog ); dialog = NULL; } } if ( dialogOptions.clientName != NULL ) { CFRelease( dialogOptions.clientName ); } if ( outDialog != NULL ) { *outDialog = dialog; } if ( outUserAction != NULL ) { *outUserAction = userAction; } return theErr; }
OSStatus OpenFileDialog( OSType applicationSignature, short numTypes, OSType typeList[], NavDialogRef *outDialog ) { OSStatus theErr = noErr; if ( gOpenFileDialog == NULL ) { NavDialogCreationOptions dialogOptions; NavTypeListHandle openList = NULL; NavGetDefaultDialogCreationOptions( &dialogOptions ); dialogOptions.modality = kWindowModalityNone; dialogOptions.clientName = CFStringCreateWithPascalString( NULL, LMGetCurApName(), GetApplicationTextEncoding()); openList = (NavTypeListHandle)NewOpenHandle( applicationSignature, numTypes, typeList ); theErr = NavCreateGetFileDialog( &dialogOptions, openList, GetPrivateEventUPP(), NULL, NULL, NULL, &gOpenFileDialog ); if ( theErr == noErr ) { theErr = NavDialogRun( gOpenFileDialog ); if ( theErr != noErr ) { NavDialogDispose( gOpenFileDialog ); gOpenFileDialog = NULL; } } if (openList != NULL) { DisposeHandle((Handle)openList); } if ( dialogOptions.clientName != NULL ) { CFRelease( dialogOptions.clientName ); } } else { if ( NavDialogGetWindow( gOpenFileDialog ) != NULL ) { SelectWindow( NavDialogGetWindow( gOpenFileDialog )); } } if ( outDialog != NULL ) { *outDialog = gOpenFileDialog; } return NULL; }