]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c
HII Library Class interface refine.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / Strings.c
CommitLineData
4259256b 1/**@file\r
0368663f 2 This file implements the protocol functions related to string package.\r
3 \r
4259256b 4Copyright (c) 2006 - 2008, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15\r
16#include "HiiDatabase.h"\r
17\r
133a9dfb 18typedef struct {\r
19 CHAR8 *Iso639;\r
20 CHAR8 *Rfc3066;\r
21} ISO639TORFC3066MAP;\r
22\r
23ISO639TORFC3066MAP Iso639ToRfc3066Map [] = {\r
24 {"eng", "en-US"},\r
25 {"fra", "fr-FR"},\r
26};\r
27\r
28CHAR8 *\r
29ConvertIso639ToRfc3066 (\r
30 CHAR8 *Iso638Lang\r
31 )\r
32{\r
33 UINTN Index;\r
66df2531
LG
34 CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];\r
35 \r
36 AsciiStrnCpy (AsciiLanguage, Iso638Lang, sizeof (AsciiLanguage));\r
37 for (Index = 0; Index < ISO_639_2_ENTRY_SIZE + 1; Index ++) {\r
38 if (AsciiLanguage [Index] == 0) {\r
39 break;\r
40 } else if (AsciiLanguage [Index] >= 'A' && AsciiLanguage [Index] <= 'Z') {\r
98b16b9d 41 AsciiLanguage [Index] = (CHAR8) (AsciiLanguage [Index] - 'A' + 'a');\r
66df2531
LG
42 }\r
43 }\r
133a9dfb 44\r
45 for (Index = 0; Index < sizeof (Iso639ToRfc3066Map) / sizeof (Iso639ToRfc3066Map[0]); Index++) {\r
66df2531 46 if (AsciiStrnCmp (AsciiLanguage, Iso639ToRfc3066Map[Index].Iso639, AsciiStrSize (AsciiLanguage)) == 0) {\r
133a9dfb 47 return Iso639ToRfc3066Map[Index].Rfc3066;\r
48 }\r
49 }\r
50\r
51 return (CHAR8 *) NULL;\r
52}\r
53\r
3321fa09 54/**\r
55 Test if all of the characters in a string have corresponding font characters.\r
56\r
57 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and\r
58 return EFI_UNSUPPORTED.\r
133a9dfb 59\r
3321fa09 60 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
61 @param StringToTest A pointer to a Unicode string.\r
62 @param FirstMissing A pointer to an index into the string. On input, the index of \r
63 the first character in the StringToTest to examine. On exit, the index \r
64 of the first character encountered for which a glyph is unavailable. \r
65 If all glyphs in the string are available, the index is the index of the terminator \r
66 of the string. \r
67 @param GlyphBufferSize A pointer to a value. On output, if the function returns EFI_SUCCESS, \r
cb7d01c0 68 it contains the amount of memory that is required to store the string? glyph equivalent.\r
3321fa09 69\r
70 @retval EFI_UNSUPPORTED The function performs nothing and return EFI_UNSUPPORTED.\r
71**/\r
4259256b 72EFI_STATUS\r
73EFIAPI\r
74HiiTestString (\r
75 IN EFI_HII_PROTOCOL *This,\r
76 IN CHAR16 *StringToTest,\r
77 IN OUT UINT32 *FirstMissing,\r
78 OUT UINT32 *GlyphBufferSize\r
79 )\r
4259256b 80{\r
81 ASSERT (FALSE);\r
3321fa09 82 \r
83 return EFI_UNSUPPORTED;\r
4259256b 84}\r
85\r
133a9dfb 86\r
3321fa09 87/**\r
88 Find the corressponding TAG GUID from a Framework HII Handle given.\r
89\r
90 @param Private The HII Thunk Module Private context.\r
91 @param FwHiiHandle The Framemwork HII Handle.\r
92 @param TagGuid The output of TAG GUID found.\r
133a9dfb 93\r
3321fa09 94 @return NULL If Framework HII Handle is invalid.\r
95 @return The corresponding HII Thunk Context.\r
96**/\r
4259256b 97EFI_STATUS\r
0368663f 98GetTagGuidByFwHiiHandle (\r
99 IN CONST HII_THUNK_PRIVATE_DATA *Private,\r
100 IN FRAMEWORK_EFI_HII_HANDLE FwHiiHandle,\r
4259256b 101 OUT EFI_GUID *TagGuid\r
102 )\r
103{\r
0368663f 104 LIST_ENTRY *Link;\r
105 HII_THUNK_CONTEXT *ThunkContext;\r
4259256b 106\r
107 ASSERT (TagGuid != NULL);\r
108\r
0368663f 109 Link = GetFirstNode (&Private->ThunkContextListHead);\r
110 while (!IsNull (&Private->ThunkContextListHead, Link)) {\r
4259256b 111\r
0368663f 112 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);\r
4259256b 113\r
0368663f 114 if (FwHiiHandle == ThunkContext->FwHiiHandle) {\r
115 CopyGuid (TagGuid, &ThunkContext->TagGuid);\r
4259256b 116 return EFI_SUCCESS;\r
117 }\r
0368663f 118\r
119 Link = GetNextNode (&Private->ThunkContextListHead, Link);\r
4259256b 120 }\r
0368663f 121\r
4259256b 122 return EFI_NOT_FOUND;\r
123}\r
124\r
3321fa09 125/**\r
126 Create or update the String given a new string and String ID.\r
127\r
128 @param ThunkContext The Thunk Context.\r
129 @param Rfc3066AsciiLanguage The RFC 3066 Language code in ASCII string format.\r
130 @param NewString The new string.\r
131 @param StringId The String ID. If StringId is 0, a new String Token\r
132 is created. Otherwise, the String Token StringId is \r
133 updated.\r
134 \r
135\r
136 @retval EFI_SUCCESS The new string is created or updated successfully. \r
137 The new String Token ID is returned in StringId if\r
138 *StringId is 0 on input.\r
139 @return Others The update of string failed. \r
140 \r
141**/\r
142EFI_STATUS\r
143UpdateString (\r
144 IN CONST HII_THUNK_CONTEXT *ThunkContext,\r
145 IN CONST CHAR8 *Rfc3066AsciiLanguage,\r
146 IN CHAR16 *NewString,\r
147 IN OUT STRING_REF *StringId\r
148 )\r
149{\r
150 EFI_STRING_ID NewStringId;\r
3321fa09 151\r
cb7d01c0 152 NewStringId = HiiSetString (ThunkContext->UefiHiiHandle, *StringId, NewString, Rfc3066AsciiLanguage);\r
153 *StringId = NewStringId;\r
154 if (NewStringId == 0) {\r
3321fa09 155 //\r
156 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.\r
157 //\r
cb7d01c0 158 return EFI_INVALID_PARAMETER;\r
159 } else {\r
160 return EFI_SUCCESS;\r
3321fa09 161 }\r
3321fa09 162}\r
163\r
164/**\r
165 Create or update a String Token in a String Package.\r
166\r
167 If *Reference == 0, a new String Token is created.\r
168\r
169 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
170 @param Language Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
171 identifier, indicating the language to print. A string consisting of\r
172 all spaces indicates that the string is applicable to all languages.\r
173 @param Handle The handle of the language pack to which the string is to be added.\r
174 @param Token The string token assigned to the string.\r
175 @param NewString The string to be added.\r
176\r
0368663f 177\r
3321fa09 178 @retval EFI_SUCCESS The string was effectively registered.\r
179 @retval EFI_INVALID_PARAMETER The Handle was unknown. The string is not created or updated in the\r
180 the string package.\r
181**/\r
0368663f 182\r
4259256b 183EFI_STATUS\r
0368663f 184EFIAPI\r
185HiiNewString (\r
186 IN EFI_HII_PROTOCOL *This,\r
187 IN CHAR16 *Language,\r
188 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
189 IN OUT STRING_REF *Reference,\r
190 IN CHAR16 *NewString\r
4259256b 191 )\r
192{\r
193 EFI_STATUS Status;\r
0368663f 194 HII_THUNK_PRIVATE_DATA *Private;\r
195 EFI_GUID TagGuid;\r
196 LIST_ENTRY *Link;\r
197 HII_THUNK_CONTEXT *ThunkContext;\r
3321fa09 198 HII_THUNK_CONTEXT *StringPackThunkContext;\r
0368663f 199 EFI_STRING_ID StringId;\r
200 EFI_STRING_ID LastStringId;\r
133a9dfb 201 CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];\r
8ea58c07 202 CHAR16 LanguageCopy[ISO_639_2_ENTRY_SIZE + 1];\r
133a9dfb 203 CHAR8 *Rfc3066AsciiLanguage;\r
4259256b 204\r
0368663f 205 LastStringId = (EFI_STRING_ID) 0;\r
206 StringId = (EFI_STRING_ID) 0;\r
133a9dfb 207 Rfc3066AsciiLanguage = NULL;\r
4259256b 208\r
0368663f 209 if (Language != NULL) {\r
133a9dfb 210 ZeroMem (AsciiLanguage, sizeof (AsciiLanguage));;\r
8ea58c07 211 ZeroMem (LanguageCopy, sizeof (LanguageCopy));\r
212 CopyMem (LanguageCopy, Language, ISO_639_2_ENTRY_SIZE * sizeof (CHAR16));\r
213 UnicodeStrToAsciiStr (LanguageCopy, AsciiLanguage);\r
133a9dfb 214 Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (AsciiLanguage);\r
215 ASSERT (Rfc3066AsciiLanguage != NULL);\r
ea58467b 216 }\r
4259256b 217\r
3321fa09 218 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
4259256b 219\r
3321fa09 220 StringPackThunkContext = FwHiiHandleToThunkContext (Private, Handle);\r
221 if (StringPackThunkContext == NULL) {\r
222 return EFI_INVALID_PARAMETER;\r
223 }\r
224\r
225 if (StringPackThunkContext->SharingStringPack) {\r
226 Status = GetTagGuidByFwHiiHandle (Private, Handle, &TagGuid);\r
227 ASSERT_EFI_ERROR (Status);\r
228\r
229 Link = GetFirstNode (&Private->ThunkContextListHead);\r
230 while (!IsNull (&Private->ThunkContextListHead, Link)) {\r
231 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);\r
0368663f 232\r
3321fa09 233 if (CompareGuid (&TagGuid, &ThunkContext->TagGuid)) {\r
234 if (ThunkContext->SharingStringPack) {\r
235 StringId = *Reference;\r
236 Status = UpdateString (ThunkContext, Rfc3066AsciiLanguage, NewString, &StringId);\r
237 if (EFI_ERROR (Status)) {\r
238 break;\r
4259256b 239 }\r
3321fa09 240 \r
241 DEBUG_CODE_BEGIN ();\r
242 if (*Reference == 0) {\r
243 //\r
244 // When creating new string token, make sure all created token is the same\r
245 // for all string packages registered using FW HII interface.\r
246 //\r
247 if (LastStringId == (EFI_STRING_ID) 0) {\r
248 LastStringId = StringId;\r
249 } else {\r
250 if (LastStringId != StringId) {\r
251 ASSERT(FALSE);\r
252 }\r
253 }\r
254 }\r
255 DEBUG_CODE_END ();\r
256 \r
4259256b 257 }\r
258 }\r
0368663f 259\r
3321fa09 260 Link = GetNextNode (&Private->ThunkContextListHead, Link);\r
261 }\r
262 } else {\r
263 StringId = *Reference;\r
264 Status = UpdateString (StringPackThunkContext, Rfc3066AsciiLanguage, NewString, &StringId);\r
4259256b 265 }\r
266\r
3321fa09 267 if (!EFI_ERROR (Status)) {\r
0368663f 268 if (*Reference == 0) {\r
269 *Reference = StringId;\r
270 }\r
4259256b 271 } else {\r
0368663f 272 //\r
3321fa09 273 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.\r
0368663f 274 //\r
3321fa09 275 Status = EFI_INVALID_PARAMETER;\r
4259256b 276 }\r
277 \r
46b5ebc8 278 return Status;\r
4259256b 279}\r
280\r
3321fa09 281/**\r
282 This function removes any new strings that were added after the initial string export for this handle.\r
283 UEFI HII String Protocol does not have Reset String function. This function perform nothing.\r
284\r
285 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
286 @param Handle The HII handle on which the string resides.\r
287\r
288 @retval EFI_SUCCESS This function is a NOP and always return EFI_SUCCESS.\r
289\r
290**/\r
4259256b 291EFI_STATUS\r
292EFIAPI\r
293HiiResetStrings (\r
294 IN EFI_HII_PROTOCOL *This,\r
295 IN FRAMEWORK_EFI_HII_HANDLE Handle\r
296 )\r
4259256b 297{\r
0368663f 298 return EFI_SUCCESS;\r
4259256b 299}\r
300\r
3321fa09 301/**\r
302 This function extracts a string from a package already registered with the EFI HII database.\r
303\r
304 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
305 @param Handle The HII handle on which the string resides.\r
306 @param Token The string token assigned to the string.\r
307 @param Raw If TRUE, the string is returned unedited in the internal storage format described\r
308 above. If false, the string returned is edited by replacing <cr> with <space>\r
309 and by removing special characters such as the <wide> prefix.\r
310 @param LanguageString Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
311 identifier, indicating the language to print. If the LanguageString is empty (starts\r
312 with a NULL), the default system language will be used to determine the language.\r
313 @param BufferLength Length of the StringBuffer. If the status reports that the buffer width is too\r
314 small, this parameter is filled with the length of the buffer needed.\r
315 @param StringBuffer The buffer designed to receive the characters in the string. Type EFI_STRING is\r
316 defined in String.\r
317\r
318 @retval EFI_INVALID_PARAMETER If input parameter is invalid.\r
319 @retval EFI_BUFFER_TOO_SMALL If the *BufferLength is too small.\r
320 @retval EFI_SUCCESS Operation is successful.\r
321\r
322**/\r
4259256b 323EFI_STATUS\r
324EFIAPI\r
cdaf7905 325HiiThunkGetString (\r
133a9dfb 326 IN EFI_HII_PROTOCOL *This,\r
327 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
328 IN STRING_REF Token,\r
329 IN BOOLEAN Raw,\r
330 IN CHAR16 *LanguageString,\r
331 IN OUT UINTN *BufferLengthTemp,\r
332 OUT EFI_STRING StringBuffer\r
4259256b 333 )\r
4259256b 334{\r
0368663f 335 HII_THUNK_PRIVATE_DATA *Private;\r
cb7d01c0 336 CHAR8 *Iso639AsciiLanguage;\r
133a9dfb 337 CHAR8 *Rfc3066AsciiLanguage;\r
cb7d01c0 338 CHAR8 *SupportedLanguages;\r
339 CHAR8 *PlatformLanguage;\r
340 CHAR8 *BestLanguage;\r
133a9dfb 341 EFI_HII_HANDLE UefiHiiHandle;\r
342 EFI_STATUS Status;\r
4259256b 343\r
0368663f 344 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
4259256b 345\r
133a9dfb 346 Iso639AsciiLanguage = NULL;\r
347 Rfc3066AsciiLanguage = NULL;\r
348\r
349 if (LanguageString != NULL) {\r
350 Iso639AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);\r
351 if (Iso639AsciiLanguage == NULL) {\r
4259256b 352 return EFI_OUT_OF_RESOURCES;\r
353 }\r
133a9dfb 354 UnicodeStrToAsciiStr (LanguageString, Iso639AsciiLanguage);\r
ea58467b 355\r
133a9dfb 356 //\r
357 // Caller of Framework HII Interface uses the Language Identification String defined \r
358 // in Iso639. So map it to the Language Identifier defined in RFC3066.\r
359 //\r
360 Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (Iso639AsciiLanguage);\r
1668bd49 361\r
362 //\r
363 // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to \r
364 // Iso639ToRfc3066Map.\r
365 //\r
366 ASSERT (Rfc3066AsciiLanguage != NULL);\r
ea58467b 367 \r
4259256b 368 }\r
369\r
133a9dfb 370 UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);\r
371 if (UefiHiiHandle == NULL) {\r
372 Status = EFI_NOT_FOUND;\r
373 goto Done;\r
374 }\r
4259256b 375\r
133a9dfb 376 if (Rfc3066AsciiLanguage == NULL) {\r
cb7d01c0 377 //\r
378 // Get the languages that the package specified by HiiHandle supports\r
379 //\r
380 SupportedLanguages = HiiGetSupportedLanguages (UefiHiiHandle);\r
381 if (SupportedLanguages == NULL) {\r
382 goto Error2;\r
383 }\r
384\r
385 //\r
386 // Get the current platform language setting\r
387 //\r
388 PlatformLanguage = GetEfiGlobalVariable (L"PlatformLang");\r
389 if (PlatformLanguage == NULL) {\r
390 goto Error1;\r
391 }\r
392\r
393 //\r
394 // Get the best matching language from SupportedLanguages\r
395 //\r
396 BestLanguage = GetBestLanguage (\r
397 SupportedLanguages, \r
398 FALSE, // RFC 4646 mode\r
399 PlatformLanguage, // Next highest priority\r
400 SupportedLanguages, // Lowest priority \r
401 NULL\r
402 );\r
403 if (BestLanguage == NULL) {\r
404 FreePool (PlatformLanguage);\r
405Error1:\r
406 FreePool (SupportedLanguages);\r
407Error2:\r
408 Status = EFI_INVALID_PARAMETER;\r
409 goto Done;\r
410 }\r
411\r
412 Status = mHiiStringProtocol->GetString (\r
413 mHiiStringProtocol,\r
414 BestLanguage,\r
415 UefiHiiHandle,\r
416 Token,\r
417 StringBuffer,\r
418 BufferLengthTemp,\r
419 NULL\r
420 );\r
421 FreePool (BestLanguage);\r
133a9dfb 422 } else {\r
423 Status = mHiiStringProtocol->GetString (\r
424 mHiiStringProtocol,\r
425 Rfc3066AsciiLanguage,\r
426 UefiHiiHandle,\r
427 Token,\r
428 StringBuffer,\r
429 BufferLengthTemp,\r
430 NULL\r
431 );\r
4259256b 432 }\r
433\r
133a9dfb 434Done:\r
7001eaf8 435 if (Iso639AsciiLanguage != NULL) {\r
436 FreePool (Iso639AsciiLanguage);\r
437 }\r
133a9dfb 438 \r
439 return Status;\r
4259256b 440}\r
441\r
3321fa09 442/**\r
4259256b 443\r
444 This function allows a program to extract a part of a string of not more than a given width.\r
445 With repeated calls, this allows a calling program to extract "lines" of text that fit inside\r
446 columns. The effort of measuring the fit of strings inside columns is localized to this call.\r
447\r
3321fa09 448 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and\r
449 return EFI_UNSUPPORTED.\r
450\r
451 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
452 @param Handle The HII handle on which the string resides.\r
453 @param Token The string token assigned to the string.\r
454 @param Raw If TRUE, the string is returned unedited in the internal storage format described\r
455 above. If false, the string returned is edited by replacing <cr> with <space>\r
456 and by removing special characters such as the <wide> prefix.\r
457 @param LanguageString Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
458 identifier, indicating the language to print. If the LanguageString is empty (starts\r
459 with a NULL), the default system language will be used to determine the language.\r
460 @param BufferLength Length of the StringBuffer. If the status reports that the buffer width is too\r
461 small, this parameter is filled with the length of the buffer needed.\r
462 @param StringBuffer The buffer designed to receive the characters in the string. Type EFI_STRING is\r
463 defined in String.\r
464\r
465 @retval EFI_UNSUPPORTED.\r
466**/\r
467EFI_STATUS\r
468EFIAPI\r
469HiiGetLine (\r
470 IN EFI_HII_PROTOCOL *This,\r
471 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
472 IN STRING_REF Token,\r
473 IN OUT UINT16 *Index,\r
474 IN UINT16 LineWidth,\r
475 IN CHAR16 *LanguageString,\r
476 IN OUT UINT16 *BufferLength,\r
477 OUT EFI_STRING StringBuffer\r
478 )\r
4259256b 479{\r
480 ASSERT (FALSE);\r
481 return EFI_UNSUPPORTED;\r
482}\r
483\r
1668bd49 484\r