]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c
Fix the conflicted function names to new HII library.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / 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 CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];
35
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');
42 }
43 }
44
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;
48 }
49 }
50
51 return (CHAR8 *) NULL;
52 }
53
54 /**
55 Test if all of the characters in a string have corresponding font characters.
56
57 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and
58 return EFI_UNSUPPORTED.
59
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.
69
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
79 )
80 {
81 ASSERT (FALSE);
82
83 return EFI_UNSUPPORTED;
84 }
85
86
87 /**
88 Find the corressponding TAG GUID from a Framework HII Handle given.
89
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.
93
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
102 )
103 {
104 LIST_ENTRY *Link;
105 HII_THUNK_CONTEXT *ThunkContext;
106
107 ASSERT (TagGuid != NULL);
108
109 Link = GetFirstNode (&Private->ThunkContextListHead);
110 while (!IsNull (&Private->ThunkContextListHead, Link)) {
111
112 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);
113
114 if (FwHiiHandle == ThunkContext->FwHiiHandle) {
115 CopyGuid (TagGuid, &ThunkContext->TagGuid);
116 return EFI_SUCCESS;
117 }
118
119 Link = GetNextNode (&Private->ThunkContextListHead, Link);
120 }
121
122 return EFI_NOT_FOUND;
123 }
124
125 /**
126 Create or update the String given a new string and String ID.
127
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.
134
135
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.
140
141 **/
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
148 )
149 {
150 EFI_STRING_ID NewStringId;
151 EFI_STATUS Status;
152
153
154 NewStringId = 0;
155
156 if (*StringId == 0) {
157 //
158 // Create a new string token.
159 //
160 if (Rfc3066AsciiLanguage == NULL) {
161 //
162 // For all languages in the package list.
163 //
164 Status = HiiLibNewString (ThunkContext->UefiHiiHandle, &NewStringId, NewString);
165 } else {
166 //
167 // For specified language.
168 //
169 Status = mHiiStringProtocol->NewString (
170 mHiiStringProtocol,
171 ThunkContext->UefiHiiHandle,
172 &NewStringId,
173 Rfc3066AsciiLanguage,
174 NULL,
175 NewString,
176 NULL
177 );
178 }
179 } else {
180 //
181 // Update the existing string token.
182 //
183 if (Rfc3066AsciiLanguage == NULL) {
184 //
185 // For all languages in the package list.
186 //
187 Status = HiiLibSetString (ThunkContext->UefiHiiHandle, *StringId, NewString);
188 } else {
189 //
190 // For specified language.
191 //
192 Status = mHiiStringProtocol->SetString (
193 mHiiStringProtocol,
194 ThunkContext->UefiHiiHandle,
195 *StringId,
196 Rfc3066AsciiLanguage,
197 NewString,
198 NULL
199 );
200 }
201 }
202
203 if (!EFI_ERROR (Status)) {
204 if (*StringId == 0) {
205 //
206 // When creating new string, return the newly created String Token.
207 //
208 *StringId = NewStringId;
209 }
210 } else {
211 //
212 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.
213 //
214 *StringId = 0;
215 }
216
217 return Status;
218 }
219
220 /**
221 Create or update a String Token in a String Package.
222
223 If *Reference == 0, a new String Token is created.
224
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.
232
233
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.
237 **/
238
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
247 )
248 {
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;
260
261 LastStringId = (EFI_STRING_ID) 0;
262 StringId = (EFI_STRING_ID) 0;
263 Rfc3066AsciiLanguage = NULL;
264
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);
272 }
273
274 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
275
276 StringPackThunkContext = FwHiiHandleToThunkContext (Private, Handle);
277 if (StringPackThunkContext == NULL) {
278 return EFI_INVALID_PARAMETER;
279 }
280
281 if (StringPackThunkContext->SharingStringPack) {
282 Status = GetTagGuidByFwHiiHandle (Private, Handle, &TagGuid);
283 ASSERT_EFI_ERROR (Status);
284
285 Link = GetFirstNode (&Private->ThunkContextListHead);
286 while (!IsNull (&Private->ThunkContextListHead, Link)) {
287 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);
288
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;
295 }
296
297 DEBUG_CODE_BEGIN ();
298 if (*Reference == 0) {
299 //
300 // When creating new string token, make sure all created token is the same
301 // for all string packages registered using FW HII interface.
302 //
303 if (LastStringId == (EFI_STRING_ID) 0) {
304 LastStringId = StringId;
305 } else {
306 if (LastStringId != StringId) {
307 ASSERT(FALSE);
308 }
309 }
310 }
311 DEBUG_CODE_END ();
312
313 }
314 }
315
316 Link = GetNextNode (&Private->ThunkContextListHead, Link);
317 }
318 } else {
319 StringId = *Reference;
320 Status = UpdateString (StringPackThunkContext, Rfc3066AsciiLanguage, NewString, &StringId);
321 }
322
323 if (!EFI_ERROR (Status)) {
324 if (*Reference == 0) {
325 *Reference = StringId;
326 }
327 } else {
328 //
329 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.
330 //
331 Status = EFI_INVALID_PARAMETER;
332 }
333
334 return Status;
335 }
336
337 /**
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.
340
341 @param This A pointer to the EFI_HII_PROTOCOL instance.
342 @param Handle The HII handle on which the string resides.
343
344 @retval EFI_SUCCESS This function is a NOP and always return EFI_SUCCESS.
345
346 **/
347 EFI_STATUS
348 EFIAPI
349 HiiResetStrings (
350 IN EFI_HII_PROTOCOL *This,
351 IN FRAMEWORK_EFI_HII_HANDLE Handle
352 )
353 {
354 return EFI_SUCCESS;
355 }
356
357 /**
358 This function extracts a string from a package already registered with the EFI HII database.
359
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.
373
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.
377
378 **/
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
389 )
390 {
391 CHAR8 *Iso639AsciiLanguage;
392 HII_THUNK_PRIVATE_DATA *Private;
393 CHAR8 *Rfc3066AsciiLanguage;
394 EFI_HII_HANDLE UefiHiiHandle;
395 EFI_STATUS Status;
396
397 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
398
399 Iso639AsciiLanguage = NULL;
400 Rfc3066AsciiLanguage = NULL;
401
402 if (LanguageString != NULL) {
403 Iso639AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);
404 if (Iso639AsciiLanguage == NULL) {
405 return EFI_OUT_OF_RESOURCES;
406 }
407 UnicodeStrToAsciiStr (LanguageString, Iso639AsciiLanguage);
408
409 //
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.
412 //
413 Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (Iso639AsciiLanguage);
414
415 //
416 // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to
417 // Iso639ToRfc3066Map.
418 //
419 ASSERT (Rfc3066AsciiLanguage != NULL);
420
421 }
422
423 UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);
424 if (UefiHiiHandle == NULL) {
425 Status = EFI_NOT_FOUND;
426 goto Done;
427 }
428
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
440 );
441 }
442
443 Done:
444 if (Iso639AsciiLanguage != NULL) {
445 FreePool (Iso639AsciiLanguage);
446 }
447
448 return Status;
449 }
450
451 /**
452
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.
456
457 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and
458 return EFI_UNSUPPORTED.
459
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.
473
474 @retval EFI_UNSUPPORTED.
475 **/
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
487 )
488 {
489 ASSERT (FALSE);
490 return EFI_UNSUPPORTED;
491 }
492
493