OSStatus
CConfigPropertySheet::TearDownBrowsing()
{
	OSStatus err = kNoErr;

	if ( m_browseDomainsRef )
	{
		err = WSAAsyncSelect( DNSServiceRefSockFD( m_browseDomainsRef ), m_hWnd, 0, 0 );
		check_noerr( err );

		DNSServiceRefDeallocate( m_browseDomainsRef );
	
		m_browseDomainsRef = NULL;
	}

	if ( m_regDomainsRef )
	{
		err = WSAAsyncSelect( DNSServiceRefSockFD( m_regDomainsRef ), m_hWnd, 0, 0 );
		check_noerr( err );

		DNSServiceRefDeallocate( m_regDomainsRef );
	
		m_regDomainsRef = NULL;
	}

	return err;
}
void
CConfigPropertySheet::OnEndDialog()
{
	OSStatus err;

	err = TearDownRegistryNotifications();
	check_noerr( err );

	err = TearDownBrowsing();
	check_noerr( err );
}
Esempio n. 3
0
void	DNSServiceDiscoveryDeallocate( dns_service_discovery_ref inRef )
{
	_dns_service_discovery_t *		obj;
	DNSStatus						err;
	
	check( inRef );
	check( inRef->ref );
	
	obj = (_dns_service_discovery_t *) inRef;
	switch( obj->type )
	{
		case kDNSServiceDiscoveryObjectTypeRegistration:
			if( inRef->ref )
			{
				err = DNSRegistrationRelease( (DNSRegistrationRef) inRef->ref, 0 );
				check_noerr( err );
			}
			free( inRef );
			break;
		
		case kDNSServiceDiscoveryObjectTypeDomainEnumeration:
			if( inRef->ref )
			{
				err = DNSBrowserRelease( (DNSBrowserRef) inRef->ref, 0 );
				check_noerr( err );
			}
			free( inRef );
			break;
		
		case kDNSServiceDiscoveryObjectTypeBrowser:
			if( inRef->ref )
			{
				err = DNSBrowserRelease( (DNSBrowserRef) inRef->ref, 0 );
				check_noerr( err );
			}
			free( inRef );
			break;
		
		case kDNSServiceDiscoveryObjectTypeResolver:
			if( inRef->ref )
			{
				err = DNSResolverRelease( (DNSResolverRef) inRef->ref, 0 );
				check_noerr( err );
			}
			free( inRef );
			break;
		
		default:
			debugf( DEBUG_NAME "unknown object type (%d)\n", obj->type );
			break;
	}
}
Esempio n. 4
0
void
TabbedWindow::DisableAllPanes( void )
{
    OSStatus status;
    ControlRef controlRef;
    ControlID controlID;
    
    controlID.signature = kTabPaneSignature;
    
    // loop through and disable all of the panes
    for ( int i = 1; i <= kTabPaneCount; i++ )
    {
        controlID.id = gPaneArray[i];
        status = GetControlByID( fWindowRef, &controlID, &controlRef );
        check_noerr( status );
        
        // disable the panes
        if ( status == noErr )
        {
            SetControlVisibility( controlRef, false, false );
            DisableControl( controlRef );
        }
    }
    return;
}
Esempio n. 5
0
TabbedWindow::TabbedWindow( void )
{
    OSStatus status;
    IBNibRef nibRef;
    fWindowRef = NULL;
    
    static const ControlID tabControlID = 
        { kMasterTabControlSignature, kMasterTabControlID };

    // Create a Nib reference passing the name of the nib file (without the .nib
    // extension) CreateNibReference only searches into the application bundle.
    status = CreateNibReference( CFSTR("main"), &nibRef );
    require_noerr( status, TabbedWindow_err );
	
    // Then create a window & set menubar based on Nib.
    status = CreateWindowFromNib( nibRef, CFSTR("MainWindow"), &fWindowRef );
    require_noerr( status, TabbedWindow_err );
    status = SetMenuBarFromNib( nibRef, CFSTR( "MenuBar" ) );
    require_noerr( status, TabbedWindow_err );

    // finsihed with the nib reference
    DisposeNibReference(nibRef);
    
    // what events will this window handle?
    status = this->RegisterWindowCarbonEventhandler();
    require_noerr( status, TabbedWindow_err );
    
    // start with current tab pane set to NULL.
    fCurrentTabPane = NULL;
    
    // start with all panes disabled
    this->DisableAllPanes();
    
    // Get a reference to the tab control in the window
    status = GetControlByID( fWindowRef, &tabControlID, &fTabControlRef );
    //check_noerr( status );
    
    // put event handlers on it
    status = InstallStandardEventHandler( GetControlEventTarget( fTabControlRef ) );
    check_noerr( status );
    
    // Switch to the tab content indicated by current value of the tab control
    if( status == noErr )
        status = this->SwitchTabPane( fTabControlRef );
    
    // show the new window
    ShowWindow( fWindowRef );
	
TabbedWindow_err:

    #if DEBUG_ERROR_LOGS
    if( status != noErr )
    {
        SysBeep(10);
        std::cout << "Error in TabbedWindow constructor:" << status << std::endl;
    }
    #endif

    return;
}
Esempio n. 6
0
OSStatus
    AES_CTR_Init( 
        AES_CTR_Context *   inContext, 
        const uint8_t       inKey[ kAES_CTR_Size ], 
        const uint8_t       inNonce[ kAES_CTR_Size ] )
{
#if( AES_UTILS_USE_COMMON_CRYPTO )
    OSStatus        err;
    
    inContext->cryptor = NULL;
    err = CCCryptorCreate( kCCEncrypt, kCCAlgorithmAES128, kCCOptionECBMode, inKey, kAES_CTR_Size, NULL, 
        &inContext->cryptor );
    check_noerr( err );
    if( err ) return( err );
#elif( AES_UTILS_USE_GLADMAN_AES )
    aes_init();
    aes_encrypt_key128( inKey, &inContext->ctx );
#elif( AES_UTILS_USE_USSL )
    aes_setkey_enc( &inContext->ctx, (unsigned char *) inKey, kAES_CTR_Size * 8 );
#else
    AES_set_encrypt_key( inKey, kAES_CTR_Size * 8, &inContext->key );
#endif
    memcpy( inContext->ctr, inNonce, kAES_CTR_Size );
    inContext->used = 0;
    inContext->legacy = false;
    return( kNoErr );
}
Esempio n. 7
0
OSStatus
    AES_CBCFrame_Init( 
        AES_CBCFrame_Context *  inContext, 
        const uint8_t           inKey[ kAES_CBCFrame_Size ], 
        const uint8_t           inIV[ kAES_CBCFrame_Size ], 
        Boolean                 inEncrypt )
{
#if( AES_UTILS_USE_COMMON_CRYPTO )
    OSStatus        err;
    
    inContext->cryptor = NULL;
    err = CCCryptorCreate( inEncrypt ? kCCEncrypt : kCCDecrypt, kCCAlgorithmAES128, 0, inKey, kAES_CTR_Size, 
        NULL, &inContext->cryptor );
    check_noerr( err );
    if( err ) return( err );
#elif( AES_UTILS_USE_GLADMAN_AES )
    aes_init();
    if( inEncrypt ) aes_encrypt_key128( inKey, &inContext->ctx.encrypt );
    else            aes_decrypt_key128( inKey, &inContext->ctx.decrypt );
    inContext->encrypt = inEncrypt;
#elif( AES_UTILS_USE_USSL )
    if( inEncrypt ) aes_setkey_enc( &inContext->ctx, (unsigned char *) inKey, kAES_CBCFrame_Size * 8 );
    else            aes_setkey_dec( &inContext->ctx, (unsigned char *) inKey, kAES_CBCFrame_Size * 8 );
    inContext->encrypt = inEncrypt;
#else
    if( inEncrypt ) AES_set_encrypt_key( inKey, kAES_CBCFrame_Size * 8, &inContext->key );
    else            AES_set_decrypt_key( inKey, kAES_CBCFrame_Size * 8, &inContext->key );
    inContext->mode = inEncrypt ? AES_ENCRYPT : AES_DECRYPT;
#endif
    memcpy( inContext->iv, inIV, kAES_CBCFrame_Size );
    return( kNoErr );
}
smcp_status_t
resend_get_request(void* context) {
    ThingMLCOAPContext * thingml_context = (ThingMLCOAPContext*) context;
    smcp_status_t status = 0;

    status = smcp_outbound_begin(smcp_get_current_instance(),COAP_METHOD_GET, get_tt);
    require_noerr(status,bail);

    status = smcp_outbound_set_uri(thingml_context->url, 0);
    require_noerr(status,bail);

    if(request_accept_type!=COAP_CONTENT_TYPE_UNKNOWN) {
        status = smcp_outbound_add_option_uint(COAP_OPTION_ACCEPT, request_accept_type);
        require_noerr(status,bail);
    }

    status = smcp_outbound_send();

    if(status) {
        check_noerr(status);
        fprintf(stderr,
                "smcp_outbound_send() returned error %d(%s).\n",
                status,
                smcp_status_to_cstr(status));
        goto bail;
    }

bail:
    return status;
}
Esempio n. 9
0
/* Starts enumeration process. */
CHXDirectory::FSOBJ 
CHXDirectory::FindFirst(const char* szPattern, char* szPath, UINT16 nSize)
{
	OSErr err;
	CHXDirSpecifier dirSpec(m_strPath);
	
	require(dirSpec.IsSet() && CHXFileSpecUtils::DirectoryExists(dirSpec), bail);

	// if there is already an iterator, dispose it
	if (m_FSIterator)
	{

		err = FSCloseIterator(m_FSIterator);
		check_noerr(err);

		m_FSIterator = 0;
	}

	err = FSOpenIterator((FSRef *) dirSpec, kFSIterateFlat, &m_FSIterator);
	require_noerr(err, bail);
	
	m_strFindPattern = szPattern;

	return FindNext(szPath, nSize);
	
bail:
	return FSOBJ_NOTVALID;
}
//-----------------------------------------------------------------------------
//	CreateCustomToolbarItem
//-----------------------------------------------------------------------------
//	Our 'public' API to create our custom URL item.
//
HIToolbarItemRef
CreateCustomToolbarItem( CFStringRef inIdentifier, CFTypeRef inURL )
{
	OSStatus			err;
	EventRef			event;
	UInt32				options = kHIToolbarItemAllowDuplicates;
	HIToolbarItemRef	result = NULL;
	
	RegisterCustomToolbarItemClass();
	
	err = CreateEvent( NULL, kEventClassHIObject, kEventHIObjectInitialize,
			GetCurrentEventTime(), 0, &event );
	require_noerr( err, CantCreateEvent );

	SetEventParameter( event, kEventParamToolbarItemIdentifier, typeCFStringRef, sizeof( CFStringRef ), &inIdentifier );
	SetEventParameter( event, kEventParamAttributes, typeUInt32, sizeof( UInt32 ), &options );

	if ( inURL )
		SetEventParameter( event, kEventParamToolbarItemConfigData, typeCFTypeRef, sizeof( CFTypeRef ), &inURL );
	
	err = HIObjectCreate( kCustomToolbarItemClassID, event, (HIObjectRef*)&result );
	check_noerr( err );

	ReleaseEvent( event );
	
CantCreateEvent:
	return result;
}
Esempio n. 11
0
OSStatus
TextViewDefaultSettings( HIViewRef textView )
{
	OSStatus status = paramErr;
	static const CFStringRef taskCFStr = CFSTR("TaskDefault");
	WindowRef window;
	
	status = AddTextToTheTextView( textView );
	check_noerr( status );
	status = TextViewEditCommandSupport( textView, true );
	check_noerr( status );
	status = TextViewFontPanelSupport( textView, false );
	check_noerr( status );
	status = TextViewSpellingSupport( textView, false );
	check_noerr( status );
	status = TextViewScrollingOptions( textView, (UInt32)kTXNAutoScrollInsertionIntoView );
	check_noerr( status );
	status = TXNSetSelection(HITextViewGetTXNObject(textView), kTXNStartOffset, kTXNStartOffset);
	check_noerr( status );
	status = HIScrollViewNavigate(HIViewGetSuperview(textView),kHIScrollViewScrollToTop) ;
	check_noerr( status );

	status = SignalHelpMessage( HIViewGetWindow( textView ), taskCFStr );

	return status;
}
Esempio n. 12
0
OSStatus
GetTextViewFromWindow( WindowRef window, HIViewRef& textView )
{
	OSStatus status = paramErr;
	if( window != NULL )
	{
		status = HIViewFindByID(HIViewGetRoot(window), kTextViewControlID, &textView);
		check_noerr( status );
	}
	return status;
}
//---------------------------------------------------------------------
// Creates one of our simple document windows and returns a ref to it.
//
WindowRef MyCreateNewDocumentWindow(void)
{
    IBNibRef nib;
    WindowRef window = NULL;
	OSStatus status;

    // Create one of our special main document windows
    status = CreateNibReference(CFSTR("main"), &nib);
	require_noerr( status, CantGetNIBRef );
    status = CreateWindowFromNib(nib, CFSTR("MainDocumentWindow"), &window);
	require_noerr( status, CantCreateWindow );

	// Set its default options
	status = MySetTextViewOptions(GetTextViewFromWindow(window));
	check_noerr( status );

	// Make the window transparent
	status = MakeWindowTransparent(window);
	check_noerr( status );

	// Make the TextView partially transparent
	status = TextViewSetAlpha(GetTextViewFromWindow(window), 0.25);
	check_noerr( status );

	// Initialize the window title and proxy icon
	status = SetWindowTitleWithCFString(window, CFSTR("Untitled"));
	check_noerr( status );
	status = SetWindowProxyCreatorAndType(window, kUnknownType, kUnknownType, kOnSystemDisk);
	check_noerr( status );

	// Show the window
    ShowWindow(window);

	// Cleanup
CantGetViewRef:
CantCreateWindow:
    DisposeNibReference(nib);
CantGetNIBRef:
	return window;
}
Esempio n. 14
0
static smcp_status_t
resend_async_response(void* context) {
    smcp_status_t ret = 0;
    smcp_curl_request_t request = (smcp_curl_request_t)context;
    struct smcp_async_response_s* async_response = &request->async_response;

    coap_size_t len = (coap_size_t)request->content_len;
    if(len>512) {
        len = 512;
    }

    {
        uint16_t code;
        curl_easy_getinfo(request->curl, CURLINFO_RESPONSE_CODE,&code);
        code = http_to_coap_code(code);

        ret = smcp_outbound_begin_async_response(code,async_response);
        require_noerr(ret,bail);
    }

    {
        const char* content_type_string;
        curl_easy_getinfo(request->curl, CURLINFO_CONTENT_TYPE,&content_type_string);
        coap_content_type_t content_type = coap_content_type_from_cstr(content_type_string);
        if(content_type!=COAP_CONTENT_TYPE_UNKNOWN) {
            ret = smcp_outbound_add_option_uint(COAP_OPTION_CONTENT_TYPE, content_type);
            check_noerr(ret);
        } else {
            DEBUG_PRINTF("Unrecognised content-type: %s",content_type_string);
        }
    }

    ret = smcp_outbound_append_content(request->content, len);
    require_noerr(ret,bail);

    ret = smcp_outbound_send();
    require_noerr(ret,bail);

    if(ret) {
        assert_printf(
            "smcp_outbound_send() returned error %d(%s).\n",
            ret,
            smcp_status_to_cstr(ret)
        );
        goto bail;
    }

bail:
    return ret;
}
Esempio n. 15
0
static
OSStatus CreateStyleObjectWithFontName(
	char		*fontName,
	Fixed		*fontSize,
	RGBColor	*fontColor,
	ATSUStyle	*newStyle )
{
	OSStatus				err;
	ATSUFontID				fontID;
	ATSUAttributeTag		tags[3];
	ByteCount				tagValueSizes[3];
	ATSUAttributeValuePtr	tagValuePtrs[3];
	
	
	// try to find the font based on the font name
	err = ATSUFindFontFromName( fontName, strlen( fontName ), kFontFullName,
		kFontNoPlatform, kFontNoScript, kFontNoLanguage, &fontID );
	require_noerr( err, CreateStyleObjectWithFontName_err );

	// first, create the new style object
	err = ATSUCreateStyle( newStyle );
	
	// set up the three tags that we are setting in the style
	tags[0] = kATSUFontTag;
	tagValueSizes[0] = sizeof( ATSUFontID );
	tagValuePtrs[0] = &fontID;
	
	tags[1] = kATSUSizeTag;
	tagValueSizes[1] = sizeof( Fixed );
	tagValuePtrs[1] = fontSize;
	
	tags[2] = kATSUColorTag;
	tagValueSizes[2] = sizeof( RGBColor );
	tagValuePtrs[2] = fontColor;
	
	// set the attributes in the style object
	err = ATSUSetAttributes( *newStyle, 3, tags, tagValueSizes, tagValuePtrs );
	check_noerr( err );
	
	// if there was an error, then dispose of the style
	if ( err != noErr ) {
		ATSUDisposeStyle( *newStyle );
	}
	
CreateStyleObjectWithFontName_err: 

	return err;
	
}
Esempio n. 16
0
//
// release the directory
//
void CMacFindFile::OS_CloseDirectory ()
{
	HX_VECTOR_DELETE(m_pszOutFileName);
	
	if (m_FSIterator)
	{
		OSErr err;

		err = FSCloseIterator(m_FSIterator);
		check_noerr(err);

		m_FSIterator = 0;
	}

	return;
}
Esempio n. 17
0
// Create a new demo window
OSStatus
NewWindow()
{
    IBNibRef nibRef;
    WindowRef window;
	EventTypeSpec commandEventType = {kEventClassWindow, kEventWindowFocusAcquired};
    OSStatus status = noErr;

    // Create a Nib reference passing the name of the nib file (without the .nib extension)
    // CreateNibReference only searches into the application bundle.
	status = CreateNibReference(CFSTR("main"), &nibRef);
    require_noerr( status, CantGetNibRef );
    
    // Then create a window. "MainWindow" is the name of the window object. This name is set in 
    // InterfaceBuilder when the nib is created.
    status = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window);
    require_noerr( status, CantCreateWindow );

    // We don't need the nib reference anymore.
    DisposeNibReference(nibRef);
	
	// Let's customize the HITextView in that window
	status = SetUpTheTextView( window );	
	check_noerr( status );

    // The window was created hidden so show it.
    ShowWindow( window );

	// by default, focus the HITextView at start
	status = TextViewFocusInWindow( window );
    require_noerr( status, CantFocusTextView );

	// set up the control state from the state of the text view
	status = UpdateControlsFromTextViewWindow( window );
    require_noerr( status, CantSetControlState );

	// Install a handler to update the UI when this window comes to the front
	status = InstallEventHandler(GetWindowEventTarget(window), NewEventHandlerUPP(WindowFocusAcquired), 1, &commandEventType, NULL, NULL);
    require_noerr( status, CantInstallWindowEventHandler );
	
CantFocusTextView:
CantSetControlState:
CantInstallWindowEventHandler:
CantCreateWindow:
CantGetNibRef:
	return status;
}
Esempio n. 18
0
smcp_status_t
plugtest_obs_handler(
	struct plugtest_server_s *self
) {
	smcp_status_t ret = SMCP_STATUS_NOT_ALLOWED;
	smcp_method_t method = smcp_inbound_get_code();

	if(method==COAP_METHOD_GET) {
		char* content = NULL;
		coap_size_t max_len = 0;

		ret = smcp_outbound_begin_response(COAP_RESULT_205_CONTENT);
		require_noerr(ret, bail);

		ret = smcp_outbound_add_option_uint(COAP_OPTION_CONTENT_TYPE, COAP_CONTENT_TYPE_TEXT_PLAIN);
		require_noerr(ret, bail);

		if(!smcp_timer_is_scheduled(smcp_get_current_instance(), &self->obs_timer))
			plugtest_obs_timer_callback(smcp_get_current_instance(),self);

		ret = smcp_observable_update(&self->observable,PLUGTEST_OBS_KEY);
		check_noerr(ret);

		ret = smcp_outbound_add_option_uint(COAP_OPTION_MAX_AGE,10);
		require_noerr(ret, bail);

		content = smcp_outbound_get_content_ptr(&max_len);
		require_action(content!=NULL, bail, ret = SMCP_STATUS_FAILURE);

		require_action(max_len>11, bail, ret = SMCP_STATUS_MESSAGE_TOO_BIG);

		ret = smcp_outbound_set_content_len(
			(coap_size_t)strlen(uint32_to_dec_cstr(content, (uint32_t)time(NULL)))
		);
		require_noerr(ret, bail);

		ret = smcp_outbound_send();
		require_noerr(ret, bail);
	}
bail:
	return ret;
}
//---------------------------------------------------------------------
// Sets the alpha of an HITextView to the specified value
//
OSStatus TextViewSetAlpha(HIViewRef textView, float alpha)
{
	CGColorRef prevColor, newColor;
	OSStatus status;
	
	status = HITextViewCopyBackgroundColor(textView, &prevColor);
	require_noerr( status, CantGetBackgroundColor );
	
	newColor = CGColorCreateCopyWithAlpha(prevColor, alpha);
	require( (newColor != NULL), CantCreateNewColor );
	
	status = HITextViewSetBackgroundColor(textView, newColor);
	check_noerr( status );

	CGColorRelease(newColor);
CantCreateNewColor:
	CGColorRelease(prevColor);
CantGetBackgroundColor:
	return status;
}
Esempio n. 20
0
// ---------------------------------------------------------------------------
OSXWindowImpl::OSXWindowImpl(Window* window)
  : WindowImpl(window)
{
  OSStatus s;
  WindowClass wc = kDocumentWindowClass;
  WindowAttributes wa = 0
    // |kWindowCompositingAttribute
    |kWindowStandardDocumentAttributes
    |kWindowStandardHandlerAttribute
    |kWindowLiveResizeAttribute
  ;
  mRect.left = 100;
  mRect.right = mRect.left + 256;
  mRect.top = 100;
  mRect.bottom = mRect.top + 256;
  s = CreateNewWindow(wc,wa,&mRect,&mWindowRef);
  check_noerr(s); 
  EventTypeSpec typeList[] = {
    { kEventClassWindow,    kEventWindowClosed },
    { kEventClassWindow,    kEventWindowDrawContent },
    { kEventClassWindow,    kEventWindowBoundsChanged },
    { kEventClassKeyboard,  kEventRawKeyDown },
    { kEventClassKeyboard,  kEventRawKeyUp },
    { kEventClassMouse,     kEventMouseDown },
    { kEventClassMouse,     kEventMouseUp },
    { kEventClassMouse,     kEventMouseMoved },
    { kEventClassMouse,     kEventMouseDragged },
    { kEventClassMouse,     kEventMouseWheelMoved }
  };
  int numTypes = sizeof(typeList)/sizeof(EventTypeSpec);
  EventHandlerUPP handlerUPP = NewEventHandlerUPP(OSXWindowImpl::memberDelegate);
  EventTargetRef theTarget; 
  theTarget = GetWindowEventTarget(mWindowRef);
  InstallEventHandler(
    theTarget, handlerUPP,
    numTypes, typeList,
    this, 
    NULL
  );  	
  on_init();	
}
Esempio n. 21
0
int main(int argc, char* argv[])
{
    IBNibRef 		nibRef;
    WindowRef 		window;
    
    OSStatus		err;

    // Create a Nib reference passing the name of the nib file (without the .nib extension)
    // CreateNibReference only searches into the application bundle.
    err = CreateNibReference(CFSTR("main"), &nibRef);
    require_noerr( err, CantGetNibRef );
    
    // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar
    // object. This name is set in InterfaceBuilder when the nib is created.
    err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar"));
    require_noerr( err, CantSetMenuBar );
    
    // Then create a window. "MainWindow" is the name of the window object. This name is set in 
    // InterfaceBuilder when the nib is created.
    err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window);
    require_noerr( err, CantCreateWindow );

    // We don't need the nib reference anymore.
    DisposeNibReference(nibRef);
    
    // The window was created hidden so show it.
    ShowWindow( window );
	
	// Run the sample code
	err = RunRoundTripFlatteningSample( window );
	check_noerr( err );
    
    // Call the event loop
    RunApplicationEventLoop();

CantCreateWindow:
CantSetMenuBar:
CantGetNibRef:
	return err;
}
Esempio n. 22
0
OSStatus    AES_ECB_Init( AES_ECB_Context *inContext, uint32_t inMode, const uint8_t inKey[ kAES_ECB_Size ] )
{
#if( AES_UTILS_USE_COMMON_CRYPTO )
    OSStatus        err;
    
    inContext->cryptor = NULL;
    err = CCCryptorCreate( inMode, kCCAlgorithmAES128, kCCOptionECBMode, inKey, kAES_ECB_Size, NULL, &inContext->cryptor );
    check_noerr( err );
    if( err ) return( err );
#elif( AES_UTILS_USE_GLADMAN_AES )
    aes_init();
    if( inMode == kAES_ECB_Mode_Encrypt )   aes_encrypt_key128( inKey, &inContext->ctx.encrypt );
    else                                    aes_decrypt_key128( inKey, &inContext->ctx.decrypt );
    inContext->encrypt = inMode;
#elif( AES_UTILS_USE_USSL )
    if( inMode == kAES_ECB_Mode_Encrypt )   aes_setkey_enc( &inContext->ctx, (unsigned char *) inKey, kAES_ECB_Size * 8 );
    else                                    aes_setkey_dec( &inContext->ctx, (unsigned char *) inKey, kAES_ECB_Size * 8 );
    inContext->mode = inMode;
#else
    AES_set_encrypt_key( inKey, kAES_ECB_Size * 8, &inContext->key );
    inContext->cryptFunc = ( inMode == kAES_ECB_Mode_Encrypt ) ? AES_encrypt : AES_decrypt;
#endif
    return( kNoErr );
}
Esempio n. 23
0
static
OSStatus DrawSingleLine(
	DrawContextStruct *context )
{
	OSStatus				err;
	ATSTrapezoid			glyphBounds;
	ItemCount				numGlyphBounds;
	Fixed					lineHeight;
	ATSUTextMeasurement		xPosition;
	ATSUTextMeasurement		yPosition;
	
	// set the xPosition and the yPosition as the boundries. 
	xPosition = context->bounds.origin.x;
	yPosition = context->bounds.size.height;
	
	xPosition = xPosition << 16;
	yPosition = yPosition << 16;
	
	// we need to calculate where the line should start, so get the height of the
	// line.
	err = ATSUGetGlyphBounds( context->layoutObject, 0, 0, kATSUFromTextBeginning, kATSUToTextEnd, kATSUseCaretOrigins, 1, &glyphBounds, &numGlyphBounds );
	require_noerr( err, DrawSingleLine_err );
	
	lineHeight = glyphBounds.lowerRight.y - glyphBounds.upperRight.y;
	
	// adjust the line position based on the line height
	yPosition -= lineHeight;
	
	// draw!
	err = ATSUDrawText( context->layoutObject, kATSUFromTextBeginning, kATSUToTextEnd, xPosition, yPosition );
	check_noerr( err );
	
DrawSingleLine_err:
	
	return err;
}
Esempio n. 24
0
UINT32 
CHXDirectory::Rename(const char* szOldName, const char* szNewName)
{
	UINT32		err;
	
	// Unfortunately, the semantics of the parameters for this call aren't clear
	//
	// presumably, szOldName is a full path, or a partial path in the current directory
	// presumably, szNewName is a full path, or just a name
	
	CHXString	oldFileStr(szOldName);
	CHXString	newFileStr(szNewName);
	
	CHXFileSpecifier		oldFileSpec;
	CHXFileSpecifier		newFileSpec;
	CHXDirSpecifier			destDirSpec;
	
	if (oldFileStr.Find(':') >= 0)
	{
		// the old name has a colon; convert it to a file spec
		oldFileSpec = oldFileStr;
	}
	
	if (!oldFileSpec.IsSet())
	{
		// we couldn't get a valid FSSpec for the old name,
		// so assume it's relative to the current directory,
		// and make a file spec for it
		
		CHXDirSpecifier currPathSpec(m_strPath);
		
		oldFileSpec = currPathSpec.SpecifyChildFile((const char *) oldFileStr);
		
	}
	require_action(oldFileSpec.IsSet(), CantGetSourceForRename, err = fnfErr);
	
	if (newFileStr.Find(':') >= 0)
	{
		// the new name has a colon; try to convert it to a file spec
		newFileSpec = newFileStr;
	}
	
	// make a filespec for the destination folder
	//
	// use the directory of the new file if it was specified, otherwise use
	//   the directory of the old file
	FSRef destFSRef;
	
	if (newFileSpec.IsSet())
	{
		CHXDirSpecifier newParentDir = newFileSpec.GetParentDirectory();
		
		err = FSMakeFSRef(newFileSpec.GetVRefNum(), newParentDir.GetDirID(),
			NULL, &destFSRef);
	}
	
	else
	{
		CHXDirSpecifier oldParentDir = oldFileSpec.GetParentDirectory();

		err = FSMakeFSRef(oldFileSpec.GetVRefNum(), oldParentDir.GetDirID(),
			NULL, &destFSRef);
	}
	
	check_noerr(err);
	
	destDirSpec = destFSRef;
	
	// make sure we're not trying to move to another volume
	require_action(destDirSpec.GetVRefNum() == oldFileSpec.GetVRefNum(), CantChangeVolumes, err = HXR_FAILED);

	// they're on the same drive; possibly in different folders

	// use the name from the new file spec, if we have one, or else from the parameter
	HFSUniStr255 uniName;
	
	if (newFileSpec.IsSet())
	{
		uniName = newFileSpec.GetNameHFSUniStr255();
	}
	else
	{
		newFileStr.MakeHFSUniStr255(uniName, CFStringGetSystemEncoding());
	}
	
	FSRef newFSRef;
	
	err = FSMoveRenameObjectUnicode(oldFileSpec, destDirSpec, uniName.length, uniName.unicode,
		kTextEncodingUnknown, &newFSRef);
	if (err == dupFNErr)
	{
		err = FSDeleteObject(newFileSpec);
		if (err == noErr)
		{
			err = FSMoveRenameObjectUnicode(oldFileSpec, destDirSpec, uniName.length, uniName.unicode,
				kTextEncodingUnknown, &newFSRef);
		}
	}
		
		
CantChangeVolumes:
CantGetSourceForRename:

	if (err == noErr) 	err = HXR_OK;
	else			err = HXR_FAILED;
	
	
	return err;
}
Esempio n. 25
0
// Printer::EventHandler implementation
OSStatus
CSecondPage::OnAddPrinter(
				uint32_t		inInterfaceIndex,
				const char *	inName,	
				const char *	inType,	
				const char *	inDomain,
				bool			moreComing)
{
	Printer						*	printer;
	Service						*	service;
	CPrinterSetupWizardSheet	*	psheet;
	DWORD							printerNameCount;
	bool							newPrinter = false;
	OSStatus						err = kNoErr;

	check( IsWindow( m_hWnd ) );

	m_browseList.SetRedraw(FALSE);

	psheet = reinterpret_cast<CPrinterSetupWizardSheet*>(GetParent());
	require_quiet( psheet, exit );

	printer = Lookup( inName );

	if (printer == NULL)
	{
		try
		{
			printer = new Printer;
		}
		catch (...)
		{
			printer = NULL;
		}

		require_action( printer, exit, err = E_OUTOFMEMORY );

		printer->window		=	this;
		printer->name		=	inName;
		
		err = UTF8StringToStringObject(inName, printer->displayName);
		check_noerr( err );
		printer->actualName	=	printer->displayName;
		printer->installed	=	false;
		printer->deflt		=	false;
		printer->resolving	=	0;

		//
		// Compare this name against printers that are already installed
		// to avoid name clashes.  Rename as necessary
		// to come up with a unique name.
		//
		printerNameCount = 2;

		for (;;)
		{
			PrinterNameMap::iterator it;

			it = m_printerNames.find(printer->actualName);

			if (it != m_printerNames.end())
			{
				printer->actualName.Format(L"%s (%d)", printer->displayName, printerNameCount);
			}
			else
			{
				break;
			}

			printerNameCount++;
		}

		newPrinter = true;
	}

	check( printer );

	service = printer->LookupService( inType );

	if ( service != NULL )
	{
		service->refs++;
	}
	else
	{
		try
		{
			service = new Service;
		}
		catch (...)
		{
			service = NULL;
		}

		require_action( service, exit, err = E_OUTOFMEMORY );
		
		service->printer	=	printer;
		service->ifi		=	inInterfaceIndex;
		service->type		=	inType;
		service->domain		=	inDomain;
		service->qtotal		=	1;
		service->refs		=	1;
		service->serviceRef	=	NULL;

		printer->services.push_back( service );

		//
		// if the printer is selected, then we'll want to start a
		// resolve on this guy
		//

		if ( m_selected == printer )
		{
			StartResolve( service );
		}
	}
	
	if ( newPrinter )
	{
		printer->item = m_browseList.InsertItem(printer->displayName);

		m_browseList.SetItemData( printer->item, (DWORD_PTR) printer );

		m_printers.push_back( printer );
		
		m_browseList.SortChildren(TVI_ROOT);
		
		if ( printer->name == m_selectedName )
		{
			m_browseList.SelectItem( printer->item );
		}

		//
		// if the searching item is still in the list
		// get rid of it
		//
		// note that order is important here.  Insert the printer
		// item before removing the placeholder so we always have
		// an item in the list to avoid experiencing the bug
		// in Microsoft's implementation of CTreeCtrl
		//
		if (m_emptyListItem != NULL)
		{
			m_browseList.DeleteItem(m_emptyListItem);
			m_emptyListItem = NULL;
			m_browseList.EnableWindow(TRUE);
		}
	}

exit:

	if (!moreComing)
	{
		m_browseList.SetRedraw(TRUE);
		m_browseList.Invalidate();
	}

	return err;
}
Esempio n. 26
0
Printer*
CPrinterSetupWizardSheet::OnAddPrinter(
								uint32_t 		inInterfaceIndex,
								const char *	inName,	
								const char *	inType,	
								const char *	inDomain,
								bool			moreComing)
{
	Printer	*	printer = NULL;
	DWORD		printerNameCount;
	OSStatus	err;

	DEBUG_UNUSED( inInterfaceIndex );
	DEBUG_UNUSED( inType );
	DEBUG_UNUSED( inDomain );

	try
	{
		printer = new Printer;
	}
	catch (...)
	{
		printer = NULL;
	}

	require_action( printer, exit, err = E_OUTOFMEMORY );

	printer->window		=	this;
	printer->name		=	inName;
	
	err = UTF8StringToStringObject(inName, printer->displayName);
	check_noerr( err );
	printer->actualName	=	printer->displayName;
	printer->installed	=	false;
	printer->deflt		=	false;
	printer->resolving	=	0;

	// Compare this name against printers that are already installed
	// to avoid name clashes.  Rename as necessary
	// to come up with a unique name.

	printerNameCount = 2;

	for (;;)
	{
		CPrinterSetupWizardSheet::PrinterNames::iterator it;

		// <rdar://problem/4141221> Don't use find to do comparisons because we need to
		// do a case insensitive string comparison

		for ( it = m_printerNames.begin(); it != m_printerNames.end(); it++ )
		{
			if ( (*it).CompareNoCase( printer->actualName ) == 0 )
			{
				break;
			}
		}

		if (it != m_printerNames.end())
		{
			printer->actualName.Format(L"%s (%d)", printer->displayName, printerNameCount);
		}
		else
		{
			break;
		}

		printerNameCount++;
	}

	m_printers.push_back( printer );

	if ( GetActivePage() == &m_pgSecond )
	{
		m_pgSecond.OnAddPrinter( printer, moreComing );
	}

exit:

	return printer;
}
Esempio n. 27
0
void DNSSD_API
	ExplorerBarWindow::ResolveCallBack(
		DNSServiceRef			inRef,
		DNSServiceFlags			inFlags,
		uint32_t				inInterfaceIndex,
		DNSServiceErrorType		inErrorCode,
		const char *			inFullName,	
		const char *			inHostName, 
		uint16_t 				inPort,
		uint16_t 				inTXTSize,
		const char *			inTXT,
		void *					inContext )
{
	ExplorerBarWindow *			obj;
	ServiceHandlerEntry *		handler;
	OSStatus					err;
	
	DEBUG_UNUSED( inRef );
	DEBUG_UNUSED( inFlags );
	DEBUG_UNUSED( inErrorCode );
	DEBUG_UNUSED( inFullName );
	
	require_noerr( inErrorCode, exit );
	handler = (ServiceHandlerEntry *) inContext;
	check( handler );
	obj = handler->obj;
	check( obj );
	
	try
	{
		ResolveInfo *		resolve;
		int					idx;
		
		dlog( kDebugLevelNotice, "resolved %s on ifi %d to %s\n", inFullName, inInterfaceIndex, inHostName );
		
		// Stop resolving after the first good result.
		
		obj->StopResolve();
		
		// Post a message to the main thread so it can handle it since MFC is not thread safe.
		
		resolve = new ResolveInfo;
		require_action( resolve, exit, err = kNoMemoryErr );
		
		UTF8StringToStringObject( inHostName, resolve->host );

		// rdar://problem/3841564
		// 
		// strip trailing dot from hostname because some flavors of Windows
		// have trouble parsing it.

		idx = resolve->host.ReverseFind('.');

		if ((idx > 1) && ((resolve->host.GetLength() - 1) == idx))
		{
			resolve->host.Delete(idx, 1);
		}

		resolve->port		= ntohs( inPort );
		resolve->ifi		= inInterfaceIndex;
		resolve->handler	= handler;
		
		err = resolve->txt.SetData( inTXT, inTXTSize );
		check_noerr( err );
		
		obj->OnResolve(resolve);
	}
	catch( ... )
	{
		dlog( kDebugLevelError, "ResolveCallBack: exception thrown\n" );
	}

exit:
	return;
}
Esempio n. 28
0
void DNSSD_API
	ExplorerBarWindow::BrowseCallBack(
		DNSServiceRef 			inRef,
		DNSServiceFlags 		inFlags,
		uint32_t 				inInterfaceIndex,
		DNSServiceErrorType 	inErrorCode,
		const char *			inName,	
		const char *			inType,	
		const char *			inDomain,	
		void *					inContext )
{
	ServiceHandlerEntry *		obj;
	ServiceInfo *				service;
	OSStatus					err;
	
	DEBUG_UNUSED( inRef );
	
	obj		=	NULL;
	service = NULL;
	
	require_noerr( inErrorCode, exit );
	obj = reinterpret_cast < ServiceHandlerEntry * > ( inContext );
	check( obj );
	check( obj->obj );
	
	//
	// set the UI to hold off on updates
	//
	obj->obj->mTree.SetRedraw(FALSE);

	try
	{
		service = new ServiceInfo;
		require_action( service, exit, err = kNoMemoryErr );
		
		err = UTF8StringToStringObject( inName, service->displayName );
		check_noerr( err );

		service->name = strdup( inName );
		require_action( service->name, exit, err = kNoMemoryErr );
		
		service->type = strdup( inType );
		require_action( service->type, exit, err = kNoMemoryErr );
		
		service->domain = strdup( inDomain );
		require_action( service->domain, exit, err = kNoMemoryErr );
		
		service->ifi 		= inInterfaceIndex;
		service->handler	= obj;

		service->refs		= 1;
		
		if (inFlags & kDNSServiceFlagsAdd) obj->obj->OnServiceAdd   (service);
		else                               obj->obj->OnServiceRemove(service);
	
		service = NULL;
	}
	catch( ... )
	{
		dlog( kDebugLevelError, "BrowseCallBack: exception thrown\n" );
	}
	
exit:
	//
	// If no more coming, then update UI
	//
	if (obj && obj->obj && ((inFlags & kDNSServiceFlagsMoreComing) == 0))
	{
		obj->obj->mTree.SetRedraw(TRUE);
		obj->obj->mTree.Invalidate();
	}

	if( service )
	{
		delete service;
	}
}
Esempio n. 29
0
smcp_status_t
resend_test_request(void* context) {
	test_data_s* test_data = context;
	smcp_status_t status = 0;

	status = smcp_outbound_begin(smcp_get_current_instance(),test_data->outbound_code, test_data->outbound_tt);
	require_noerr(status,bail);

	status = smcp_outbound_set_uri(test_data->url, 0);
	require_noerr(status,bail);

	if (test_data->outbound_content_type != COAP_CONTENT_TYPE_UNKNOWN) {
		status = smcp_outbound_add_option_uint(COAP_OPTION_CONTENT_TYPE, test_data->outbound_content_type);
		require_noerr(status,bail);
	}

	if (test_data->extra & EXT_BLOCK_01) {
		struct coap_block_info_s block1_info;
		uint32_t resource_length = 200;
		uint32_t block_stop;

		coap_decode_block(&block1_info, test_data->block1_option + (1<<4));

		block_stop = block1_info.block_offset+block1_info.block_size;

		if (block1_info.block_offset < resource_length) {
			if (block_stop >= resource_length) {
				test_data->block1_option &= ~(1<<3);
			} else {
				test_data->block1_option |= (1<<3);
			}

			if (test_data->has_block1_option) {
				test_data->block1_option += (1<<4);
			}

			smcp_outbound_add_option_uint(COAP_OPTION_BLOCK1, test_data->block1_option);

			if (block1_info.block_m) {
				coap_size_t max_len = 0;
				uint32_t i;
				uint32_t block_stop;
				char* content = NULL;
				content = smcp_outbound_get_content_ptr(&max_len);

				if (!content) {
					status = SMCP_STATUS_FAILURE;
					goto bail;
				}

				block_stop = block1_info.block_offset+block1_info.block_size;

				for (i = block1_info.block_offset; i < block_stop; i++) {
					if (!((i + 1) % 64)) {
						content[i-block1_info.block_offset] = '\n';
					} else {
						content[i-block1_info.block_offset] = '0'+(i%10);
					}
				}

				status = smcp_outbound_set_content_len(MIN((coap_code_t)(block_stop-block1_info.block_offset),(coap_code_t)(resource_length-block1_info.block_offset)));
				require_noerr(status,bail);
			}
		}
	}

	if(test_data->extra & EXT_BLOCK_02) {
		smcp_outbound_add_option_uint(COAP_OPTION_BLOCK2, 1);	// 32 byte block size.
	}

	status = smcp_outbound_send();

	if(status) {
		check_noerr(status);
		fprintf(stderr,
			"smcp_outbound_send() returned error %d(%s).\n",
			status,
			smcp_status_to_cstr(status));
		goto bail;
	} else {
		test_data->outbound_attempts++;
	}

bail:
	return status;
}
Esempio n. 30
0
// Each time a new window is first opened, call this one time function to set up
// the text view
OSStatus
SetUpTheTextView( WindowRef window )
{
	OSStatus status = noErr;
	HIViewRef textView = NULL;
	HIViewRef scrollView = NULL;
	HIViewRef scrollParentView = NULL;
	
	CMLTEViewData* mlteData = NULL;
	
	// Get the HITextView from the window
	status = GetTextViewFromWindow( window, textView );
	
	require_action( textView != NULL, EXIT, status = paramErr );
	
	// make a new custom C++ object to hold MLTE related data
	mlteData = new CMLTEViewData();
	
	// DON'T FORGET TO DISPOSE THIS WHEN HITextView destructs!!!
	
	// put the custom object in the HITextView for this window
	// as a control property so that we can retrieve it later when we need it.
	status = TextViewStoreMLTEInstanceData( textView, mlteData );
	require_action( textView != NULL, EXIT, status = paramErr );
	
	// Now set the text view as we like it
	status = TextViewDefaultSettings( textView );
	check_noerr( status );
	status = TextViewAddActionNameMapper( textView );
	check_noerr( status );
	status = TextViewSetMargins( textView, 0 /*top*/, 0 /*left*/, 0 /*right*/ );
	check_noerr( status );
	
	// get fancy - try to add a picture behind the textView
	scrollView = HIViewGetSuperview( textView );
	scrollParentView = HIViewGetSuperview( scrollView );
	
	if( scrollParentView != NULL )
	{
		HIViewRef imageViewRef = AddImage( scrollParentView );
		if( imageViewRef != NULL )
		{
			HIRect scrollFrame;
			
			HIViewGetFrame( scrollView, &scrollFrame );
			HIViewSetFrame( imageViewRef, &scrollFrame );
			
			status = HIViewSetZOrder( scrollView, kHIViewZOrderAbove, imageViewRef );
			check_noerr( status );
			HIViewSetVisible(imageViewRef, true);
			
			status = TextViewSetBGAlpha( textView, 0.75 );
			check_noerr( status );
  
		}
	}
	
	// register for menu handing
	status = TextViewInstallMenuHandlers( textView );
  
	EXIT:
	return status;
}