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