On 2015-05-20 14:08:40, Jonathan Doman wrote:
> +STATIC
> +EFI_STATUS
> +PosixExtendedMatch (
> + IN CHAR16 *String,
> + IN CHAR16 *Pattern,
> + OUT BOOLEAN *Result,
> + OUT EFI_REGEX_CAPTURE **Captures, OPTIONAL
> + OUT UINTN *CapturesCount
> + )
> +{
> + REG_EX_HANDLE Regex;
> + CHAR8 *AsciiString;
> + CHAR8 *AsciiPattern;
> + EFI_STATUS Status;
> +
> + ASSERT (String != NULL);
> + ASSERT (Pattern != NULL);
> + ASSERT (Result != NULL);
> + ASSERT (CapturesCount != NULL);
> +
> + //
> + // Our POSIX Extended library only supports ASCII input
> + //
> + AsciiString = AllocatePool (StrLen (String) + 1);
> + if (AsciiString == NULL) {
> + return EFI_OUT_OF_RESOURCES;
> + }
> + UnicodeStrToAsciiStr (String, AsciiString);
I don't think this matches the spec.
> + AsciiPattern = AllocatePool (StrLen (Pattern) + 1);
> + if (AsciiPattern == NULL) {
> + FreePool (AsciiString);
> + return EFI_OUT_OF_RESOURCES;
> + }
> + UnicodeStrToAsciiStr (Pattern, AsciiPattern);
I don't think this matches the spec.
> + //
> + // Compile and run the regex
> + //
> + Status = RegExCompile (&Regex, AsciiPattern);
> +
> + if (!EFI_ERROR (Status)) {
> + *Result = RegExMatch (Regex, AsciiString, NULL, 0);
> + } else {
> + *Result = FALSE;
> + }
> +
> + //
> + // Write out the results
> + //
> + if (!*Result) {
> + if (Captures != NULL) {
> + *Captures = NULL;
> + }
> + *CapturesCount = 0;
> + } else {
> + //
> + // Doesn't support sub-expression capture groups yet
Doesn't meet the spec. :)
-Jordan
> + //
> + if (Captures != NULL) {
> + *Captures = AllocatePool (sizeof(EFI_REGEX_CAPTURE));
> + (*Captures)[0].CapturePtr = String;
> + (*Captures)[0].Length = StrLen (String);
> + }
> + *CapturesCount = 1;
> + }
> +
> + RegExFree (Regex);
> +
> + FreePool (AsciiPattern);
> + FreePool (AsciiString);
> +
> + return Status;
> +}
> +
> +/**
> + Returns information about the regular expression syntax types supported
> + by the implementation.
> +
> + This A pointer to the EFI_REGULAR_EXPRESSION_PROTOCOL
> + instance.
> +
> + RegExSyntaxTypeListSize On input, the size in bytes of
> RegExSyntaxTypeList.
> + On output with a return code of EFI_SUCCESS, the
> + size in bytes of the data returned in
> + RegExSyntaxTypeList. On output with a return code
> + of EFI_BUFFER_TOO_SMALL, the size of
> + RegExSyntaxTypeList required to obtain the list.
> +
> + RegExSyntaxTypeList A caller-allocated memory buffer filled by the
> + driver with one EFI_REGEX_SYNTAX_TYPE element
> + for each supported Regular expression syntax
> + type. The list must not change across multiple
> + calls to the same driver. The first syntax
> + type in the list is the default type for the
> + driver.
> +
> + @retval EFI_SUCCESS The regular expression syntax types list
> + was returned successfully.
> + @retval EFI_UNSUPPORTED The service is not supported by this driver.
> + @retval EFI_DEVICE_ERROR The list of syntax types could not be
> + retrieved due to a hardware or firmware
> error.
> + @retval EFI_BUFFER_TOO_SMALL The buffer RegExSyntaxTypeList is too small
> + to hold the result.
> + @retval EFI_INVALID_PARAMETER RegExSyntaxTypeListSize is NULL
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +RegularExpressionGetInfo (
> + IN EFI_REGULAR_EXPRESSION_PROTOCOL *This,
> + IN OUT UINTN *RegExSyntaxTypeListSize,
> + OUT EFI_REGEX_SYNTAX_TYPE *RegExSyntaxTypeList
> + )
> +{
> + UINTN SyntaxSize;
> + UINTN Index;
> +
> + if (This == NULL || RegExSyntaxTypeListSize == NULL || RegExSyntaxTypeList
> == NULL) {
> + return EFI_INVALID_PARAMETER;
> + }
> +
> + SyntaxSize = ARRAY_SIZE (mSupportedSyntaxes) *
> sizeof(**mSupportedSyntaxes);
> +
> + if (*RegExSyntaxTypeListSize < SyntaxSize) {
> + *RegExSyntaxTypeListSize = SyntaxSize;
> + return EFI_BUFFER_TOO_SMALL;
> + }
> +
> + for (Index = 0; Index < ARRAY_SIZE (mSupportedSyntaxes); ++Index) {
> + CopyMem (&RegExSyntaxTypeList[Index], mSupportedSyntaxes[Index],
> sizeof(**mSupportedSyntaxes));
> + }
> + *RegExSyntaxTypeListSize = SyntaxSize;
> +
> + return EFI_SUCCESS;
> +}
> +
> +/**
> + Checks if the input string matches to the regular expression pattern.
> +
> + This A pointer to the EFI_REGULAR_EXPRESSION_PROTOCOL instance.
> + Type EFI_REGULAR_EXPRESSION_PROTOCOL is defined in Section
> + XYZ.
> +
> + String A pointer to a NULL terminated string to match against the
> + regular expression string specified by Pattern.
> +
> + Pattern A pointer to a NULL terminated string that represents the
> + regular expression.
> +
> + SyntaxType A pointer to the EFI_REGEX_SYNTAX_TYPE that identifies the
> + regular expression syntax type to use. May be NULL in which
> + case the function will use its default regular expression
> + syntax type.
> +
> + Result On return, points to TRUE if String fully matches against
> + the regular expression Pattern using the regular expression
> + SyntaxType. Otherwise, points to FALSE.
> +
> + Captures A Pointer to an array of EFI_REGEX_CAPTURE objects to receive
> + the captured groups in the event of a match. The full
> + sub-string match is put in Captures[0], and the results of N
> + capturing groups are put in Captures[1:N]. If Captures is
> + NULL, then this function doesn't allocate the memory for the
> + array and does not build up the elements. It only returns the
> + number of matching patterns in CapturesCount. If Captures is
> + not NULL, this function returns a pointer to an array and
> + builds up the elements in the array. CapturesCount is also
> + updated to the number of matching patterns found. It is the
> + caller's responsibility to free the memory pool in Captures
> + and in each CapturePtr in the array elements.
> +
> + CapturesCount On output, CapturesCount is the number of matching patterns
> + found in String. Zero means no matching patterns were found
> + in the string.
> +
> + @retval EFI_SUCCESS The regular expression string matching
> + completed successfully.
> + @retval EFI_UNSUPPORTED The regular expression syntax specified by
> + SyntaxType is not supported by this driver.
> + @retval EFI_DEVICE_ERROR The regular expression string matching
> + failed due to a hardware or firmware error.
> + @retval EFI_INVALID_PARAMETER String, Pattern, Result, or CapturesCountis
> + NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +RegularExpressionMatch (
> + IN EFI_REGULAR_EXPRESSION_PROTOCOL *This,
> + IN CHAR16 *String,
> + IN CHAR16 *Pattern,
> + IN EFI_REGEX_SYNTAX_TYPE *SyntaxType, OPTIONAL
> + OUT BOOLEAN *Result,
> + OUT EFI_REGEX_CAPTURE **Captures, OPTIONAL
> + OUT UINTN *CapturesCount
> + )
> +{
> + EFI_STATUS Status;
> + UINT32 Index;
> + BOOLEAN Supported;
> +
> + if (This == NULL || String == NULL || Pattern == NULL || Result == NULL ||
> CapturesCount == NULL) {
> + return EFI_INVALID_PARAMETER;
> + }
> +
> + //
> + // Figure out which syntax to use
> + //
> + if (SyntaxType == NULL) {
> + SyntaxType = mSupportedSyntaxes[0];
> + } else {
> + Supported = FALSE;
> + for (Index = 0; Index < ARRAY_SIZE (mSupportedSyntaxes); ++Index) {
> + if (CompareGuid (SyntaxType, mSupportedSyntaxes[Index])) {
> + Supported = TRUE;
> + break;
> + }
> + }
> + if (!Supported) {
> + return EFI_UNSUPPORTED;
> + }
> + }
> +
> + //
> + // Here is where we determine which underlying library can handle the
> + // requested syntax. (Or possibly one library can implement all the
> + // protocols.)
> + //
> + if (CompareGuid (SyntaxType, &gEfiRegexSyntaxTypePosixExtendedGuid)) {
> + Status = PosixExtendedMatch (String, Pattern, Result, Captures,
> CapturesCount);
> + } else {
> + ASSERT (FALSE);
> + DEBUG ((DEBUG_ERROR, "Regex Syntax %g is supported but unimplemented\n",
> SyntaxType));
> + Status = EFI_DEVICE_ERROR;
> + }
> +
> + return Status;
> +}
> +
> +/**
> + Entry point for RegularExpressionDxe.
> +**/
> +EFI_STATUS
> +EFIAPI
> +RegularExpressionDxeEntry (
> + IN EFI_HANDLE ImageHandle,
> + IN EFI_SYSTEM_TABLE *SystemTable
> + )
> +{
> + EFI_STATUS Status;
> +
> + STATIC
> + CONST EFI_REGULAR_EXPRESSION_PROTOCOL ProtocolInstance = {
> + RegularExpressionMatch,
> + RegularExpressionGetInfo
> + };
> +
> + (VOID)SystemTable;
> +
> + Status = gBS->InstallMultipleProtocolInterfaces (
> + &ImageHandle,
> + &gEfiRegularExpressionProtocolGuid,
> + &ProtocolInstance,
> + NULL
> + );
> +
> + return Status;
> +}
> diff --git
> a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
> b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
> new file mode 100644
> index 0000000..b83f105
> --- /dev/null
> +++ b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
> @@ -0,0 +1,44 @@
> +##
> +# @file
> +#
> +# EFI_REGULAR_EXPRESSION_PROTOCOL Implementation
> +#
> +# Copyright (c) 2015, Hewlett-Packard Development Company, L.P.<BR>
> +#
> +# This program and the accompanying materials are licensed and made
> available
> +# under the terms and conditions of the BSD License that accompanies this
> +# distribution. The full text of the license may be found at
> +# http://opensource.org/licenses/bsd-license.php.
> +#
> +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> WITHOUT
> +# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +##
> +
> +[Defines]
> + INF_VERSION = 0x00010018
> + BASE_NAME = RegularExpressionDxe
> + FILE_GUID = 3E197E9C-D8DC-42D3-89CE-B04FA9833756
> + MODULE_TYPE = UEFI_DRIVER
> + VERSION_STRING = 1.0
> + ENTRY_POINT = RegularExpressionDxeEntry
> +
> +[Sources]
> + RegularExpressionDxe.c
> +
> +[Packages]
> + MdePkg/MdePkg.dec
> + MdeModulePkg/MdeModulePkg.dec
> +
> +[LibraryClasses]
> + UefiBootServicesTableLib
> + UefiDriverEntryPoint
> + MemoryAllocationLib
> + BaseMemoryLib
> + DebugLib
> + RegExLib
> +
> +[Guids]
> + gEfiRegexSyntaxTypePosixExtendedGuid
> +
> +[Protocols]
> + gEfiRegularExpressionProtocolGuid
> --
> 2.4.1
>
>
> ------------------------------------------------------------------------------
> One dashboard for servers and applications across Physical-Virtual-Cloud
> Widest out-of-the-box monitoring support with 50+ applications
> Performance metrics, stats and reports that give you Actionable Insights
> Deep dive visibility with transaction tracing using APM Insight.
> http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
> _______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
------------------------------------------------------------------------------
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel