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