1. Support inconsistent if opcode used in string/password opcode.

2. Add sample code of using inconsistent if opcode in string opcode.


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11196 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
ydong10
2010-12-23 06:47:50 +00:00
parent 7b546f7480
commit e2100bfa65
8 changed files with 89 additions and 69 deletions

View File

@ -910,9 +910,6 @@ DriverCallback (
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if ((Type == EFI_IFR_TYPE_STRING) && (Value->string == 0)) {
return EFI_INVALID_PARAMETER;
}
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This); PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);
@ -1166,6 +1163,15 @@ DriverCallback (
break; break;
case 0x2000: case 0x2000:
//
// Only used to update the state.
//
if ((Type == EFI_IFR_TYPE_STRING) && (Value->string == 0) &&
(PrivateData->PasswordState == BROWSER_STATE_SET_PASSWORD)) {
PrivateData->PasswordState = BROWSER_STATE_VALIDATE_PASSWORD;
return EFI_INVALID_PARAMETER;
}
// //
// When try to set a new password, user will be chanlleged with old password. // When try to set a new password, user will be chanlleged with old password.
// The Callback is responsible for validating old password input by user, // The Callback is responsible for validating old password input by user,

View File

@ -285,6 +285,9 @@ formset
key = 0x1236, key = 0x1236,
minsize = 6, minsize = 6,
maxsize = 40, maxsize = 40,
inconsistentif prompt = STRING_TOKEN(STR_STRING_CHECK_ERROR_POPUP),
pushthis != stringref(STRING_TOKEN(STR_STRING_CHECK))
endif
endstring; endstring;
// //

View File

@ -542,11 +542,13 @@ DestroyStorage (
/** /**
Free resources of a Statement. Free resources of a Statement.
@param FormSet Pointer of the FormSet
@param Statement Pointer of the Statement @param Statement Pointer of the Statement
**/ **/
VOID VOID
DestroyStatement ( DestroyStatement (
IN FORM_BROWSER_FORMSET *FormSet,
IN OUT FORM_BROWSER_STATEMENT *Statement IN OUT FORM_BROWSER_STATEMENT *Statement
) )
{ {
@ -608,17 +610,22 @@ DestroyStatement (
if (Statement->BufferValue != NULL) { if (Statement->BufferValue != NULL) {
FreePool (Statement->BufferValue); FreePool (Statement->BufferValue);
} }
if (Statement->Operand == EFI_IFR_STRING_OP || Statement->Operand == EFI_IFR_PASSWORD_OP) {
DeleteString(Statement->HiiValue.Value.string, FormSet->HiiHandle);
}
} }
/** /**
Free resources of a Form. Free resources of a Form.
@param FormSet Pointer of the FormSet
@param Form Pointer of the Form. @param Form Pointer of the Form.
**/ **/
VOID VOID
DestroyForm ( DestroyForm (
IN FORM_BROWSER_FORMSET *FormSet,
IN OUT FORM_BROWSER_FORM *Form IN OUT FORM_BROWSER_FORM *Form
) )
{ {
@ -645,7 +652,7 @@ DestroyForm (
Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link); Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link);
RemoveEntryList (&Statement->Link); RemoveEntryList (&Statement->Link);
DestroyStatement (Statement); DestroyStatement (FormSet, Statement);
} }
// //
@ -731,7 +738,7 @@ DestroyFormSet (
Form = FORM_BROWSER_FORM_FROM_LINK (Link); Form = FORM_BROWSER_FORM_FROM_LINK (Link);
RemoveEntryList (&Form->Link); RemoveEntryList (&Form->Link);
DestroyForm (Form); DestroyForm (FormSet, Form);
} }
} }
@ -1580,6 +1587,7 @@ ParseOpCodes (
CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_STRING; CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_STRING;
CurrentStatement->BufferValue = AllocateZeroPool (CurrentStatement->StorageWidth + sizeof (CHAR16)); CurrentStatement->BufferValue = AllocateZeroPool (CurrentStatement->StorageWidth + sizeof (CHAR16));
CurrentStatement->HiiValue.Value.string = NewString ((CHAR16*) CurrentStatement->BufferValue, FormSet->HiiHandle);
InitializeRequestElement (FormSet, CurrentStatement); InitializeRequestElement (FormSet, CurrentStatement);
break; break;
@ -1598,6 +1606,7 @@ ParseOpCodes (
CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_STRING; CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_STRING;
CurrentStatement->BufferValue = AllocateZeroPool ((CurrentStatement->StorageWidth + sizeof (CHAR16))); CurrentStatement->BufferValue = AllocateZeroPool ((CurrentStatement->StorageWidth + sizeof (CHAR16)));
CurrentStatement->HiiValue.Value.string = NewString ((CHAR16*) CurrentStatement->BufferValue, FormSet->HiiHandle);
InitializeRequestElement (FormSet, CurrentStatement); InitializeRequestElement (FormSet, CurrentStatement);
break; break;

View File

@ -1103,12 +1103,7 @@ SetupBrowser (
HiiValue = &Statement->HiiValue; HiiValue = &Statement->HiiValue;
TypeValue = &HiiValue->Value; TypeValue = &HiiValue->Value;
if (HiiValue->Type == EFI_IFR_TYPE_STRING) { if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {
//
// Create String in HII database for Configuration Driver to retrieve
//
HiiValue->Value.string = NewString ((CHAR16 *) Statement->BufferValue, Selection->FormSet->HiiHandle);
} else if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {
// //
// For OrderedList, passing in the value buffer to Callback() // For OrderedList, passing in the value buffer to Callback()
// //
@ -1124,13 +1119,6 @@ SetupBrowser (
&ActionRequest &ActionRequest
); );
if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
//
// Clean the String in HII Database
//
DeleteString (HiiValue->Value.string, Selection->FormSet->HiiHandle);
}
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
switch (ActionRequest) { switch (ActionRequest) {
case EFI_BROWSER_ACTION_REQUEST_RESET: case EFI_BROWSER_ACTION_REQUEST_RESET:

View File

@ -302,9 +302,8 @@ PasswordCallback (
EFI_STATUS Status; EFI_STATUS Status;
EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess; EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
EFI_BROWSER_ACTION_REQUEST ActionRequest; EFI_BROWSER_ACTION_REQUEST ActionRequest;
EFI_HII_VALUE *QuestionValue; EFI_IFR_TYPE_VALUE IfrTypeValue;
QuestionValue = &MenuOption->ThisTag->HiiValue;
ConfigAccess = Selection->FormSet->ConfigAccess; ConfigAccess = Selection->FormSet->ConfigAccess;
if (ConfigAccess == NULL) { if (ConfigAccess == NULL) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
@ -314,9 +313,9 @@ PasswordCallback (
// Prepare password string in HII database // Prepare password string in HII database
// //
if (String != NULL) { if (String != NULL) {
QuestionValue->Value.string = NewString (String, Selection->FormSet->HiiHandle); IfrTypeValue.string = NewString (String, Selection->FormSet->HiiHandle);
} else { } else {
QuestionValue->Value.string = 0; IfrTypeValue.string = 0;
} }
// //
@ -326,8 +325,8 @@ PasswordCallback (
ConfigAccess, ConfigAccess,
EFI_BROWSER_ACTION_CHANGING, EFI_BROWSER_ACTION_CHANGING,
MenuOption->ThisTag->QuestionId, MenuOption->ThisTag->QuestionId,
QuestionValue->Type, MenuOption->ThisTag->HiiValue.Type,
&QuestionValue->Value, &IfrTypeValue,
&ActionRequest &ActionRequest
); );
@ -335,7 +334,7 @@ PasswordCallback (
// Remove password string from HII database // Remove password string from HII database
// //
if (String != NULL) { if (String != NULL) {
DeleteString (QuestionValue->Value.string, Selection->FormSet->HiiHandle); DeleteString (IfrTypeValue.string, Selection->FormSet->HiiHandle);
} }
return Status; return Status;
@ -402,12 +401,14 @@ ProcessOptions (
UINTN Index2; UINTN Index2;
UINT8 *ValueArray; UINT8 *ValueArray;
UINT8 ValueType; UINT8 ValueType;
EFI_STRING_ID StringId;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
StringPtr = NULL; StringPtr = NULL;
Character[1] = L'\0'; Character[1] = L'\0';
*OptionString = NULL; *OptionString = NULL;
StringId = 0;
ZeroMem (FormattedNumber, 21 * sizeof (CHAR16)); ZeroMem (FormattedNumber, 21 * sizeof (CHAR16));
BufferSize = (gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow; BufferSize = (gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow;
@ -742,11 +743,17 @@ ProcessOptions (
Status = ReadString (MenuOption, gPromptForData, StringPtr); Status = ReadString (MenuOption, gPromptForData, StringPtr);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, StringPtr, NULL);
Status = ValidateQuestion(Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);
if (EFI_ERROR (Status)) {
HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL);
} else {
CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16)); CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16));
SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE); SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);
UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE); UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);
} }
}
FreePool (StringPtr); FreePool (StringPtr);
} else { } else {
@ -889,6 +896,39 @@ ProcessOptions (
// Compare two typed-in new passwords // Compare two typed-in new passwords
// //
if (StrCmp (StringPtr, TempString) == 0) { if (StrCmp (StringPtr, TempString) == 0) {
//
// Prepare the Question->HiiValue.Value.string for ValidateQuestion use.
//
if((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {
StringId = Question->HiiValue.Value.string;
Question->HiiValue.Value.string = NewString (StringPtr, Selection->FormSet->HiiHandle);
} else {
HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, StringPtr, NULL);
}
Status = ValidateQuestion(Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);
//
// Researve the Question->HiiValue.Value.string.
//
if((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {
DeleteString(Question->HiiValue.Value.string, Selection->FormSet->HiiHandle);
Question->HiiValue.Value.string = StringId;
}
if (EFI_ERROR (Status)) {
//
// Reset state machine for interactive password
//
if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {
PasswordCallback (Selection, MenuOption, NULL);
} else {
//
// Researve the Question->HiiValue.Value.string.
//
HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL);
}
} else {
// //
// Two password match, send it to Configuration Driver // Two password match, send it to Configuration Driver
// //
@ -898,6 +938,7 @@ ProcessOptions (
CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16)); CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16));
SetQuestionValue (Selection->FormSet, Selection->Form, Question, FALSE); SetQuestionValue (Selection->FormSet, Selection->Form, Question, FALSE);
} }
}
} else { } else {
// //
// Reset state machine for interactive password // Reset state machine for interactive password

View File

@ -2078,6 +2078,10 @@ LoadFormConfig (
return Status; return Status;
} }
if ((Question->Operand == EFI_IFR_STRING_OP) || (Question->Operand == EFI_IFR_PASSWORD_OP)) {
HiiSetString (FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL);
}
// //
// Check whether EfiVarstore with CallBack can be got. // Check whether EfiVarstore with CallBack can be got.
// //
@ -2109,12 +2113,7 @@ LoadFormConfig (
ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE; ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
HiiValue = &Question->HiiValue; HiiValue = &Question->HiiValue;
BufferValue = (UINT8 *) &Question->HiiValue.Value; BufferValue = (UINT8 *) &Question->HiiValue.Value;
if (HiiValue->Type == EFI_IFR_TYPE_STRING) { if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {
//
// Create String in HII database for Configuration Driver to retrieve
//
HiiValue->Value.string = NewString ((CHAR16 *) Question->BufferValue, FormSet->HiiHandle);
} else if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {
BufferValue = Question->BufferValue; BufferValue = Question->BufferValue;
} }
@ -2126,14 +2125,6 @@ LoadFormConfig (
(EFI_IFR_TYPE_VALUE *) BufferValue, (EFI_IFR_TYPE_VALUE *) BufferValue,
&ActionRequest &ActionRequest
); );
if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
//
// Clean the String in HII Database
//
DeleteString (HiiValue->Value.string, FormSet->HiiHandle);
}
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
switch (ActionRequest) { switch (ActionRequest) {
case EFI_BROWSER_ACTION_REQUEST_RESET: case EFI_BROWSER_ACTION_REQUEST_RESET:

View File

@ -341,7 +341,6 @@ RefreshForm (
UI_MENU_SELECTION *Selection; UI_MENU_SELECTION *Selection;
FORM_BROWSER_STATEMENT *Question; FORM_BROWSER_STATEMENT *Question;
EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess; EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
EFI_HII_VALUE *HiiValue;
EFI_BROWSER_ACTION_REQUEST ActionRequest; EFI_BROWSER_ACTION_REQUEST ActionRequest;
if (gMenuRefreshHead != NULL) { if (gMenuRefreshHead != NULL) {
@ -384,31 +383,14 @@ RefreshForm (
ConfigAccess = Selection->FormSet->ConfigAccess; ConfigAccess = Selection->FormSet->ConfigAccess;
if (((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) && (ConfigAccess != NULL)) { if (((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) && (ConfigAccess != NULL)) {
ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE; ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
HiiValue = &Question->HiiValue;
if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
//
// Create String in HII database for Configuration Driver to retrieve
//
HiiValue->Value.string = NewString ((CHAR16 *) Question->BufferValue, Selection->FormSet->HiiHandle);
}
Status = ConfigAccess->Callback ( Status = ConfigAccess->Callback (
ConfigAccess, ConfigAccess,
EFI_BROWSER_ACTION_CHANGING, EFI_BROWSER_ACTION_CHANGING,
Question->QuestionId, Question->QuestionId,
HiiValue->Type, Question->HiiValue.Type,
&HiiValue->Value, &Question->HiiValue.Value,
&ActionRequest &ActionRequest
); );
if (HiiValue->Type == EFI_IFR_TYPE_STRING) {
//
// Clean the String in HII Database
//
DeleteString (HiiValue->Value.string, Selection->FormSet->HiiHandle);
}
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
switch (ActionRequest) { switch (ActionRequest) {
case EFI_BROWSER_ACTION_REQUEST_RESET: case EFI_BROWSER_ACTION_REQUEST_RESET: