]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Strings.c
Bug fixes for FrameworkHiiToUefiHiiThunk;
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiToUefiHiiThunk / Strings.c
1 /**@file
2 This file implements the protocol functions related to string package.
3
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
9
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.
12
13 **/
14
15
16 #include "HiiDatabase.h"
17
18 EFI_STATUS
19 EFIAPI
20 HiiTestString (
21 IN EFI_HII_PROTOCOL *This,
22 IN CHAR16 *StringToTest,
23 IN OUT UINT32 *FirstMissing,
24 OUT UINT32 *GlyphBufferSize
25 )
26 /*++
27
28 Routine Description:
29 Test if all of the characters in a string have corresponding font characters.
30
31 Arguments:
32
33 Returns:
34
35 --*/
36 {
37 ASSERT (FALSE);
38 return EFI_SUCCESS;
39 }
40
41 EFI_STATUS
42 GetTagGuidByFwHiiHandle (
43 IN CONST HII_THUNK_PRIVATE_DATA *Private,
44 IN FRAMEWORK_EFI_HII_HANDLE FwHiiHandle,
45 OUT EFI_GUID *TagGuid
46 )
47 {
48 LIST_ENTRY *Link;
49 HII_THUNK_CONTEXT *ThunkContext;
50
51 ASSERT (TagGuid != NULL);
52
53 Link = GetFirstNode (&Private->ThunkContextListHead);
54 while (!IsNull (&Private->ThunkContextListHead, Link)) {
55
56 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);
57
58 if (FwHiiHandle == ThunkContext->FwHiiHandle) {
59 CopyGuid (TagGuid, &ThunkContext->TagGuid);
60 return EFI_SUCCESS;
61 }
62
63 Link = GetNextNode (&Private->ThunkContextListHead, Link);
64 }
65
66 return EFI_NOT_FOUND;
67 }
68
69
70
71 EFI_STATUS
72 EFIAPI
73 HiiNewString (
74 IN EFI_HII_PROTOCOL *This,
75 IN CHAR16 *Language,
76 IN FRAMEWORK_EFI_HII_HANDLE Handle,
77 IN OUT STRING_REF *Reference,
78 IN CHAR16 *NewString
79 )
80 /*++
81
82 Routine Description:
83 This function allows a new String to be added to an already existing String Package.
84 We will make a buffer the size of the package + StrSize of the new string. We will
85 copy the string package that first gets changed and the following language packages until
86 we encounter the NULL string package. All this time we will ensure that the offsets have
87 been adjusted.
88
89 Arguments:
90
91 Returns:
92
93 --*/
94 {
95 EFI_STATUS Status;
96 HII_THUNK_PRIVATE_DATA *Private;
97 EFI_GUID TagGuid;
98 LIST_ENTRY *Link;
99 HII_THUNK_CONTEXT *ThunkContext;
100 EFI_STRING_ID StringId;
101 EFI_STRING_ID LastStringId;
102 CHAR8 *AsciiLanguage;
103 BOOLEAN Found;
104
105 //
106 // BugBug: Conver the language to 3066.
107 //
108
109 LastStringId = (EFI_STRING_ID) 0;
110 StringId = (EFI_STRING_ID) 0;
111 Found = FALSE;
112 AsciiLanguage = NULL;
113
114 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
115
116 Status = GetTagGuidByFwHiiHandle (Private, Handle, &TagGuid);
117 ASSERT_EFI_ERROR (Status);
118
119 if (Language != NULL) {
120 AsciiLanguage = AllocateZeroPool (StrLen (Language) + 1);
121 UnicodeStrToAsciiStr (Language, AsciiLanguage);
122 }
123
124 Link = GetFirstNode (&Private->ThunkContextListHead);
125 while (!IsNull (&Private->ThunkContextListHead, Link)) {
126 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);
127
128 if (CompareGuid (&TagGuid, &ThunkContext->TagGuid)) {
129 Found = TRUE;
130 if (*Reference == 0) {
131 //
132 // Create a new string token.
133 //
134 if (AsciiLanguage == NULL) {
135 //
136 // For all languages in the package list.
137 //
138 Status = HiiLibNewString (ThunkContext->UefiHiiHandle, &StringId, NewString);
139 } else {
140 //
141 // For specified language.
142 //
143 Status = mHiiStringProtocol->NewString (
144 mHiiStringProtocol,
145 ThunkContext->UefiHiiHandle,
146 &StringId,
147 AsciiLanguage,
148 NULL,
149 NewString,
150 NULL
151 );
152 }
153 } else {
154 //
155 // Update the existing string token.
156 //
157 if (AsciiLanguage == NULL) {
158 //
159 // For all languages in the package list.
160 //
161 Status = HiiLibSetString (ThunkContext->UefiHiiHandle, *Reference, NewString);
162 } else {
163 //
164 // For specified language.
165 //
166 Status = mHiiStringProtocol->SetString (
167 mHiiStringProtocol,
168 ThunkContext->UefiHiiHandle,
169 *Reference,
170 AsciiLanguage,
171 NewString,
172 NULL
173 );
174 }
175 }
176 if (EFI_ERROR (Status)) {
177 //
178 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.
179 //
180 return EFI_INVALID_PARAMETER;
181 }
182
183 if (*Reference == 0) {
184 //
185 // When creating new string token, make sure all created token is the same
186 // for all string packages registered using FW HII interface.
187 //
188 if (LastStringId == (EFI_STRING_ID) 0) {
189 LastStringId = StringId;
190 } else {
191 if (LastStringId != StringId) {
192 ASSERT(FALSE);
193 return EFI_INVALID_PARAMETER;
194 }
195 }
196 }
197 }
198
199 Link = GetNextNode (&Private->ThunkContextListHead, Link);
200 }
201
202 if (Found) {
203 if (*Reference == 0) {
204 *Reference = StringId;
205 }
206 Status = EFI_SUCCESS;
207 } else {
208 DEBUG((EFI_D_ERROR, "Thunk HiiNewString fails to find the String Packages to update\n"));
209 //
210 // BUGBUG: Remove ths ASSERT when development is done.
211 //
212 ASSERT (FALSE);
213 Status = EFI_NOT_FOUND;
214 }
215
216 //
217 // For UNI file, some String may not be defined for a language. This has been true for a lot of platform code.
218 // For this case, EFI_NOT_FOUND will be returned. To allow the old code to be run without porting, we don't assert
219 // on EFI_NOT_FOUND. The missing Strings will be shown if user select a differnt languages other than the default
220 // English language for the platform.
221 //
222 ASSERT_EFI_ERROR (EFI_ERROR (Status) && Status != EFI_NOT_FOUND);
223
224 return Status;
225 }
226
227 EFI_STATUS
228 EFIAPI
229 HiiResetStrings (
230 IN EFI_HII_PROTOCOL *This,
231 IN FRAMEWORK_EFI_HII_HANDLE Handle
232 )
233 /*++
234
235 Routine Description:
236
237 This function removes any new strings that were added after the initial string export for this handle.
238
239 Arguments:
240
241 Returns:
242
243 --*/
244 {
245 return EFI_SUCCESS;
246 }
247
248 typedef struct {
249 CHAR8 *Iso639;
250 CHAR8 *Rfc3066;
251 } ISO639TORFC3066MAP;
252
253 ISO639TORFC3066MAP Iso639ToRfc3066Map [] = {
254 {"eng", "en-US"},
255 {"fra", "fr-FR"},
256 };
257
258 CHAR8 *
259 ConvertIso639ToRfc3066 (
260 CHAR8 *Iso638Lang
261 )
262 {
263 UINTN Index;
264
265 for (Index = 0; Index < sizeof (Iso639ToRfc3066Map) / sizeof (Iso639ToRfc3066Map[0]); Index++) {
266 if (AsciiStrnCmp (Iso638Lang, Iso639ToRfc3066Map[Index].Iso639, AsciiStrSize (Iso638Lang)) == 0) {
267 return Iso639ToRfc3066Map[Index].Rfc3066;
268 }
269 }
270
271 return (CHAR8 *) NULL;
272 }
273
274 EFI_STATUS
275 EFIAPI
276 HiiGetString (
277 IN EFI_HII_PROTOCOL *This,
278 IN FRAMEWORK_EFI_HII_HANDLE Handle,
279 IN STRING_REF Token,
280 IN BOOLEAN Raw,
281 IN CHAR16 *LanguageString,
282 IN OUT UINTN *BufferLengthTemp,
283 OUT EFI_STRING StringBuffer
284 )
285 /*++
286
287 Routine Description:
288
289 This function extracts a string from a package already registered with the EFI HII database.
290
291 Arguments:
292 This - A pointer to the EFI_HII_PROTOCOL instance.
293 Handle - The HII handle on which the string resides.
294 Token - The string token assigned to the string.
295 Raw - If TRUE, the string is returned unedited in the internal storage format described
296 above. If false, the string returned is edited by replacing <cr> with <space>
297 and by removing special characters such as the <wide> prefix.
298 LanguageString - Pointer to a NULL-terminated string containing a single ISO 639-2 language
299 identifier, indicating the language to print. If the LanguageString is empty (starts
300 with a NULL), the default system language will be used to determine the language.
301 BufferLength - Length of the StringBuffer. If the status reports that the buffer width is too
302 small, this parameter is filled with the length of the buffer needed.
303 StringBuffer - The buffer designed to receive the characters in the string. Type EFI_STRING is
304 defined in String.
305
306 Returns:
307 EFI_INVALID_PARAMETER - If input parameter is invalid.
308 EFI_BUFFER_TOO_SMALL - If the *BufferLength is too small.
309 EFI_SUCCESS - Operation is successful.
310
311 --*/
312 {
313 LIST_ENTRY *Link;
314 HII_THUNK_CONTEXT *ThunkContext;
315 CHAR8 *AsciiLanguage;
316 HII_THUNK_PRIVATE_DATA *Private;
317 CHAR8 *Rfc3066AsciiLanguage;
318
319 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
320
321 if (LanguageString == NULL) {
322 AsciiLanguage = NULL;
323 } else {
324 AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);
325 if (AsciiLanguage == NULL) {
326 return EFI_OUT_OF_RESOURCES;
327 }
328 UnicodeStrToAsciiStr (LanguageString, AsciiLanguage);
329
330 Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (AsciiLanguage);
331
332 //
333 // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to
334 // Iso639ToRfc3066Map.
335 //
336 ASSERT (Rfc3066AsciiLanguage != NULL);
337 //
338 // Caller of Framework HII Interface uses the Language Identification String defined
339 // in Iso639. So map it to the Language Identifier defined in RFC3066.
340 //
341 if (Rfc3066AsciiLanguage != NULL) {
342 FreePool (AsciiLanguage);
343 AsciiLanguage = AllocateCopyPool (AsciiStrSize (Rfc3066AsciiLanguage), Rfc3066AsciiLanguage);
344 }
345
346 }
347
348 Link = GetFirstNode (&Private->ThunkContextListHead);
349
350 while (!IsNull (&Private->ThunkContextListHead, Link)) {
351
352 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);
353
354 if (Handle == ThunkContext->FwHiiHandle) {
355 if (AsciiLanguage == NULL) {
356 return HiiLibGetString (ThunkContext->UefiHiiHandle, Token, StringBuffer, BufferLengthTemp);
357 } else {
358 return mHiiStringProtocol->GetString (
359 mHiiStringProtocol,
360 AsciiLanguage,
361 ThunkContext->UefiHiiHandle,
362 Token,
363 StringBuffer,
364 BufferLengthTemp,
365 NULL
366 );
367 }
368 }
369
370
371 Link = GetNextNode (&Private->ThunkContextListHead, Link);
372 }
373
374 return EFI_NOT_FOUND;
375 }
376
377 EFI_STATUS
378 EFIAPI
379 HiiGetLine (
380 IN EFI_HII_PROTOCOL *This,
381 IN FRAMEWORK_EFI_HII_HANDLE Handle,
382 IN STRING_REF Token,
383 IN OUT UINT16 *Index,
384 IN UINT16 LineWidth,
385 IN CHAR16 *LanguageString,
386 IN OUT UINT16 *BufferLength,
387 OUT EFI_STRING StringBuffer
388 )
389 /*++
390
391 Routine Description:
392
393 This function allows a program to extract a part of a string of not more than a given width.
394 With repeated calls, this allows a calling program to extract "lines" of text that fit inside
395 columns. The effort of measuring the fit of strings inside columns is localized to this call.
396
397 Arguments:
398
399 Returns:
400
401 --*/
402 {
403 ASSERT (FALSE);
404 return EFI_UNSUPPORTED;
405 }
406
407