Ejemplo n.º 1
0
/***********************************************************************
 *
 * FUNCTION:    PrvUpdateTimeFields
 *
 * DESCRIPTION: Update the current time and new time displayed if they have
 *					 changed in the time zone dialog. Also used to update these
 *					 times in the daylight saving time dialog.
 *
 * PARAMETERS:  frm	 - the time zone or daylight saving time dialog
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			peter	4/13/00	Initial Revision
 *
 ***********************************************************************/
static void PrvUpdateTimeFields (FormPtr frm,
	DateTimeType *currentTimeP, DateTimeType *newTimeP,
	MemHandle currentTimeHandle, MemHandle newTimeHandle,
	UInt16 currentTimeFieldID, UInt16 newTimeFieldID)
{
	DateTimeType now, then;
	UInt32 delta;

	TimSecondsToDateTime(TimGetSeconds(), &now);

	if (now.minute != currentTimeP->minute ||
		now.hour != currentTimeP->hour ||
		now.day != currentTimeP->day ||
		now.month != currentTimeP->month ||
		now.year != currentTimeP->year)
	{
		then = *currentTimeP;
		*currentTimeP = now;
		PrvSetTimeField(frm, currentTimeFieldID, currentTimeHandle, currentTimeP, true);
		if (FldGetTextLength(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, newTimeFieldID))) != 0)
		{
			delta = TimDateTimeToSeconds(newTimeP) - TimDateTimeToSeconds(&then);
			TimSecondsToDateTime(TimDateTimeToSeconds(currentTimeP) + delta, newTimeP);
			PrvSetTimeField(frm, newTimeFieldID, newTimeHandle, newTimeP, true);
		}
	}
} // PrvUpdateTimeFields
Ejemplo n.º 2
0
// Show a registration dialog where a user enters registration code.
// if fDeleteAfterCancel is set to true, we'll remove the registration code
// from preferences. We want this behavior if "re-enter registration code" was
// pressed after registration process failed (this was an invalid registration code
// so we don't want the client to send it to the server -> so we erase it).
// If this dialog was brought by "Register" menu item, then we don't want to
// touch the registration code (we assume it's correct)
// TODO: maybe if we're called from "Register" menu and registartion code
// is already present (i.e. valid) we should make it harder to edit it by accident
// (e.g. make it read only until user makes some action like pressing a "edit" button)
static void MainFormHandleRegister(AppContext* appContext, bool fDeleteAfterCancel)
{
    FormType* form=FrmInitForm(formRegistration);
    if (!form)
    {
        FrmAlert(alertMemError);
        return;
    }

    DefaultFormInit(appContext, form);
    FrmSetEventHandler(form, RegistrationFormHandleEvent);
    UInt16 button=FrmDoDialog(form);
    if (buttonRegister!=button)
    {
        if (fDeleteAfterCancel)
        {
            appContext->prefs.regCode[0] = '\0';
            SavePreferencesInoah(appContext);
        }
        goto Exit;
    }

    UInt16 index=FrmGetObjectIndex(form, fieldRegCode);
    Assert(frmInvalidObjectId!=index);
    const FieldType* field=static_cast<FieldType*>(FrmGetObjectPtr(form, index));
    Assert(field);
    const char* regCode=FldGetTextPtr(field);
    int regCodeLen = (int)FldGetTextLength(field);

    if ( (NULL != regCode) && (regCodeLen>0) )
    {
        // save the registration code in preferences so that we can
        // send it in all requests
        if (regCodeLen>MAX_REG_CODE_LENGTH)
        {
            // this is laziness: reg code longer than MAX_REG_CODE_LENGTH
            // is invalid for sure so we should just display such message
            // but we'll just use truncated version and go on with normal
            // processing
            regCodeLen=MAX_REG_CODE_LENGTH;
        }
        SafeStrNCopy((char*)appContext->prefs.regCode, sizeof(appContext->prefs.regCode), regCode, regCodeLen);
        RemoveNonDigits( (char*)appContext->prefs.regCode );
        // save preferences just for sure - so that we don't loose regCode
        // in case of a crash
        SavePreferencesInoah(appContext);
        // send a registration query to the server so that the user
        // knows if he registered correctly
        // it doesn't really matter, in the long run, because every time
        // we send a request, we also send the registration code and
        // if it's not correct, we'll reject the query
        StartRegistration(appContext, (const char*)appContext->prefs.regCode);
    }
Exit:
    FrmDeleteForm(form);
}
Ejemplo n.º 3
0
int AppendField( FieldPtr fld, CharPtr str, UInt len )
{
	Err err=0;
	CharPtr  s;
	VoidHand h;
	UInt prevlen;

	h=(VoidHand)FldGetTextHandle(fld);

	if(h==NULL) {
		h=MemHandleNew(len+1);
		if(h==NULL) return(-1);
		s=MemHandleLock(h);
		StrNCopy(s, str, len);
		s[len]=0;
		MemHandleUnlock(h);
	} else {
		prevlen=FldGetTextLength(fld);

		FldSetTextHandle(fld, NULL);

		if( MemHandleSize(h)<=(prevlen+len)) {
			err=MemHandleResize( h, prevlen+len+1 );
		}
		if( err!=0 ) return(-1);

		s=MemHandleLock(h);
		StrNCopy(s+prevlen, str, len);
		s[len+prevlen]=0;
		MemHandleUnlock(h);
	}

	FldSetTextHandle(fld, (Handle)h);
	/* FldDrawField(fld); */

	return( 0 );
}
Ejemplo n.º 4
0
static Boolean MyMainFormHandleEvent( EventPtr event )
{
	Boolean handled = false;
	Int i;
	FieldPtr fld;
	FormPtr frm;
	Word readerNum;

#ifdef __GCC__
	CALLBACK_PROLOGUE
#endif

	frm = FrmGetActiveForm();

	switch( event->eType ) {
		case frmOpenEvent:
			UpdateScrollbar( dataFieldID, dataSbarID );
			FrmDrawForm( frm );
			break;
		case ctlSelectEvent:
			if( event->data.ctlSelect.controlID==updateButtonID ) {
				handled=true;

				if( readerType==SC_READER_UNKNOWN ) {
					FrmAlert( alert6FormID );
					break;
				}

				FrmHideObject(frm, FrmGetObjectIndex(frm, updateButtonID));

				i=scdir();

				UpdateScrollbar( dataFieldID, dataSbarID );

				if( i==1 ) FrmAlert(alert1FormID);
				else if( i==2 ) FrmAlert(alert2FormID);
				else if( i==3 ) FrmAlert(alert3FormID);
				else if( i==4 ) FrmAlert(alert4FormID);
				else if( i>4 ) FrmAlert(alert5FormID);

				FrmShowObject(frm, FrmGetObjectIndex(frm, updateButtonID));
			}
			break;
		case menuEvent:
			fld = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, dataFieldID)); 
			switch( event->data.menu.itemID ) {
				case selectMenuID:
					handled = true;
					FldSetSelection (fld, 0, FldGetTextLength (fld));
					break;
				case copyMenuID:
					handled = true;
					FldCopy(fld);
					break;
				case readerMenuID:
					handled = true;

					switch(readerType) {
						case SC_READER_DUMBMOUSE:
							readerNum=0;
							break;
						case SC_READER_TOWITOKO:
							readerNum=1;
							break;
						default:
							readerNum=-1;
							break;
					}

					readerNum = ChooseReader( readerNum );

					switch(readerNum) {
						case 0:
							readerType=SC_READER_DUMBMOUSE;
							break;
						case 1:
							readerType=SC_READER_TOWITOKO;
							break;
						default:
							readerType=SC_READER_UNKNOWN;
							break;
					}

					break;
				case aboutMenuID:
					handled = true;
					FrmAlert(aboutFormID);
					break;
				case helpMenuID:
					handled = true;
					FrmAlert(helpFormID);
					break;
				default:
					break;
			}
		case fldChangedEvent:
			if( event->data.fldChanged.fieldID==dataFieldID ) {
				UpdateScrollbar( dataFieldID, dataSbarID );
				handled=true;
			}
			break;
		case sclRepeatEvent:
			if( event->data.sclRepeat.scrollBarID==dataSbarID ) {
				ScrollLines( dataFieldID, dataSbarID,
					event->data.sclRepeat.newValue -
					event->data.sclRepeat.value, false );
			}
			break;
		case keyDownEvent:
			if( event->data.keyDown.chr == pageUpChr ) {
				PageScroll( dataFieldID, dataSbarID, up );
				handled = true;
			} else if( event->data.keyDown.chr == pageDownChr ) {
				PageScroll( dataFieldID, dataSbarID, down );
				handled = true;
			}
            break;
		default:
			break;
	}

#ifdef __GCC__
	CALLBACK_EPILOGUE
#endif

	return handled;
}
Ejemplo n.º 5
0
/********************************************************************************
 * Description: this is the function responsible for checking the 
 * input password value of the authentication form. 
 * ******************************************************************************/ 
static void 
checkPassword (void) 
{
	MemPtr pass1, scratch = NULL;
	char *input;

	UInt16 index = 0;
	MemHandle rec;
	mdKey in;
	ListType *list;
	
		// compact text and get a pointer.
		FldCompactText (GetObjectFromActiveForm (PasswordField));
	input = FldGetTextPtr (GetObjectFromActiveForm (PasswordField));
	list = GetObjectFromActiveForm (selPopupList);
	
		// if SysPass is defined, free it. this happens when Strip locks
		// itself after the timeout.
		if (SysPass)
		MemPtrFree (SysPass);
	
		// if its the first time the user has used the program we need 
		// to set some things up. 
		if (input && StrLen (input))
		
	{
		
			// read the password from the database, decrypt with the input text.
			if ((rec = DmQueryRecord (PasswordDB, index)))
			
		{
			pass1 = MemHandleLock (rec);
			if ((scratch = MemPtrNew (24)))
				
			{
				UInt16 chk = LstGetSelection (list);
				
					//printf("%d\n", LstGetSelection(list)); 
					switch (chk)
					
				{
					case 0:
						UnpackPassword_old (pass1, scratch, input, 1);
						break;
					case 1:
						UnpackPassword_old (pass1, scratch, input, 2);
						break;
					case 2:
						UnpackPassword_old (pass1, scratch, input, 0);
						break;
				}
			}
			MemHandleUnlock (rec);
		}
		
			// the message digest of the password they provided should be exactly the
			// same as the message digest that was just decrypted out of the password
			// database. Do a MemCmp to make sure they are the same.
		md5_string (input, in);

		if ((!MemCmp (in, scratch, 16)) && input)
			
		{
			
				// if so, copy the password onto the system-password
		if ((SysPass = MemPtrNew (StrLen (input) + 1)))
				StrCopy (SysPass, input);
		if (scratch)
				MemPtrFree (scratch);
		md_string(SysPass, NewSysPass);
		cryptSwitch (LstGetSelection (list));
		}
		
		else
			
		{
			
				// FAILURE!!!!!!
				// free the memory and tell the user they entered the wrong password.
				FieldType *fld = GetObjectFromActiveForm (PasswordField);
			FrmCustomAlert (GenericError,
							  "The password you entered is incorrect", NULL,
							  NULL);
				FldSetSelection (fld, 0, FldGetTextLength (fld));
			LstDrawList (list);
			if (scratch)
				
			{
				MemPtrFree (scratch);
				SysPass = NULL;
			}
		}
	}
	
		// null string is always wrong!!!
		else
		
	{
		FrmCustomAlert (GenericError, "You forgot to enter a password!!",
						 NULL, NULL);
		LstDrawList (list);
	}
}