Fix the conflicted function names to new HII library.
[edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / Strings.c
blobd9cc39eb8d54d6f829479199c211ecdb94114ca5
1 /**@file
2 This file implements the protocol functions related to string package.
4 Copyright (c) 2006 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 **/
16 #include "HiiDatabase.h"
18 typedef struct {
19 CHAR8 *Iso639;
20 CHAR8 *Rfc3066;
21 } ISO639TORFC3066MAP;
23 ISO639TORFC3066MAP Iso639ToRfc3066Map [] = {
24 {"eng", "en-US"},
25 {"fra", "fr-FR"},
28 CHAR8 *
29 ConvertIso639ToRfc3066 (
30 CHAR8 *Iso638Lang
33 UINTN Index;
34 CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];
36 AsciiStrnCpy (AsciiLanguage, Iso638Lang, sizeof (AsciiLanguage));
37 for (Index = 0; Index < ISO_639_2_ENTRY_SIZE + 1; Index ++) {
38 if (AsciiLanguage [Index] == 0) {
39 break;
40 } else if (AsciiLanguage [Index] >= 'A' && AsciiLanguage [Index] <= 'Z') {
41 AsciiLanguage [Index] = (CHAR8) (AsciiLanguage [Index] - 'A' + 'a');
45 for (Index = 0; Index < sizeof (Iso639ToRfc3066Map) / sizeof (Iso639ToRfc3066Map[0]); Index++) {
46 if (AsciiStrnCmp (AsciiLanguage, Iso639ToRfc3066Map[Index].Iso639, AsciiStrSize (AsciiLanguage)) == 0) {
47 return Iso639ToRfc3066Map[Index].Rfc3066;
51 return (CHAR8 *) NULL;
54 /**
55 Test if all of the characters in a string have corresponding font characters.
57 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and
58 return EFI_UNSUPPORTED.
60 @param This A pointer to the EFI_HII_PROTOCOL instance.
61 @param StringToTest A pointer to a Unicode string.
62 @param FirstMissing A pointer to an index into the string. On input, the index of
63 the first character in the StringToTest to examine. On exit, the index
64 of the first character encountered for which a glyph is unavailable.
65 If all glyphs in the string are available, the index is the index of the terminator
66 of the string.
67 @param GlyphBufferSize A pointer to a value. On output, if the function returns EFI_SUCCESS,
68 it contains the amount of memory that is required to store the string¡¯s glyph equivalent.
70 @retval EFI_UNSUPPORTED The function performs nothing and return EFI_UNSUPPORTED.
71 **/
72 EFI_STATUS
73 EFIAPI
74 HiiTestString (
75 IN EFI_HII_PROTOCOL *This,
76 IN CHAR16 *StringToTest,
77 IN OUT UINT32 *FirstMissing,
78 OUT UINT32 *GlyphBufferSize
81 ASSERT (FALSE);
83 return EFI_UNSUPPORTED;
87 /**
88 Find the corressponding TAG GUID from a Framework HII Handle given.
90 @param Private The HII Thunk Module Private context.
91 @param FwHiiHandle The Framemwork HII Handle.
92 @param TagGuid The output of TAG GUID found.
94 @return NULL If Framework HII Handle is invalid.
95 @return The corresponding HII Thunk Context.
96 **/
97 EFI_STATUS
98 GetTagGuidByFwHiiHandle (
99 IN CONST HII_THUNK_PRIVATE_DATA *Private,
100 IN FRAMEWORK_EFI_HII_HANDLE FwHiiHandle,
101 OUT EFI_GUID *TagGuid
104 LIST_ENTRY *Link;
105 HII_THUNK_CONTEXT *ThunkContext;
107 ASSERT (TagGuid != NULL);
109 Link = GetFirstNode (&Private->ThunkContextListHead);
110 while (!IsNull (&Private->ThunkContextListHead, Link)) {
112 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);
114 if (FwHiiHandle == ThunkContext->FwHiiHandle) {
115 CopyGuid (TagGuid, &ThunkContext->TagGuid);
116 return EFI_SUCCESS;
119 Link = GetNextNode (&Private->ThunkContextListHead, Link);
122 return EFI_NOT_FOUND;
126 Create or update the String given a new string and String ID.
128 @param ThunkContext The Thunk Context.
129 @param Rfc3066AsciiLanguage The RFC 3066 Language code in ASCII string format.
130 @param NewString The new string.
131 @param StringId The String ID. If StringId is 0, a new String Token
132 is created. Otherwise, the String Token StringId is
133 updated.
136 @retval EFI_SUCCESS The new string is created or updated successfully.
137 The new String Token ID is returned in StringId if
138 *StringId is 0 on input.
139 @return Others The update of string failed.
142 EFI_STATUS
143 UpdateString (
144 IN CONST HII_THUNK_CONTEXT *ThunkContext,
145 IN CONST CHAR8 *Rfc3066AsciiLanguage,
146 IN CHAR16 *NewString,
147 IN OUT STRING_REF *StringId
150 EFI_STRING_ID NewStringId;
151 EFI_STATUS Status;
154 NewStringId = 0;
156 if (*StringId == 0) {
158 // Create a new string token.
160 if (Rfc3066AsciiLanguage == NULL) {
162 // For all languages in the package list.
164 Status = HiiLibNewString (ThunkContext->UefiHiiHandle, &NewStringId, NewString);
165 } else {
167 // For specified language.
169 Status = mHiiStringProtocol->NewString (
170 mHiiStringProtocol,
171 ThunkContext->UefiHiiHandle,
172 &NewStringId,
173 Rfc3066AsciiLanguage,
174 NULL,
175 NewString,
176 NULL
179 } else {
181 // Update the existing string token.
183 if (Rfc3066AsciiLanguage == NULL) {
185 // For all languages in the package list.
187 Status = HiiLibSetString (ThunkContext->UefiHiiHandle, *StringId, NewString);
188 } else {
190 // For specified language.
192 Status = mHiiStringProtocol->SetString (
193 mHiiStringProtocol,
194 ThunkContext->UefiHiiHandle,
195 *StringId,
196 Rfc3066AsciiLanguage,
197 NewString,
198 NULL
203 if (!EFI_ERROR (Status)) {
204 if (*StringId == 0) {
206 // When creating new string, return the newly created String Token.
208 *StringId = NewStringId;
210 } else {
212 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.
214 *StringId = 0;
217 return Status;
221 Create or update a String Token in a String Package.
223 If *Reference == 0, a new String Token is created.
225 @param This A pointer to the EFI_HII_PROTOCOL instance.
226 @param Language Pointer to a NULL-terminated string containing a single ISO 639-2 language
227 identifier, indicating the language to print. A string consisting of
228 all spaces indicates that the string is applicable to all languages.
229 @param Handle The handle of the language pack to which the string is to be added.
230 @param Token The string token assigned to the string.
231 @param NewString The string to be added.
234 @retval EFI_SUCCESS The string was effectively registered.
235 @retval EFI_INVALID_PARAMETER The Handle was unknown. The string is not created or updated in the
236 the string package.
239 EFI_STATUS
240 EFIAPI
241 HiiNewString (
242 IN EFI_HII_PROTOCOL *This,
243 IN CHAR16 *Language,
244 IN FRAMEWORK_EFI_HII_HANDLE Handle,
245 IN OUT STRING_REF *Reference,
246 IN CHAR16 *NewString
249 EFI_STATUS Status;
250 HII_THUNK_PRIVATE_DATA *Private;
251 EFI_GUID TagGuid;
252 LIST_ENTRY *Link;
253 HII_THUNK_CONTEXT *ThunkContext;
254 HII_THUNK_CONTEXT *StringPackThunkContext;
255 EFI_STRING_ID StringId;
256 EFI_STRING_ID LastStringId;
257 CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];
258 CHAR16 LanguageCopy[ISO_639_2_ENTRY_SIZE + 1];
259 CHAR8 *Rfc3066AsciiLanguage;
261 LastStringId = (EFI_STRING_ID) 0;
262 StringId = (EFI_STRING_ID) 0;
263 Rfc3066AsciiLanguage = NULL;
265 if (Language != NULL) {
266 ZeroMem (AsciiLanguage, sizeof (AsciiLanguage));;
267 ZeroMem (LanguageCopy, sizeof (LanguageCopy));
268 CopyMem (LanguageCopy, Language, ISO_639_2_ENTRY_SIZE * sizeof (CHAR16));
269 UnicodeStrToAsciiStr (LanguageCopy, AsciiLanguage);
270 Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (AsciiLanguage);
271 ASSERT (Rfc3066AsciiLanguage != NULL);
274 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
276 StringPackThunkContext = FwHiiHandleToThunkContext (Private, Handle);
277 if (StringPackThunkContext == NULL) {
278 return EFI_INVALID_PARAMETER;
281 if (StringPackThunkContext->SharingStringPack) {
282 Status = GetTagGuidByFwHiiHandle (Private, Handle, &TagGuid);
283 ASSERT_EFI_ERROR (Status);
285 Link = GetFirstNode (&Private->ThunkContextListHead);
286 while (!IsNull (&Private->ThunkContextListHead, Link)) {
287 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);
289 if (CompareGuid (&TagGuid, &ThunkContext->TagGuid)) {
290 if (ThunkContext->SharingStringPack) {
291 StringId = *Reference;
292 Status = UpdateString (ThunkContext, Rfc3066AsciiLanguage, NewString, &StringId);
293 if (EFI_ERROR (Status)) {
294 break;
297 DEBUG_CODE_BEGIN ();
298 if (*Reference == 0) {
300 // When creating new string token, make sure all created token is the same
301 // for all string packages registered using FW HII interface.
303 if (LastStringId == (EFI_STRING_ID) 0) {
304 LastStringId = StringId;
305 } else {
306 if (LastStringId != StringId) {
307 ASSERT(FALSE);
311 DEBUG_CODE_END ();
316 Link = GetNextNode (&Private->ThunkContextListHead, Link);
318 } else {
319 StringId = *Reference;
320 Status = UpdateString (StringPackThunkContext, Rfc3066AsciiLanguage, NewString, &StringId);
323 if (!EFI_ERROR (Status)) {
324 if (*Reference == 0) {
325 *Reference = StringId;
327 } else {
329 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.
331 Status = EFI_INVALID_PARAMETER;
334 return Status;
338 This function removes any new strings that were added after the initial string export for this handle.
339 UEFI HII String Protocol does not have Reset String function. This function perform nothing.
341 @param This A pointer to the EFI_HII_PROTOCOL instance.
342 @param Handle The HII handle on which the string resides.
344 @retval EFI_SUCCESS This function is a NOP and always return EFI_SUCCESS.
347 EFI_STATUS
348 EFIAPI
349 HiiResetStrings (
350 IN EFI_HII_PROTOCOL *This,
351 IN FRAMEWORK_EFI_HII_HANDLE Handle
354 return EFI_SUCCESS;
358 This function extracts a string from a package already registered with the EFI HII database.
360 @param This A pointer to the EFI_HII_PROTOCOL instance.
361 @param Handle The HII handle on which the string resides.
362 @param Token The string token assigned to the string.
363 @param Raw If TRUE, the string is returned unedited in the internal storage format described
364 above. If false, the string returned is edited by replacing <cr> with <space>
365 and by removing special characters such as the <wide> prefix.
366 @param LanguageString Pointer to a NULL-terminated string containing a single ISO 639-2 language
367 identifier, indicating the language to print. If the LanguageString is empty (starts
368 with a NULL), the default system language will be used to determine the language.
369 @param BufferLength Length of the StringBuffer. If the status reports that the buffer width is too
370 small, this parameter is filled with the length of the buffer needed.
371 @param StringBuffer The buffer designed to receive the characters in the string. Type EFI_STRING is
372 defined in String.
374 @retval EFI_INVALID_PARAMETER If input parameter is invalid.
375 @retval EFI_BUFFER_TOO_SMALL If the *BufferLength is too small.
376 @retval EFI_SUCCESS Operation is successful.
379 EFI_STATUS
380 EFIAPI
381 HiiThunkGetString (
382 IN EFI_HII_PROTOCOL *This,
383 IN FRAMEWORK_EFI_HII_HANDLE Handle,
384 IN STRING_REF Token,
385 IN BOOLEAN Raw,
386 IN CHAR16 *LanguageString,
387 IN OUT UINTN *BufferLengthTemp,
388 OUT EFI_STRING StringBuffer
391 CHAR8 *Iso639AsciiLanguage;
392 HII_THUNK_PRIVATE_DATA *Private;
393 CHAR8 *Rfc3066AsciiLanguage;
394 EFI_HII_HANDLE UefiHiiHandle;
395 EFI_STATUS Status;
397 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
399 Iso639AsciiLanguage = NULL;
400 Rfc3066AsciiLanguage = NULL;
402 if (LanguageString != NULL) {
403 Iso639AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);
404 if (Iso639AsciiLanguage == NULL) {
405 return EFI_OUT_OF_RESOURCES;
407 UnicodeStrToAsciiStr (LanguageString, Iso639AsciiLanguage);
410 // Caller of Framework HII Interface uses the Language Identification String defined
411 // in Iso639. So map it to the Language Identifier defined in RFC3066.
413 Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (Iso639AsciiLanguage);
416 // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to
417 // Iso639ToRfc3066Map.
419 ASSERT (Rfc3066AsciiLanguage != NULL);
423 UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);
424 if (UefiHiiHandle == NULL) {
425 Status = EFI_NOT_FOUND;
426 goto Done;
429 if (Rfc3066AsciiLanguage == NULL) {
430 Status = HiiLibGetString (UefiHiiHandle, Token, StringBuffer, BufferLengthTemp);
431 } else {
432 Status = mHiiStringProtocol->GetString (
433 mHiiStringProtocol,
434 Rfc3066AsciiLanguage,
435 UefiHiiHandle,
436 Token,
437 StringBuffer,
438 BufferLengthTemp,
439 NULL
443 Done:
444 if (Iso639AsciiLanguage != NULL) {
445 FreePool (Iso639AsciiLanguage);
448 return Status;
453 This function allows a program to extract a part of a string of not more than a given width.
454 With repeated calls, this allows a calling program to extract "lines" of text that fit inside
455 columns. The effort of measuring the fit of strings inside columns is localized to this call.
457 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and
458 return EFI_UNSUPPORTED.
460 @param This A pointer to the EFI_HII_PROTOCOL instance.
461 @param Handle The HII handle on which the string resides.
462 @param Token The string token assigned to the string.
463 @param Raw If TRUE, the string is returned unedited in the internal storage format described
464 above. If false, the string returned is edited by replacing <cr> with <space>
465 and by removing special characters such as the <wide> prefix.
466 @param LanguageString Pointer to a NULL-terminated string containing a single ISO 639-2 language
467 identifier, indicating the language to print. If the LanguageString is empty (starts
468 with a NULL), the default system language will be used to determine the language.
469 @param BufferLength Length of the StringBuffer. If the status reports that the buffer width is too
470 small, this parameter is filled with the length of the buffer needed.
471 @param StringBuffer The buffer designed to receive the characters in the string. Type EFI_STRING is
472 defined in String.
474 @retval EFI_UNSUPPORTED.
476 EFI_STATUS
477 EFIAPI
478 HiiGetLine (
479 IN EFI_HII_PROTOCOL *This,
480 IN FRAMEWORK_EFI_HII_HANDLE Handle,
481 IN STRING_REF Token,
482 IN OUT UINT16 *Index,
483 IN UINT16 LineWidth,
484 IN CHAR16 *LanguageString,
485 IN OUT UINT16 *BufferLength,
486 OUT EFI_STRING StringBuffer
489 ASSERT (FALSE);
490 return EFI_UNSUPPORTED;