2019-09-03 11:58:42 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* @APPLE_LICENSE_HEADER_START@
|
|
|
|
*
|
|
|
|
* The contents of this file constitute Original Code as defined in and
|
|
|
|
* are subject to the Apple Public Source License Version 1.1 (the
|
|
|
|
* "License"). You may not use this file except in compliance with the
|
|
|
|
* License. Please obtain a copy of the License at
|
|
|
|
* http://www.apple.com/publicsource and read it before using this file.
|
|
|
|
*
|
|
|
|
* This Original Code and all software distributed under the License are
|
|
|
|
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
|
|
|
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
|
|
|
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
|
|
|
|
* License for the specific language governing rights and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
* @APPLE_LICENSE_HEADER_END@
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* plist.c - plist parsing functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2000-2005 Apple Computer, Inc.
|
|
|
|
*
|
|
|
|
* DRI: Josh de Cesare
|
|
|
|
* code split out from drivers.c by Soren Spies, 2005
|
|
|
|
*/
|
|
|
|
//Slice - rewrite for UEFI with more functions like Copyright (c) 2003 Apple Computer
|
2020-08-17 21:40:52 +02:00
|
|
|
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
|
2023-11-18 11:04:54 +01:00
|
|
|
#include "../../cpp_foundation/apd.h"
|
2020-08-25 17:35:19 +02:00
|
|
|
#include "../b64cdecode.h"
|
2020-04-22 19:52:21 +02:00
|
|
|
#include "plist.h"
|
2020-08-25 17:35:19 +02:00
|
|
|
#include "../../libeg/FloatLib.h"
|
|
|
|
#include "xml.h"
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
#ifndef DEBUG_ALL
|
2020-08-25 17:35:19 +02:00
|
|
|
#define DEBUG_PLIST 0
|
2019-09-03 11:58:42 +02:00
|
|
|
#else
|
|
|
|
#define DEBUG_PLIST DEBUG_ALL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DEBUG_PLIST == 0
|
|
|
|
#define DBG(...)
|
|
|
|
#else
|
|
|
|
#define DBG(...) DebugLog(DEBUG_PLIST, __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CHAR8* buffer_start = NULL;
|
|
|
|
|
|
|
|
// Forward declarations
|
2020-08-19 14:50:26 +02:00
|
|
|
EFI_STATUS ParseTagDict( CHAR8* buffer, TagStruct* * tag, UINT32 empty, UINT32* lenPtr);
|
|
|
|
EFI_STATUS ParseTagArray( CHAR8* buffer, TagStruct* * tag, UINT32 empty, UINT32* lenPtr);
|
|
|
|
EFI_STATUS ParseTagKey( char * buffer, TagStruct* * tag, UINT32* lenPtr);
|
|
|
|
EFI_STATUS ParseTagString(CHAR8* buffer, TagStruct* * tag, UINT32* lenPtr);
|
|
|
|
EFI_STATUS ParseTagInteger(CHAR8* buffer, TagStruct* * tag, UINT32* lenPtr);
|
|
|
|
EFI_STATUS ParseTagFloat(CHAR8* buffer, TagStruct* * tag, UINT32* lenPtr);
|
|
|
|
EFI_STATUS ParseTagData(CHAR8* buffer, TagStruct* * tag, UINT32* lenPtr);
|
|
|
|
EFI_STATUS ParseTagDate(CHAR8* buffer, TagStruct* * tag, UINT32* lenPtr);
|
2021-09-28 15:54:31 +02:00
|
|
|
EFI_STATUS ParseTagBoolean(TagStruct* * tag, XBool value, UINT32* lenPtr);
|
2020-08-19 14:50:26 +02:00
|
|
|
|
|
|
|
EFI_STATUS XMLParseNextTag (CHAR8 *buffer, TagStruct**tag, UINT32 *lenPtr);
|
|
|
|
|
2020-02-17 21:41:09 +01:00
|
|
|
EFI_STATUS FixDataMatchingTag( CHAR8* buffer, CONST CHAR8* tag,UINT32* lenPtr);
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-08-22 15:39:24 +02:00
|
|
|
|
|
|
|
/**************************************** TagStruct ****************************************/
|
|
|
|
|
2020-08-25 17:35:19 +02:00
|
|
|
#include "TagDict.h"
|
|
|
|
#include "TagKey.h"
|
|
|
|
#include "TagBool.h"
|
|
|
|
#include "TagData.h"
|
|
|
|
#include "TagDate.h"
|
|
|
|
#include "TagArray.h"
|
|
|
|
#include "TagFloat.h"
|
|
|
|
#include "TagInt64.h"
|
|
|
|
#include "TagString8.h"
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2023-11-18 11:04:54 +01:00
|
|
|
#ifdef TagStruct_COUNT_CACHEHITMISS
|
|
|
|
size_t TagStruct::cachemiss = 0;
|
|
|
|
size_t TagStruct::cachehit = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void TagStruct::EmptyCache()
|
|
|
|
{
|
|
|
|
#ifdef TagStruct_USE_CACHE
|
|
|
|
TagArray::tagsFree.setEmpty();
|
|
|
|
TagBool::tagsFree.setEmpty();
|
|
|
|
TagData::tagsFree.setEmpty();
|
|
|
|
TagDate::tagsFree.setEmpty();
|
|
|
|
TagDict::tagsFree.setEmpty();
|
|
|
|
TagFloat::tagsFree.setEmpty();
|
|
|
|
TagInt64::tagsFree.setEmpty();
|
|
|
|
TagKey::tagsFree.setEmpty();
|
|
|
|
TagString::tagsFree.setEmpty();
|
|
|
|
#endif
|
|
|
|
}
|
2020-08-22 15:39:24 +02:00
|
|
|
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool TagStruct::debugIsEqual(const TagStruct& other, const XString8& label) const
|
2020-08-25 17:35:19 +02:00
|
|
|
{
|
|
|
|
if ( *this != other ) {
|
|
|
|
MsgLog("Difference at %s\n", label.c_str());
|
|
|
|
if ( *this != other ) {
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TagStruct::printf(unsigned int ident) const
|
|
|
|
{
|
|
|
|
XString8 s;
|
2020-08-25 18:08:05 +02:00
|
|
|
sprintf(ident, &s);
|
2020-08-25 17:35:19 +02:00
|
|
|
MsgLog("%s", s.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convenience method
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool TagStruct::isTrue() const
|
2020-08-25 17:35:19 +02:00
|
|
|
{
|
|
|
|
if ( isBool() ) return getBool()->boolValue();
|
|
|
|
return false;
|
|
|
|
}
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool TagStruct::isFalse() const
|
2020-08-25 17:35:19 +02:00
|
|
|
{
|
|
|
|
if ( isBool() ) return !getBool()->boolValue();
|
|
|
|
return false;
|
|
|
|
}
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool TagStruct::isTrueOrYy() const
|
2020-08-25 17:35:19 +02:00
|
|
|
{
|
|
|
|
if ( isBool() ) return getBool()->boolValue();
|
|
|
|
if ( isString() && getString()->stringValue().notEmpty() && (getString()->stringValue()[0] == 'y' || getString()->stringValue()[0] == 'Y') ) return true;
|
|
|
|
return false;
|
|
|
|
}
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool TagStruct::isTrueOrYes() const
|
2020-08-25 17:35:19 +02:00
|
|
|
{
|
|
|
|
if ( isBool() ) return getBool()->boolValue();
|
2021-04-11 07:18:52 +02:00
|
|
|
if ( isString() && getString()->stringValue().isEqual("Yes"_XS8) ) return true;
|
2020-08-25 17:35:19 +02:00
|
|
|
return false;
|
|
|
|
}
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool TagStruct::isFalseOrNn() const
|
2020-08-25 17:35:19 +02:00
|
|
|
{
|
|
|
|
if ( isBool() ) return !getBool()->boolValue();
|
|
|
|
if ( isString() && getString()->stringValue().notEmpty() && (getString()->stringValue()[0] == 'n' || getString()->stringValue()[0] == 'N') ) return true;
|
|
|
|
return false;
|
|
|
|
}
|
2020-08-22 15:39:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**************************************** XML ****************************************/
|
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
// Expects to see one dictionary in the XML file, the final pos will be returned
|
|
|
|
// If the pos is not equal to the strlen, then there are multiple dicts
|
|
|
|
// Puts the first dictionary it finds in the
|
2020-08-25 17:35:19 +02:00
|
|
|
// tag pointer and returns the end of the dic, or returns ?? if not found.
|
2019-09-03 11:58:42 +02:00
|
|
|
//
|
|
|
|
|
2023-11-07 11:02:22 +01:00
|
|
|
EFI_STATUS ParseXML(const UINT8* buffer, TagDict** dict, size_t bufSize)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 length = 0;
|
|
|
|
UINT32 pos = 0;
|
2020-08-19 14:50:26 +02:00
|
|
|
TagStruct* tag = NULL;
|
2023-11-18 11:04:54 +01:00
|
|
|
apd<CHAR8*> configBuffer = NULL;
|
2020-08-25 17:35:19 +02:00
|
|
|
size_t bufferSize = 0;
|
2019-09-03 11:58:42 +02:00
|
|
|
UINTN i;
|
|
|
|
|
|
|
|
if (bufSize) {
|
|
|
|
bufferSize = bufSize;
|
|
|
|
} else {
|
2023-11-07 11:02:22 +01:00
|
|
|
bufferSize = (UINT32)strlen((CHAR8*)buffer);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
2020-08-30 13:12:46 +02:00
|
|
|
DBG("buffer size=%ld\n", bufferSize);
|
2019-09-03 11:58:42 +02:00
|
|
|
if(dict == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2023-11-18 11:04:54 +01:00
|
|
|
configBuffer = (CHAR8*)malloc(bufferSize+1);
|
2021-05-06 09:55:11 +02:00
|
|
|
memset(configBuffer, 0, bufferSize+1);
|
2019-09-03 11:58:42 +02:00
|
|
|
if(configBuffer == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2020-08-25 17:35:19 +02:00
|
|
|
memmove(configBuffer, buffer, bufferSize);
|
2019-09-03 11:58:42 +02:00
|
|
|
for (i=0; i<bufferSize; i++) {
|
|
|
|
if (configBuffer[i] == 0) {
|
|
|
|
configBuffer[i] = 0x20; //replace random zero bytes to spaces
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buffer_start = configBuffer;
|
2021-09-28 10:28:45 +02:00
|
|
|
while (true)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
Status = XMLParseNextTag(configBuffer + pos, &tag, &length);
|
2020-08-30 13:12:46 +02:00
|
|
|
DBG("pos=%u\n", pos);
|
2019-09-03 11:58:42 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
DBG("error parsing next tag\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos += length;
|
|
|
|
|
|
|
|
if (tag == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-04-08 17:07:05 +02:00
|
|
|
if (tag->isDict()||tag->isArray()) {
|
2019-09-03 11:58:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-11-18 11:04:54 +01:00
|
|
|
tag->ReleaseTag();
|
2020-08-22 15:39:24 +02:00
|
|
|
tag = NULL;
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
// FreePool(configBuffer);
|
|
|
|
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
2021-04-08 17:07:05 +02:00
|
|
|
if (tag->isDict()) *dict = tag->getDict();
|
|
|
|
else *dict = NULL;
|
2019-09-03 11:58:42 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// xml
|
|
|
|
//
|
|
|
|
|
|
|
|
#define DOFREE 1
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
// ParseNextTag
|
|
|
|
|
2020-08-19 14:50:26 +02:00
|
|
|
EFI_STATUS XMLParseNextTag(CHAR8* buffer, TagStruct** tag, UINT32* lenPtr)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 length = 0;
|
|
|
|
UINT32 pos = 0;
|
|
|
|
CHAR8* tagName = NULL;
|
|
|
|
|
|
|
|
*lenPtr=0;
|
|
|
|
|
|
|
|
Status = GetNextTag((UINT8*)buffer, &tagName, 0, &length);
|
|
|
|
if (EFI_ERROR(Status)) {
|
2020-08-25 17:35:19 +02:00
|
|
|
DBG("NextTag error %s\n", efiStrError(Status));
|
2019-09-03 11:58:42 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = length;
|
2020-05-16 21:30:29 +02:00
|
|
|
if (!strncmp(tagName, kXMLTagPList, 6)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
length=0;
|
|
|
|
Status=EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
/***** dict ****/
|
2020-08-25 17:35:19 +02:00
|
|
|
else if (!strcmp(tagName, kXMLTagDict))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
DBG("begin dict len=%d\n", length);
|
2020-08-18 18:45:44 +02:00
|
|
|
Status = ParseTagDict(buffer + pos, tag, 0, &length);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
2020-08-25 17:35:19 +02:00
|
|
|
else if (!strcmp(tagName, kXMLTagDict "/"))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
DBG("end dict len=%d\n", length);
|
2020-08-18 18:45:44 +02:00
|
|
|
Status = ParseTagDict(buffer + pos, tag, 1, &length);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
2020-05-16 21:30:29 +02:00
|
|
|
else if (!strncmp(tagName, kXMLTagDict " ", 5))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
DBG("space dict len=%d\n", length);
|
2020-08-18 18:45:44 +02:00
|
|
|
Status = ParseTagDict(buffer + pos, tag, 0, &length);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
/***** key ****/
|
2020-08-25 17:35:19 +02:00
|
|
|
else if (!strcmp(tagName, kXMLTagKey))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
DBG("parse key\n");
|
|
|
|
Status = ParseTagKey(buffer + pos, tag, &length);
|
|
|
|
}
|
|
|
|
/***** string ****/
|
2020-08-25 17:35:19 +02:00
|
|
|
else if (!strcmp(tagName, kXMLTagString))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
DBG("parse String\n");
|
|
|
|
Status = ParseTagString(buffer + pos, tag, &length);
|
|
|
|
}
|
|
|
|
/***** string ****/
|
2020-05-16 21:30:29 +02:00
|
|
|
else if (!strncmp(tagName, kXMLTagString " ", 7))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
DBG("parse String len=%d\n", length);
|
|
|
|
Status = ParseTagString(buffer + pos, tag, &length);
|
|
|
|
}
|
|
|
|
/***** integer ****/
|
2020-08-25 17:35:19 +02:00
|
|
|
else if (!strcmp(tagName, kXMLTagInteger))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
Status = ParseTagInteger(buffer + pos, tag, &length);
|
|
|
|
}
|
2020-05-16 21:30:29 +02:00
|
|
|
else if (!strncmp(tagName, kXMLTagInteger " ", 8))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
Status = ParseTagInteger(buffer + pos, tag, &length);
|
|
|
|
}
|
2020-04-22 19:52:21 +02:00
|
|
|
/***** float ****/
|
2020-08-25 17:35:19 +02:00
|
|
|
else if (!strcmp(tagName, kXMLTagFloat))
|
2020-04-22 19:52:21 +02:00
|
|
|
{
|
|
|
|
Status = ParseTagFloat(buffer + pos, tag, &length);
|
|
|
|
}
|
2020-05-16 21:30:29 +02:00
|
|
|
else if (!strncmp(tagName, kXMLTagFloat " ", 8))
|
2020-04-22 19:52:21 +02:00
|
|
|
{
|
|
|
|
Status = ParseTagFloat(buffer + pos, tag, &length);
|
|
|
|
}
|
2019-09-03 11:58:42 +02:00
|
|
|
/***** data ****/
|
2020-08-25 17:35:19 +02:00
|
|
|
else if (!strcmp(tagName, kXMLTagData))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
Status = ParseTagData(buffer + pos, tag, &length);
|
|
|
|
}
|
2020-05-16 21:30:29 +02:00
|
|
|
else if (!strncmp(tagName, kXMLTagData " ", 5))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
Status = ParseTagData(buffer + pos, tag, &length);
|
|
|
|
}
|
|
|
|
/***** date ****/
|
2020-08-25 17:35:19 +02:00
|
|
|
else if (!strcmp(tagName, kXMLTagDate))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
Status = ParseTagDate(buffer + pos, tag, &length);
|
|
|
|
}
|
2021-09-28 10:28:45 +02:00
|
|
|
/***** false ****/
|
2020-08-25 17:35:19 +02:00
|
|
|
else if (!strcmp(tagName, kXMLTagFalse))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
2020-08-25 17:35:19 +02:00
|
|
|
Status = ParseTagBoolean(tag, false, &length);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
2021-09-28 10:28:45 +02:00
|
|
|
/***** true ****/
|
2020-08-25 17:35:19 +02:00
|
|
|
else if (!strcmp(tagName, kXMLTagTrue))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
2020-08-25 17:35:19 +02:00
|
|
|
Status = ParseTagBoolean(tag, true, &length);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
/***** array ****/
|
2020-08-25 17:35:19 +02:00
|
|
|
else if (!strcmp(tagName, kXMLTagArray))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
2020-08-18 18:45:44 +02:00
|
|
|
Status = ParseTagArray(buffer + pos, tag, 0, &length);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
2020-05-16 21:30:29 +02:00
|
|
|
else if (!strncmp(tagName, kXMLTagArray " ", 6))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
DBG("begin array len=%d\n", length);
|
2020-08-18 18:45:44 +02:00
|
|
|
Status = ParseTagArray(buffer + pos, tag, 0, &length);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
2020-08-25 17:35:19 +02:00
|
|
|
else if (!strcmp(tagName, kXMLTagArray "/"))
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
DBG("end array len=%d\n", length);
|
2020-08-18 18:45:44 +02:00
|
|
|
Status = ParseTagArray(buffer + pos, tag, 1, &length);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
/***** unknown ****/
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*tag = NULL;
|
|
|
|
length = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
*lenPtr = pos + length;
|
|
|
|
DBG(" len after success parse next tag %d\n", *lenPtr);
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
// ParseTagList
|
|
|
|
|
2021-09-28 15:54:31 +02:00
|
|
|
EFI_STATUS __ParseTagList(XBool isArray, CHAR8* buffer, TagStruct** tag, UINT32 empty, UINT32* lenPtr)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status = EFI_SUCCESS;
|
|
|
|
UINT32 pos;
|
2021-02-10 13:32:07 +01:00
|
|
|
// TagStruct* tagTail;
|
2019-09-03 11:58:42 +02:00
|
|
|
UINT32 length = 0;
|
|
|
|
|
2020-08-18 18:45:44 +02:00
|
|
|
if (isArray) {
|
2019-09-03 11:58:42 +02:00
|
|
|
DBG("parsing array len=%d\n", *lenPtr);
|
2020-08-18 18:45:44 +02:00
|
|
|
} else {
|
2019-09-03 11:58:42 +02:00
|
|
|
DBG("parsing dict len=%d\n", *lenPtr);
|
|
|
|
}
|
2021-02-10 13:32:07 +01:00
|
|
|
// tagTail = NULL;
|
2019-09-03 11:58:42 +02:00
|
|
|
pos = 0;
|
|
|
|
|
2020-08-22 15:39:24 +02:00
|
|
|
TagStruct* dictOrArrayTag;
|
|
|
|
XObjArray<TagStruct>* tagListPtr;
|
2020-08-19 14:50:26 +02:00
|
|
|
if (isArray) {
|
2020-08-25 17:35:19 +02:00
|
|
|
dictOrArrayTag = TagArray::getEmptyTag();
|
|
|
|
tagListPtr = &dictOrArrayTag->getArray()->arrayContent();
|
2020-08-19 14:50:26 +02:00
|
|
|
} else {
|
2020-08-25 17:35:19 +02:00
|
|
|
dictOrArrayTag = TagDict::getEmptyTag();
|
|
|
|
tagListPtr = &dictOrArrayTag->getDict()->dictContent();
|
2020-08-19 14:50:26 +02:00
|
|
|
}
|
2020-08-22 15:39:24 +02:00
|
|
|
XObjArray<TagStruct>& tagList = *tagListPtr;
|
2020-08-19 14:50:26 +02:00
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
if (!empty) {
|
2021-09-28 10:28:45 +02:00
|
|
|
while (true) {
|
2020-08-19 14:50:26 +02:00
|
|
|
TagStruct* newDictOrArrayTag = NULL;
|
|
|
|
Status = XMLParseNextTag(buffer + pos, &newDictOrArrayTag, &length);
|
2019-09-03 11:58:42 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
2020-08-25 17:35:19 +02:00
|
|
|
DBG("error XMLParseNextTag in array: %s\n", efiStrError(Status));
|
2019-09-03 11:58:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos += length;
|
|
|
|
|
2020-08-19 14:50:26 +02:00
|
|
|
if (newDictOrArrayTag == NULL) {
|
2019-09-03 11:58:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-08-19 14:50:26 +02:00
|
|
|
tagList.AddReference(newDictOrArrayTag, true);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (EFI_ERROR(Status)) {
|
2023-11-18 11:04:54 +01:00
|
|
|
dictOrArrayTag->ReleaseTag();
|
2019-09-03 11:58:42 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-19 14:50:26 +02:00
|
|
|
*tag = dictOrArrayTag;
|
2019-09-03 11:58:42 +02:00
|
|
|
*lenPtr=pos;
|
|
|
|
DBG(" return from ParseTagList with len=%d\n", *lenPtr);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-08-19 14:50:26 +02:00
|
|
|
EFI_STATUS ParseTagDict( CHAR8* buffer, TagStruct** tag, UINT32 empty, UINT32* lenPtr)
|
2020-08-18 18:45:44 +02:00
|
|
|
{
|
|
|
|
return __ParseTagList(false, buffer, tag, empty, lenPtr);
|
|
|
|
}
|
|
|
|
|
2020-08-19 14:50:26 +02:00
|
|
|
EFI_STATUS ParseTagArray( CHAR8* buffer, TagStruct** tag, UINT32 empty, UINT32* lenPtr)
|
2020-08-18 18:45:44 +02:00
|
|
|
{
|
|
|
|
return __ParseTagList(true, buffer, tag, empty, lenPtr);
|
|
|
|
}
|
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
//==========================================================================
|
|
|
|
// ParseTagKey
|
|
|
|
|
2020-08-19 14:50:26 +02:00
|
|
|
EFI_STATUS ParseTagKey( char * buffer, TagStruct** tag, UINT32* lenPtr)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 length = 0;
|
|
|
|
UINT32 length2 = 0;
|
2020-08-25 17:35:19 +02:00
|
|
|
TagKey* tmpTag;
|
2020-08-22 15:39:24 +02:00
|
|
|
// TagStruct* subTag = NULL;
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
Status = FixDataMatchingTag(buffer, kXMLTagKey, &length);
|
2020-08-25 17:35:19 +02:00
|
|
|
DBG("fixing key len=%d status=%s\n", length, efiStrError(Status));
|
2019-09-03 11:58:42 +02:00
|
|
|
if (EFI_ERROR(Status)){
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-08-22 15:39:24 +02:00
|
|
|
// Status = XMLParseNextTag(buffer + length, &subTag, &length2);
|
|
|
|
// if (EFI_ERROR(Status)) {
|
|
|
|
// return Status;
|
|
|
|
// }
|
2020-08-25 17:35:19 +02:00
|
|
|
tmpTag = TagKey::getEmptyTag();
|
2021-04-08 17:07:05 +02:00
|
|
|
tmpTag->setKeyValue(LString8(buffer, strlen(buffer)));
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
*tag = tmpTag;
|
|
|
|
*lenPtr = length + length2;
|
2020-08-22 15:39:24 +02:00
|
|
|
DBG("parse key '%s' success len=%d\n", tmpTag->keyStringValue().c_str(), *lenPtr);
|
2019-09-03 11:58:42 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
// ParseTagString
|
|
|
|
|
2020-08-19 14:50:26 +02:00
|
|
|
EFI_STATUS ParseTagString(CHAR8* buffer, TagStruct* * tag,UINT32* lenPtr)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 length = 0;
|
2020-08-25 17:35:19 +02:00
|
|
|
TagString* tmpTag;
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
Status = FixDataMatchingTag(buffer, kXMLTagString, &length);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-08-25 17:35:19 +02:00
|
|
|
tmpTag = TagString::getEmptyTag();
|
2019-09-03 11:58:42 +02:00
|
|
|
if (tmpTag == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2021-04-08 17:07:05 +02:00
|
|
|
size_t outlen = XMLDecode(buffer, strlen(buffer), buffer, strlen(buffer));
|
|
|
|
tmpTag->setStringValue(LString8(buffer, outlen));
|
2019-09-03 11:58:42 +02:00
|
|
|
*tag = tmpTag;
|
|
|
|
*lenPtr = length;
|
2020-08-25 17:35:19 +02:00
|
|
|
DBG(" parse string %s\n", tmpTag->getString()->stringValue().c_str());
|
2019-09-03 11:58:42 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
// ParseTagInteger
|
|
|
|
|
2020-08-25 17:35:19 +02:00
|
|
|
EFI_STATUS ParseTagInteger(CHAR8* buffer, TagStruct** tag, UINT32* lenPtr)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 length = 0;
|
|
|
|
INTN integer;
|
|
|
|
UINT32 size;
|
2021-09-28 15:54:31 +02:00
|
|
|
XBool negative = false;
|
2019-09-03 11:58:42 +02:00
|
|
|
CHAR8* val = buffer;
|
2020-08-25 17:35:19 +02:00
|
|
|
TagInt64* tmpTag;
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-04-22 19:52:21 +02:00
|
|
|
Status = FixDataMatchingTag(buffer, kXMLTagInteger, &length);
|
2019-09-03 11:58:42 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-08-25 17:35:19 +02:00
|
|
|
tmpTag = TagInt64::getEmptyTag();
|
2020-08-18 18:45:44 +02:00
|
|
|
tmpTag->setIntValue(0);
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-08-17 21:40:52 +02:00
|
|
|
size = length;
|
2019-09-03 11:58:42 +02:00
|
|
|
integer = 0;
|
2020-08-17 21:40:52 +02:00
|
|
|
|
|
|
|
if(buffer[0] == '<')
|
|
|
|
{
|
2019-09-03 11:58:42 +02:00
|
|
|
*tag = tmpTag;
|
|
|
|
length = 0;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
if(size > 1 && (val[1] == 'x' || val[1] == 'X')) { // Hex value
|
|
|
|
val += 2;
|
|
|
|
while(*val) {
|
|
|
|
if ((*val >= '0' && *val <= '9')) { // 0 - 9
|
|
|
|
integer = (integer * 16) + (*val++ - '0');
|
|
|
|
}
|
|
|
|
else if ((*val >= 'a' && *val <= 'f')) { // a - f
|
|
|
|
integer = (integer * 16) + (*val++ - 'a' + 10);
|
|
|
|
}
|
|
|
|
else if ((*val >= 'A' && *val <= 'F')) { // A - F
|
2020-10-12 13:51:08 +02:00
|
|
|
integer = (integer * 16) + (*val++ - 'A' + 10);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-04-17 15:14:24 +02:00
|
|
|
MsgLog("ParseTagInteger hex error (0x%hhX) in buffer %s\n", *val, buffer);
|
2019-09-03 11:58:42 +02:00
|
|
|
// getchar();
|
2023-11-18 11:04:54 +01:00
|
|
|
tmpTag->ReleaseTag();
|
2019-09-03 11:58:42 +02:00
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( size ) { // Decimal value
|
|
|
|
if (*val == '-') {
|
2021-09-28 10:28:45 +02:00
|
|
|
negative = true;
|
2019-09-03 11:58:42 +02:00
|
|
|
val++;
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (integer = 0; size > 0; size--) {
|
|
|
|
if(*val) { // UGLY HACK, fix me.
|
|
|
|
if (*val < '0' || *val > '9') {
|
2020-04-17 15:14:24 +02:00
|
|
|
MsgLog("ParseTagInteger decimal error (0x%hhX) in buffer %s\n", *val, buffer);
|
2019-09-03 11:58:42 +02:00
|
|
|
// getchar();
|
2023-11-18 11:04:54 +01:00
|
|
|
tmpTag->ReleaseTag();
|
2019-09-03 11:58:42 +02:00
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
integer = (integer * 10) + (*val++ - '0');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (negative) {
|
|
|
|
integer = -integer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-18 18:45:44 +02:00
|
|
|
tmpTag->setIntValue(integer);
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
*tag = tmpTag;
|
|
|
|
*lenPtr = length;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-04-22 19:52:21 +02:00
|
|
|
//==========================================================================
|
|
|
|
// ParseTagFloat
|
|
|
|
|
2020-08-19 14:50:26 +02:00
|
|
|
EFI_STATUS ParseTagFloat(CHAR8* buffer, TagStruct* * tag, UINT32* lenPtr)
|
2020-04-22 19:52:21 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
2020-08-18 18:45:44 +02:00
|
|
|
UINT32 length;
|
2020-08-25 17:35:19 +02:00
|
|
|
TagFloat* tmpTag;
|
2020-04-22 19:52:21 +02:00
|
|
|
|
|
|
|
Status = FixDataMatchingTag(buffer, kXMLTagFloat, &length);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-08-25 17:35:19 +02:00
|
|
|
tmpTag = TagFloat::getEmptyTag();
|
2020-04-22 19:52:21 +02:00
|
|
|
//----
|
2020-08-18 18:45:44 +02:00
|
|
|
float f;
|
|
|
|
AsciiStrToFloat(buffer, NULL, &f);
|
2020-04-22 19:52:21 +02:00
|
|
|
//----
|
2020-08-18 18:45:44 +02:00
|
|
|
tmpTag->setFloatValue(f);
|
2020-04-22 19:52:21 +02:00
|
|
|
|
|
|
|
*tag = tmpTag;
|
|
|
|
*lenPtr = length;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
//==========================================================================
|
|
|
|
// ParseTagData
|
|
|
|
|
2020-08-19 14:50:26 +02:00
|
|
|
EFI_STATUS ParseTagData(CHAR8* buffer, TagStruct* * tag, UINT32* lenPtr)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 length = 0;
|
2020-08-25 17:35:19 +02:00
|
|
|
TagData* tmpTag;
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
Status = FixDataMatchingTag(buffer, kXMLTagData,&length);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-08-25 17:35:19 +02:00
|
|
|
tmpTag = TagData::getEmptyTag();
|
2019-09-03 11:58:42 +02:00
|
|
|
//Slice - correction as Apple 2003
|
2020-08-18 18:45:44 +02:00
|
|
|
// tmpTag->setStringValue(LString8(buffer));
|
2019-09-03 11:58:42 +02:00
|
|
|
// dmazar: base64 decode data
|
2020-08-18 18:45:44 +02:00
|
|
|
UINTN len = 0;
|
|
|
|
UINT8* data = (UINT8 *)Base64DecodeClover(buffer, &len);
|
2020-08-30 21:53:40 +02:00
|
|
|
tmpTag->setDataValue(data, len);
|
2019-09-03 11:58:42 +02:00
|
|
|
*tag = tmpTag;
|
|
|
|
*lenPtr = length;
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
// ParseTagDate
|
|
|
|
|
2020-08-19 14:50:26 +02:00
|
|
|
EFI_STATUS ParseTagDate(CHAR8* buffer, TagStruct* * tag,UINT32* lenPtr)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 length = 0;
|
2020-08-25 17:35:19 +02:00
|
|
|
TagDate* tmpTag;
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
Status = FixDataMatchingTag(buffer, kXMLTagDate,&length);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-25 17:35:19 +02:00
|
|
|
tmpTag = TagDate::getEmptyTag();
|
2021-04-08 17:07:05 +02:00
|
|
|
tmpTag->setDateValue(LString8(buffer, length));
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
*tag = tmpTag;
|
|
|
|
*lenPtr = length;
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
// ParseTagBoolean
|
|
|
|
|
2021-09-28 15:54:31 +02:00
|
|
|
EFI_STATUS ParseTagBoolean(TagStruct** tag, XBool value, UINT32* lenPtr)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
2020-08-25 17:35:19 +02:00
|
|
|
TagBool* tmpTag;
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-08-25 17:35:19 +02:00
|
|
|
tmpTag = TagBool::getEmptyTag();
|
2020-08-18 18:45:44 +02:00
|
|
|
tmpTag->setBoolValue(value);
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
*tag = tmpTag;
|
|
|
|
*lenPtr = 0;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
// GetNextTag
|
|
|
|
|
|
|
|
EFI_STATUS GetNextTag( UINT8* buffer, CHAR8** tag, UINT32* start, UINT32* length)
|
|
|
|
{
|
|
|
|
UINT32 cnt, cnt2;
|
|
|
|
|
|
|
|
if (tag == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the start of the tag.
|
|
|
|
cnt = 0;
|
|
|
|
while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) {
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer[cnt] == '\0') {
|
|
|
|
DBG("empty buffer at cnt=%d\n", cnt);
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the end of the tag.
|
|
|
|
cnt2 = cnt + 1;
|
|
|
|
while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>')) {
|
|
|
|
cnt2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer[cnt2] == '\0') {
|
|
|
|
DBG("empty buffer at cnt2=%d\n", cnt2);
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fix the tag data.
|
|
|
|
*tag = (CHAR8*)(buffer + cnt + 1);
|
|
|
|
buffer[cnt2] = '\0';
|
|
|
|
if (start) {
|
|
|
|
*start = cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
*length = cnt2 + 1; //unreal to be -1. This is UINT32
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
// FixDataMatchingTag
|
|
|
|
// Modifies 'buffer' to add a '\0' at the end of the tag matching 'tag'.
|
|
|
|
// Returns the length of the data found, counting the end tag,
|
|
|
|
// or -1 if the end tag was not found.
|
|
|
|
|
2020-02-17 21:41:09 +01:00
|
|
|
EFI_STATUS FixDataMatchingTag( CHAR8* buffer, CONST CHAR8* tag, UINT32* lenPtr)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 length;
|
|
|
|
UINT32 start;
|
|
|
|
UINT32 stop;
|
|
|
|
CHAR8* endTag;
|
|
|
|
|
|
|
|
start = 0;
|
|
|
|
while (1) {
|
|
|
|
Status = GetNextTag(((UINT8 *)buffer) + start, &endTag, &stop, &length);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-08-25 17:35:19 +02:00
|
|
|
if ((*endTag == '/') && !strcmp(endTag + 1, tag)) {
|
2019-09-03 11:58:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
start += length;
|
|
|
|
}
|
|
|
|
DBG("fix buffer at pos=%d\n", start + stop);
|
|
|
|
buffer[start + stop] = '\0';
|
|
|
|
*lenPtr = start + length;
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
2020-04-16 09:15:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2021-09-28 10:28:45 +02:00
|
|
|
return true if the property present && value = true
|
|
|
|
else return false
|
2020-04-16 09:15:26 +02:00
|
|
|
*/
|
2021-09-28 10:28:45 +02:00
|
|
|
XBool
|
2020-08-22 15:39:24 +02:00
|
|
|
IsPropertyNotNullAndTrue(const TagStruct* Prop)
|
2020-04-16 09:15:26 +02:00
|
|
|
{
|
2020-08-18 18:45:44 +02:00
|
|
|
return Prop != NULL && Prop->isTrueOrYy();
|
2020-04-16 09:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2021-09-28 10:28:45 +02:00
|
|
|
return true if the property present && value = false
|
|
|
|
else return false
|
2020-04-16 09:15:26 +02:00
|
|
|
*/
|
2021-09-28 10:28:45 +02:00
|
|
|
XBool
|
2020-08-22 15:39:24 +02:00
|
|
|
IsPropertyNotNullAndFalse(const TagStruct* Prop)
|
2020-04-16 09:15:26 +02:00
|
|
|
{
|
2020-08-18 18:45:44 +02:00
|
|
|
return Prop != NULL && Prop->isFalseOrNn();
|
2020-04-16 09:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Possible values
|
|
|
|
<integer>1234</integer>
|
|
|
|
<integer>+1234</integer>
|
|
|
|
<integer>-1234</integer>
|
|
|
|
<string>0x12abd</string>
|
|
|
|
*/
|
|
|
|
INTN
|
2020-08-22 15:39:24 +02:00
|
|
|
GetPropertyAsInteger(
|
2020-08-19 14:50:26 +02:00
|
|
|
const TagStruct* Prop,
|
2020-04-16 09:15:26 +02:00
|
|
|
INTN Default
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (Prop == NULL) {
|
|
|
|
return Default;
|
|
|
|
}
|
|
|
|
|
2020-08-25 17:35:19 +02:00
|
|
|
if (Prop->isInt64()) {
|
|
|
|
return Prop->getInt64()->intValue();
|
|
|
|
} else if ((Prop->isString()) && Prop->getString()->stringValue().notEmpty()) {
|
|
|
|
if ( Prop->getString()->stringValue().length() > 1 && (Prop->getString()->stringValue()[1] == 'x' || Prop->getString()->stringValue()[1] == 'X') ) {
|
|
|
|
return (INTN)AsciiStrHexToUintn(Prop->getString()->stringValue());
|
2020-04-16 09:15:26 +02:00
|
|
|
}
|
|
|
|
|
2020-08-25 17:35:19 +02:00
|
|
|
if (Prop->getString()->stringValue()[0] == '-') {
|
|
|
|
return -(INTN)AsciiStrDecimalToUintn (Prop->getString()->stringValue().c_str() + 1);
|
2020-04-16 09:15:26 +02:00
|
|
|
}
|
|
|
|
|
2020-08-25 17:35:19 +02:00
|
|
|
// return (INTN)AsciiStrDecimalToUintn (Prop->getString()->stringValue());
|
|
|
|
return (INTN)AsciiStrDecimalToUintn((Prop->getString()->stringValue()[0] == '+') ? (Prop->getString()->stringValue().c_str() + 1) : Prop->getString()->stringValue().c_str());
|
2020-12-14 20:46:00 +01:00
|
|
|
} else if (Prop->isData()) {
|
|
|
|
|
2021-01-31 10:50:23 +01:00
|
|
|
UINTN Size = Prop->getData()->dataLenValue();
|
2020-12-14 20:46:00 +01:00
|
|
|
if (Size > 8) Size = 8;
|
|
|
|
INTN Data = 0;
|
2021-05-06 09:55:11 +02:00
|
|
|
memcpy(&Data, Prop->getData()->dataValue(), Size);
|
2020-12-14 20:46:00 +01:00
|
|
|
return Data;
|
2020-04-16 09:15:26 +02:00
|
|
|
}
|
|
|
|
return Default;
|
|
|
|
}
|
2020-04-22 19:52:21 +02:00
|
|
|
|
2020-08-19 14:50:26 +02:00
|
|
|
float GetPropertyFloat (const TagStruct* Prop, float Default)
|
2020-04-22 19:52:21 +02:00
|
|
|
{
|
|
|
|
if (Prop == NULL) {
|
|
|
|
return Default;
|
|
|
|
}
|
2020-08-18 18:45:44 +02:00
|
|
|
if (Prop->isFloat()) {
|
2020-08-25 17:35:19 +02:00
|
|
|
return Prop->getFloat()->floatValue(); //this is union char* or float
|
|
|
|
} else if ((Prop->isString()) && Prop->getString()->stringValue().notEmpty()) {
|
2020-04-22 19:52:21 +02:00
|
|
|
float fVar = 0.f;
|
2020-08-25 17:35:19 +02:00
|
|
|
if(!AsciiStrToFloat(Prop->getString()->stringValue().c_str(), NULL, &fVar)) //if success then return 0
|
2020-04-22 19:52:21 +02:00
|
|
|
return fVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Default;
|
|
|
|
}
|