OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcXmlLib.h File Reference
#include <Library/BaseOverflowLib.h>

Go to the source code of this file.

Macros

#define XML_PARSER_NEST_LEVEL   32ULL
 
#define XML_PARSER_NODE_COUNT   32768ULL
 
#define XML_PARSER_MAX_REFERENCE_COUNT   (32ULL*1024)
 
#define XML_PARSER_MAX_SIZE   (32ULL*1024*1024)
 

Typedefs

typedef enum PLIST_NODE_TYPE_ PLIST_NODE_TYPE
 
typedef struct XML_DOCUMENT_ XML_DOCUMENT
 
typedef struct XML_NODE_ XML_NODE
 

Enumerations

enum  PLIST_NODE_TYPE_ {
  PLIST_NODE_TYPE_ANY , PLIST_NODE_TYPE_ARRAY , PLIST_NODE_TYPE_DICT , PLIST_NODE_TYPE_KEY ,
  PLIST_NODE_TYPE_STRING , PLIST_NODE_TYPE_DATA , PLIST_NODE_TYPE_DATE , PLIST_NODE_TYPE_TRUE ,
  PLIST_NODE_TYPE_FALSE , PLIST_NODE_TYPE_REAL , PLIST_NODE_TYPE_INTEGER , PLIST_NODE_TYPE_MAX
}
 

Functions

XML_DOCUMENTXmlDocumentParse (IN OUT CHAR8 *Buffer, IN UINT32 Length, IN BOOLEAN WithRefs)
 
CHAR8 * XmlDocumentExport (IN CONST XML_DOCUMENT *Document, OUT UINT32 *Length OPTIONAL, IN UINT32 Skip, IN BOOLEAN PrependPlistInfo)
 
VOID XmlDocumentFree (IN OUT XML_DOCUMENT *Document)
 
XML_NODEXmlDocumentRoot (IN CONST XML_DOCUMENT *Document)
 
CONST CHAR8 * XmlNodeName (IN CONST XML_NODE *Node)
 
CONST CHAR8 * XmlNodeContent (IN CONST XML_NODE *Node)
 
VOID XmlNodeChangeContent (IN OUT XML_NODE *Node, IN CONST CHAR8 *Content)
 
UINT32 XmlNodeChildren (IN CONST XML_NODE *Node)
 
XML_NODEXmlNodeChild (IN CONST XML_NODE *Node, IN UINT32 Child)
 
XML_NODE *EFIAPI XmlEasyChild (IN OUT XML_NODE *Node, IN CONST CHAR8 *ChildName,...)
 
XML_NODEXmlNodeAppend (IN OUT XML_NODE *Node, IN CONST CHAR8 *Name, IN CONST CHAR8 *Attributes OPTIONAL, IN CONST CHAR8 *Content OPTIONAL)
 
XML_NODEXmlNodePrepend (IN OUT XML_NODE *Node, IN CONST CHAR8 *Name, IN CONST CHAR8 *Attributes, IN CONST CHAR8 *Content)
 
VOID XmlNodeRemoveByIndex (IN OUT XML_NODE *Node, IN UINT32 Index)
 
VOID XmlNodeRemove (IN OUT XML_NODE *Node, IN XML_NODE *ChildNode)
 
CONST CHAR8 * XmlUnescapeString (IN CONST CHAR8 *String)
 
XML_NODEPlistDocumentRoot (IN CONST XML_DOCUMENT *Document)
 
XML_NODEPlistNodeCast (IN XML_NODE *Node OPTIONAL, IN PLIST_NODE_TYPE Type)
 
UINT32 PlistDictChildren (IN CONST XML_NODE *Node)
 
XML_NODEPlistDictChild (IN CONST XML_NODE *Node, IN UINT32 Child, OUT XML_NODE **Value OPTIONAL)
 
CONST CHAR8 * PlistKeyValue (IN XML_NODE *Node OPTIONAL)
 
BOOLEAN PlistStringValue (IN XML_NODE *Node OPTIONAL, OUT CHAR8 *Value, IN OUT UINT32 *Size)
 
BOOLEAN PlistDataValue (IN XML_NODE *Node OPTIONAL, OUT UINT8 *Buffer, IN OUT UINT32 *Size)
 
BOOLEAN PlistBooleanValue (IN XML_NODE *Node OPTIONAL, OUT BOOLEAN *Value)
 
BOOLEAN PlistIntegerValue (IN XML_NODE *Node OPTIONAL, OUT VOID *Value, IN UINT32 Size, IN BOOLEAN Hex)
 
BOOLEAN PlistMultiDataValue (IN XML_NODE *Node OPTIONAL, OUT VOID *Buffer, IN OUT UINT32 *Size)
 
BOOLEAN PlistStringSize (IN XML_NODE *Node OPTIONAL, OUT UINT32 *Size)
 
BOOLEAN PlistDataSize (IN XML_NODE *Node OPTIONAL, OUT UINT32 *Size)
 
BOOLEAN PlistMultiDataSize (IN XML_NODE *Node OPTIONAL, OUT UINT32 *Size)
 

Detailed Description

OcXmlLib

Copyright (c) 2018, vit9696

All rights reserved.

This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which 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.

Definition in file OcXmlLib.h.

Macro Definition Documentation

◆ XML_PARSER_MAX_REFERENCE_COUNT

#define XML_PARSER_MAX_REFERENCE_COUNT   (32ULL*1024)

Maximum reference count. XML_PARSER_MAX_REFERENCE_COUNT*2 is required to fit into INT32.

Definition at line 68 of file OcXmlLib.h.

◆ XML_PARSER_MAX_SIZE

#define XML_PARSER_MAX_SIZE   (32ULL*1024*1024)

Maximum input data size, currently 32 MB. XML_PARSER_MAX_SIZE is required to fit into INT32.

Definition at line 76 of file OcXmlLib.h.

◆ XML_PARSER_NEST_LEVEL

#define XML_PARSER_NEST_LEVEL   32ULL

Maximum nest level. XML_PARSER_NEST_LEVEL is required to fit into INT32.

Definition at line 52 of file OcXmlLib.h.

◆ XML_PARSER_NODE_COUNT

#define XML_PARSER_NODE_COUNT   32768ULL

Maximum child node count. XML_PARSER_NODE_COUNT*2 is required to fit into INT32.

Definition at line 60 of file OcXmlLib.h.

Typedef Documentation

◆ PLIST_NODE_TYPE

Debug controls. Plist node types.

◆ XML_DOCUMENT

typedef struct XML_DOCUMENT_ XML_DOCUMENT

Definition at line 108 of file OcXmlLib.h.

◆ XML_NODE

typedef struct XML_NODE_ XML_NODE

Definition at line 109 of file OcXmlLib.h.

Enumeration Type Documentation

◆ PLIST_NODE_TYPE_

Debug controls. Plist node types.

Enumerator
PLIST_NODE_TYPE_ANY 
PLIST_NODE_TYPE_ARRAY 
PLIST_NODE_TYPE_DICT 
PLIST_NODE_TYPE_KEY 
PLIST_NODE_TYPE_STRING 
PLIST_NODE_TYPE_DATA 
PLIST_NODE_TYPE_DATE 
PLIST_NODE_TYPE_TRUE 
PLIST_NODE_TYPE_FALSE 
PLIST_NODE_TYPE_REAL 
PLIST_NODE_TYPE_INTEGER 
PLIST_NODE_TYPE_MAX 

Definition at line 88 of file OcXmlLib.h.

Function Documentation

◆ PlistBooleanValue()

BOOLEAN PlistBooleanValue ( IN XML_NODE *Node OPTIONAL,
OUT BOOLEAN * Value )

Get the value of a plist boolean.

Parameters
[in]NodeA pointer to the XML node. Optional.
[out]ValueValue of plist boolean.
Returns
TRUE if Node can be casted to PLIST_NODE_TYPE_TRUE or PLIST_NODE_TYPE_FALSE.

Definition at line 1922 of file OcXmlLib.c.

◆ PlistDataSize()

BOOLEAN PlistDataSize ( IN XML_NODE *Node OPTIONAL,
OUT UINT32 * Size )

Get size of a plist data.

Parameters
[in]NodeA pointer to the XML node. Optional.
[out]SizeSize of data.
Returns
TRUE if Node can be casted to PLIST_NODE_TYPE_DATA.

Definition at line 2102 of file OcXmlLib.c.

◆ PlistDataValue()

BOOLEAN PlistDataValue ( IN XML_NODE *Node OPTIONAL,
OUT UINT8 * Buffer,
IN OUT UINT32 * Size )

Decode data content for valid type or set *Size to 0.

Parameters
[in]NodeA pointer to the XML node. Optional.
[out]BufferBuffer of plist data.
[in,out]SizeSize of Buffer.
Returns
TRUE if Node can be casted to PLIST_NODE_TYPE_DATA.

Definition at line 1886 of file OcXmlLib.c.

◆ PlistDictChild()

XML_NODE * PlistDictChild ( IN CONST XML_NODE * Node,
IN UINT32 Child,
OUT XML_NODE **Value OPTIONAL )

Get the specific child node under a plist dictionary.

Parameters
[in]NodeA pointer to the XML node.
[in]ChildIndex of children of Node.
[out]ValueValue of the returned Node. Optional.
Returns
The n-th dictionary key, behaviour is undefined if out of range.

Definition at line 1823 of file OcXmlLib.c.

◆ PlistDictChildren()

UINT32 PlistDictChildren ( IN CONST XML_NODE * Node)

Get the number of plist dictionary entries.

Parameters
[in]NodeA pointer to the XML node.
Returns
Number of plist dictionary entries.

Definition at line 1813 of file OcXmlLib.c.

◆ PlistDocumentRoot()

XML_NODE * PlistDocumentRoot ( IN CONST XML_DOCUMENT * Document)

Get the root node of the plist document.

Parameters
[in]DocumentA pointer to the plist document.
Returns
Root node of the plist document or NULL.
Warning
Only a subset of plist is supported.
No validation of plist format is performed.

Definition at line 1736 of file OcXmlLib.c.

◆ PlistIntegerValue()

BOOLEAN PlistIntegerValue ( IN XML_NODE *Node OPTIONAL,
OUT VOID * Value,
IN UINT32 Size,
IN BOOLEAN Hex )

Get the value of a plist integer.

Parameters
[in]NodeA pointer to the XML node. Optional.
[out]ValueValue of plist integer.
[in]SizeSize of Value to be casted to (UINT8, UINT16, UINT32, or UINT64).
[in]HexTRUE to interpret the value as hexadecimal values, decimal otherwise.
Returns
TRUE if Node can be casted to PLIST_NODE_TYPE_TRUE or PLIST_NODE_TYPE_FALSE.

Definition at line 1943 of file OcXmlLib.c.

◆ PlistKeyValue()

CONST CHAR8 * PlistKeyValue ( IN XML_NODE *Node OPTIONAL)

Get the value of a plist key.

Parameters
[in]NodeA pointer to the XML node. Optional.
Returns
Key value for valid type or NULL.

Definition at line 1841 of file OcXmlLib.c.

◆ PlistMultiDataSize()

BOOLEAN PlistMultiDataSize ( IN XML_NODE *Node OPTIONAL,
OUT UINT32 * Size )

Get size of multiple types of data that are valid.

Valid type for MultiData is DATA itself, STRING, INTEGER, or BOOLEAN (as 1 byte with 1 or 0 value).

Parameters
[in]NodeA pointer to the XML node. Optional.
[out]SizeSize of MultiData.
Returns
TRUE if Node can be casted to any of the aforementioned types.

Definition at line 2126 of file OcXmlLib.c.

◆ PlistMultiDataValue()

BOOLEAN PlistMultiDataValue ( IN XML_NODE *Node OPTIONAL,
OUT VOID * Buffer,
IN OUT UINT32 * Size )

Get the values of multiple types of data that are valid.

Valid type for MultiData is DATA itself, STRING, INTEGER, or BOOLEAN (as 1 byte with 1 or 0 value).

Parameters
[in]NodeA pointer to the XML node. Optional.
[out]BufferBuffer of plist MultiData.
[in,out]SizeSize of Buffer.
Warning
Integer must fit 32-bit UNSIGNED.
Buffer must be at least 1 byte long.
Returns
TRUE if Node can be casted to any of the aforementioned types.

Definition at line 2008 of file OcXmlLib.c.

◆ PlistNodeCast()

XML_NODE * PlistNodeCast ( IN XML_NODE *Node OPTIONAL,
IN PLIST_NODE_TYPE Type )

Basic type casting (up to PLIST_NODE_TYPE_MAX).

Guarantees that node represents passed type. Guarantees that arrays and dicts have valid amount of children, while others have 0. Guarantees that keys have names and integers have values.

Parameters
[in]NodeA pointer to the XML node. Optional.
[in]TypePlist node type to be casted to.
Returns
Node if it is not NULL and represents passed Type or NULL.
Warning
It is not guaranteed that Node has valid data, for data or integer types.

Definition at line 1760 of file OcXmlLib.c.

◆ PlistStringSize()

BOOLEAN PlistStringSize ( IN XML_NODE *Node OPTIONAL,
OUT UINT32 * Size )

Get size of a plist string, including the '\0' terminator.

Parameters
[in]NodeA pointer to the XML node. Optional.
[out]SizeSize of string.
Returns
TRUE if Node can be casted to PLIST_NODE_TYPE_STRING.

Definition at line 2078 of file OcXmlLib.c.

◆ PlistStringValue()

BOOLEAN PlistStringValue ( IN XML_NODE *Node OPTIONAL,
OUT CHAR8 * Value,
IN OUT UINT32 * Size )

Get the value of a plist string.

Parameters
[in]NodeA pointer to the XML node. Optional.
[out]ValueValue of plist string.
[in,out]SizeSize of Value, including the '\0' terminator.
Returns
TRUE if Node can be casted to PLIST_NODE_TYPE_STRING.

Definition at line 1853 of file OcXmlLib.c.

◆ XmlDocumentExport()

CHAR8 * XmlDocumentExport ( IN CONST XML_DOCUMENT * Document,
OUT UINT32 *Length OPTIONAL,
IN UINT32 Skip,
IN BOOLEAN PrependPlistInfo )

Export parsed document into the buffer.

Parameters
[in]DocumentXML_DOCUMENT to export.
[out]LengthResulting length of the buffer without trailing '\0'. Optional.
[in]SkipNumber of root levels to be skipped before exporting, normally 0.
[in]PrependPlistInfoTRUE to prepend XML plist doc info to exported document.
Returns
The exported buffer allocated from pool or NULL.

Definition at line 1367 of file OcXmlLib.c.

◆ XmlDocumentFree()

VOID XmlDocumentFree ( IN OUT XML_DOCUMENT * Document)

Free all resources associated with the document. All XML_NODE references obtained through the document will be invalidated.

Parameters
[in,out]DocumentXML document to be freed.

Definition at line 1435 of file OcXmlLib.c.

◆ XmlDocumentParse()

XML_DOCUMENT * XmlDocumentParse ( IN OUT CHAR8 * Buffer,
IN UINT32 Length,
IN BOOLEAN WithRefs )

Parse the XML fragment in buffer. References in the document to allow deduplicated node reading: <integer ID="0" size="64">0x0</integer> <integer IDREF="0" size="64">

Parameters
[in,out]BufferChunk to be parsed.
[in]LengthSize of the buffer.
[in]WithRefTRUE to enable reference lookup support.
Warning
Buffer will be referenced by the document, it may not be freed until XML_DOCUMENT is freed.
XmlDocumentFree should be called after completion.
Buffer contents are permanently modified during parsing
Returns
The parsed xml fragment or NULL.

Definition at line 1308 of file OcXmlLib.c.

◆ XmlDocumentRoot()

XML_NODE * XmlDocumentRoot ( IN CONST XML_DOCUMENT * Document)

Get the root of the XML document.

Parameters
[in]DocumentA pointer to the XML document.
Returns
Root node of Document.

Definition at line 1447 of file OcXmlLib.c.

◆ XmlEasyChild()

XML_NODE *EFIAPI XmlEasyChild ( IN OUT XML_NODE * Node,
IN CONST CHAR8 * ChildName,
... )

Get the child node specified by the list of names.

Parameters
[in,out]NodeA pointer to the XML node.
[in]ChildNameList of child names.
Returns
The node described by the path or NULL if child cannot be found.
Warning
Each element on the way must be unique.
Last argument must be NULL.

Definition at line 1515 of file OcXmlLib.c.

◆ XmlNodeAppend()

XML_NODE * XmlNodeAppend ( IN OUT XML_NODE * Node,
IN CONST CHAR8 * Name,
IN CONST CHAR8 *Attributes OPTIONAL,
IN CONST CHAR8 *Content OPTIONAL )

Append new node to current node.

Parameters
[in,out]NodeCurrent node.
[in]NameName of the new node.
[in]AttributesAttributes of the new node. Optional.
[in]ContentNew node content. Optional.
Returns
Newly created node or NULL.
Warning
Name, Attributes, and Content must stay valid till XmlDocumentFree.

Definition at line 1581 of file OcXmlLib.c.

◆ XmlNodeChangeContent()

VOID XmlNodeChangeContent ( IN OUT XML_NODE * Node,
IN CONST CHAR8 * Content )

Change the string content of an XML node.

Parameters
[in,out]NodeA pointer to the XML node.
[in]ContentNew node content.
Warning
Content must stay valid until freed by XmlDocumentFree.

Definition at line 1477 of file OcXmlLib.c.

◆ XmlNodeChild()

XML_NODE * XmlNodeChild ( IN CONST XML_NODE * Node,
IN UINT32 Child )

Get the specific child node.

Parameters
[in]NodeA pointer to the XML node.
[in]ChildIndex of children of Node.
Returns
The n-th child, behaviour is undefined if out of range.

Definition at line 1503 of file OcXmlLib.c.

◆ XmlNodeChildren()

UINT32 XmlNodeChildren ( IN CONST XML_NODE * Node)

Get the number of child nodes under an XML node.

Parameters
[in]NodeA pointer to the XML node.
Returns
Number of child nodes.

Definition at line 1493 of file OcXmlLib.c.

◆ XmlNodeContent()

CONST CHAR8 * XmlNodeContent ( IN CONST XML_NODE * Node)

Get the content of an XML node.

Parameters
[in]NodeA pointer to the XML node.
Returns
The string content of the XML node or NULL.

Definition at line 1467 of file OcXmlLib.c.

◆ XmlNodeName()

CONST CHAR8 * XmlNodeName ( IN CONST XML_NODE * Node)

Get the name of an XML node.

Parameters
[in]NodeA pointer to the XML node.
Returns
The name of the XML node.

Definition at line 1457 of file OcXmlLib.c.

◆ XmlNodePrepend()

XML_NODE * XmlNodePrepend ( IN OUT XML_NODE * Node,
IN CONST CHAR8 * Name,
IN CONST CHAR8 * Attributes,
IN CONST CHAR8 * Content )

Prepend new node to current node.

Parameters
[in,out]NodeCurrent node.
[in]NameName of the new node.
[in]AttributesAttributes of the new node. Optional.
[in]ContentNew node content. Optional.
Returns
Newly created node or NULL.
Warning
Name, Attributes, and Content must stay valid till XmlDocumentFree.

Definition at line 1607 of file OcXmlLib.c.

◆ XmlNodeRemove()

VOID XmlNodeRemove ( IN OUT XML_NODE * Node,
IN XML_NODE * ChildNode )

Remove the child node from the current node.

Parameters
[in,out]NodeCurrent node.
[in]ChildNodeChild node to be removed.

Definition at line 1664 of file OcXmlLib.c.

◆ XmlNodeRemoveByIndex()

VOID XmlNodeRemoveByIndex ( IN OUT XML_NODE * Node,
IN UINT32 Index )

Remove the Index-th child node inside an XML node.

Parameters
[in,out]NodeCurrent node.
[in]IndexIndex-th child node to be removed.

Definition at line 1633 of file OcXmlLib.c.

◆ XmlUnescapeString()

CONST CHAR8 * XmlUnescapeString ( IN CONST CHAR8 * String)

Unescape XML string.

Parameters
[in]StringEscaped string to be converted to unescaped.
Returns
Unescaped XML string that must be freed manually, or NULL on memory allocation failure.

Definition at line 1687 of file OcXmlLib.c.